Shutdown System
Shutdown System
Hi there,
Enjoying getting to grips with Hudiy - congrats on getting this easy to use product out there guys.
I'm running my unit currently with no safe shutdown in the car and would like to be able to easily and quickly shutdown the system.
I mainly run Android Auto, and I know it can't be done from there, but once I exit Android Auto and go back to the main Hudiy interface would it be possible to add a power button style icon to the bottom bar to the right of the time that when pressed asks do you want to shutdown or reboot and then actions that?
Thanks a million!
Enjoying getting to grips with Hudiy - congrats on getting this easy to use product out there guys.
I'm running my unit currently with no safe shutdown in the car and would like to be able to easily and quickly shutdown the system.
I mainly run Android Auto, and I know it can't be done from there, but once I exit Android Auto and go back to the main Hudiy interface would it be possible to add a power button style icon to the bottom bar to the right of the time that when pressed asks do you want to shutdown or reboot and then actions that?
Thanks a million!
Re: Shutdown System
Hello,
Glad to hear that, thank you!
Safe shutdown is mostly a concern when using SD cards. With USB SSD drives, we've never seen any data corruption issues on Raspberry Pi after a sudden power loss. Still, having a safe shutdown option is a good idea - just in case.
Hudiy doesn’t include built-in controls for shutting down the Raspberry Pi, but the feature you’re describing can definitely be implemented using the custom HTML/JavaScript app.
You could create a simple HTML/JavaScript app with a “Shutdown” button that triggers a sudo halt command - using a lightweight backend in Python for example (HTML/JavaScript on its own can’t run bash commands unless you're using Node.js). Sounds like an easy job for AI
.
Once the app is ready, you just need to add it to applications.json with a unique action name (like shutdown_app). Then you can link that action to the shortcuts panel or the main menu, and Hudiy will display it using WebView.
Useful links:
Examples: https://github.com/wiboma/hudiy/tree/main/examples
Applications in Hudiy: https://github.com/wiboma/hudiy/blob/ma ... plications
Menu: https://github.com/wiboma/hudiy/blob/ma ... ME.md#menu
Shortcuts: https://github.com/wiboma/hudiy/blob/ma ... #shortcuts
WebView: https://github.com/wiboma/hudiy/blob/ma ... d#web-view
Glad to hear that, thank you!
Safe shutdown is mostly a concern when using SD cards. With USB SSD drives, we've never seen any data corruption issues on Raspberry Pi after a sudden power loss. Still, having a safe shutdown option is a good idea - just in case.
Hudiy doesn’t include built-in controls for shutting down the Raspberry Pi, but the feature you’re describing can definitely be implemented using the custom HTML/JavaScript app.
You could create a simple HTML/JavaScript app with a “Shutdown” button that triggers a sudo halt command - using a lightweight backend in Python for example (HTML/JavaScript on its own can’t run bash commands unless you're using Node.js). Sounds like an easy job for AI
Once the app is ready, you just need to add it to applications.json with a unique action name (like shutdown_app). Then you can link that action to the shortcuts panel or the main menu, and Hudiy will display it using WebView.
Useful links:
Examples: https://github.com/wiboma/hudiy/tree/main/examples
Applications in Hudiy: https://github.com/wiboma/hudiy/blob/ma ... plications
Menu: https://github.com/wiboma/hudiy/blob/ma ... ME.md#menu
Shortcuts: https://github.com/wiboma/hudiy/blob/ma ... #shortcuts
WebView: https://github.com/wiboma/hudiy/blob/ma ... d#web-view
Re: Shutdown System
Thanks for that.
I've tried the following:
shutdownPi.py
shutdownPi.html
added into .hudiy/share/config/applications.json
added into .hudiy/share/config/shortcuts.json
Not working however. Is there a log file or two I can look at to debug this?
Might have the HTML wrong. It's been a while since I've touched any of this and just trying to knock it up quickly so I can use it in the car.
I'm running off a SD card on Raspi4 and bootup time is <30s so I'm happy enough for now but do need to implement a safe shutdown.
I've tried the following:
shutdownPi.py
Code: Select all
from subprocess import call
print("Shutting Down")
call("sudo shutdown -h now", shell=True) # tell the Pi to shut downCode: Select all
<!DOCTYPE html>
<html>
<head>
<title>Shutdown Pi</title>
</head>
<body>
<button onclick="runPythonScript()">Run Python Script</button>
<script>
function runPythonScript() {
// Get the path to the Python script.
var pythonScriptPath = "/home/pi/shutdownPi.py";
// Run the Python script.
subprocess.run(["python", pythonScriptPath]);
}
</script>
</body>
</html>Code: Select all
{
"action": "shutdown_pi",
"url": "/home/pi/shutdownPi.html",
"allowBackground": "false",
"controlAudioFocus": "false",
"audioStreamCategory": "NOTIFICATION",
},Code: Select all
{
"iconFontFamily": "Material Symbols Rounded",
"iconName": "volume_down",
"action": "shutdown_pi"
},Might have the HTML wrong. It's been a while since I've touched any of this and just trying to knock it up quickly so I can use it in the car.
I'm running off a SD card on Raspi4 and bootup time is <30s so I'm happy enough for now but do need to implement a safe shutdown.
Re: Shutdown System
There is no subprocess available in HTML/JavaScript. The simplest approach is to handle everything in Python. In this minimal example, a Python script starts a basic HTTP server, serves HTML with a "Shutdown" button, and executes the sudo halt command when the button is clicked.
The script below runs the HTTP server on port 9999 and serves a basic HTML page containing mentioned single "Shutdown" button.
Then, in applications.json (applications array), you can add the following entry (make sure the json syntax is correct):
and in shortcuts.json (shortcuts array)
List of glyphs in Material Symbols Rounded font is available at https://fonts.google.com/icons
To autostart the script you can add it to the /etc/xdg/labwc/autostart file, for example:
Note the & at the end - it runs the script in the background, so it doesn't block the execution of other commands in the /etc/xdg/labwc/autostart file.
Of course, a more sophisticated HTML layout can be created to better match the Hudiy color scheme (see https://github.com/wiboma/hudiy?tab=rea ... diy-object). However, the current version should serve as a good starting point. We've added the creation of such an enhanced example to our backlog, and it will be available on our GitHub soon.
The script below runs the HTTP server on port 9999 and serves a basic HTML page containing mentioned single "Shutdown" button.
Code: Select all
from http.server import BaseHTTPRequestHandler, HTTPServer
import subprocess
PORT = 9999
HTML_PAGE = b"""<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Shutdown</title>
</head>
<body style="font-family:sans-serif; text-align:center; margin-top:50px;">
<button onclick="sendShutdown()" style="font-size:24px; padding:10px 20px;">Shutdown</button>
<p id="status"></p>
<script>
function sendShutdown() {
fetch("/shutdown", { method: "POST" })
.then(r => r.text()).then(t => {
document.getElementById("status").innerText = t;
}).catch(e => {
document.getElementById("status").innerText = "Error: " + e;
});
}
</script>
</body>
</html>
"""
class ShutdownHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(HTML_PAGE)))
self.end_headers()
self.wfile.write(HTML_PAGE)
else:
self.send_error(404, "Not Found")
def do_POST(self):
if self.path == "/shutdown":
self.send_response(200)
self.end_headers()
self.wfile.write(b"Shutdown command issued")
try:
subprocess.run(["sudo", "/sbin/halt"], check=True)
except Exception as e:
print(f"Error: {e}")
else:
self.send_error(404, "Not Found")
def log_message(self, format, *args):
return
if __name__ == "__main__":
print(f"Starting server on http://0.0.0.0:{PORT}")
with HTTPServer(("", PORT), ShutdownHandler) as httpd:
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nServer stopped.")
Code: Select all
{
"action": "shutdown_pi",
"url": "http://127.0.0.1:9999",
"allowBackground": "false",
"controlAudioFocus": "false"
}
Code: Select all
{
"iconFontFamily": "Material Symbols Rounded",
"iconName": "power_settings_new",
"action": "shutdown_pi"
}
To autostart the script you can add it to the /etc/xdg/labwc/autostart file, for example:
Code: Select all
/path/to/your/script.py &
Of course, a more sophisticated HTML layout can be created to better match the Hudiy color scheme (see https://github.com/wiboma/hudiy?tab=rea ... diy-object). However, the current version should serve as a good starting point. We've added the creation of such an enhanced example to our backlog, and it will be available on our GitHub soon.
Re: Shutdown System
Tried this but I just get a large red screen with a "!" on it when I press the new power button shortcut. Obviously some issue with the python script. Is there some log file I can check for more info? Thanks.
Re: Shutdown System
If you see such screen it means the url (http://127.0.0.1:9999) is not available. Try to reach http://127.0.0.1:9999 from web browser or via curl command.
What is the output of the python script when you run it from the terminal by python3 /path/to/script.py command?
To run the script from /etc/xdg/labwc/autostart, make sure the file has executable permissions (chmod +x /path/to/script.py) and starts with the following shebang (https://en.wikipedia.org/wiki/Shebang_(Unix)) line to ensure it's executed using the Python 3 interpreter:
otherwise it must be added as /usr/bin/python3 /path/to/script.py & in /etc/xdg/labwc/autostart
What is the output of the python script when you run it from the terminal by python3 /path/to/script.py command?
To run the script from /etc/xdg/labwc/autostart, make sure the file has executable permissions (chmod +x /path/to/script.py) and starts with the following shebang (https://en.wikipedia.org/wiki/Shebang_(Unix)) line to ensure it's executed using the Python 3 interpreter:
Code: Select all
#!/usr/bin/env python3Re: Shutdown System
Yup it just needed the "#!/usr/bin/env python3" added to the beginning of the file. Thank you. That will work great as a stop gap.
-
Sambolini94
- Posts: 21
- Joined: Tue Aug 12, 2025 7:02 pm
Re: Shutdown System
Just thought I'd offer some input as it may solve your safe shutdown process or at least offer an alternative. I originally started my project with OAP and as part of that built my setup on the required hardware and options available.. One of those was the CarPiHAT Pro Dac (Now Pro5) which ties directly into the cars ACC and Constant live with 5v power output to an original Pi 7" screen and with a simply python script it will auto safe shutdown pi when you take the key out and turn on the pi/ latch power between acc key and engine crank. Costs about £90 and it sits on the pi so no messy relays or wires.
Just my two pennies of thoughts
Just my two pennies of thoughts
Re: Shutdown System
What if we just set the SD card or USB drive to be read-only? It's a reversible process and as far I've seen, hudiy still seems to work fine. Might be a quick easy way to prevent file corruptions.
Re: Shutdown System
While Hudiy is running, it writes some data to cache ($HOME/.hudiy/cache). If you’re using HTML/JavaScript extensions, the Chromium engine may also store its own cache in that folder. The same goes for settings you can change directly in Hudiy ($HOME/.hudiy/share/config/main_configuration.json).
In general, Hudiy should work fine on a read-only filesystem, but there are a few caveats:
In general, Hudiy should work fine on a read-only filesystem, but there are a few caveats:
- large phonebooks and call logs (HFP) might not be handled correctly,
- the built-in music player (storage) may not remember the last played track and its position,
- recently played media might not be saved correctly, which could affect autoplay for FM radio and the built-in music player,
- FM radio may not remember favorite stations (when added via UI) or the last tuned frequency,
- HTML/JavaScript extensions might load slower, since the Chromium engine has to re-process the code every time instead of pulling it from cache.