What would be the proper way to add a power button for BalenaOS

Using a Raspberry Pi 3B+'s GPIO pinout, what would be the best way to add a button that can interact with the balenaOS to “Halt” balenaOS. Raspberry pi is able to Halt in raspbian:


Essentially it’s a sudo shutdown -h now command. I’m not sure that this would work for BalenaOS.

What are your thoughts?


I can point you to the code on how our supervisor performs a shutdown: https://github.com/balena-io/balena-supervisor/blob/6b5617be155c368f8ff02f044ef1c9935901426b/src/lib/systemd.ts#L85-L95. It is basically using the HostOS dbus to send a PowerOff command. I’m not an OS guy, but afaik this is not an official interface so this might break in the future.

If you plan to build this with balenaCloud where you have a supervisor available. I would suggest to use the supervisor api to perform the shutdown. https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v1shutdown

Best Regards,

Basically what I’m trying to achieve is the ability to use one button to both sleep the device and once pressed again, to turn on the device. Does Balena have any suggestions for achieving this? Even if it isn’t a true sleep but shuts down as many things as possible but doesn’t actually cut power

I seem to recal a GPIO pin that, when grounded/pulled high, would start a Pi from a halt state. You could wire this up and then run a service to hook the GPIO event (maybe in Python) and then call the DBUS power off command mentioned above. That’s the only thing I can think of right now, I hope it helps.