Raspberry Pi combined reboot/shutdown button demo

NB: this version doesn’t actually do the rebooting or shutting down: it’s a demo. This one does, though …

Here’s how you might have just one button being a reset button (hold down for two seconds) or a shutdown button (hold down for five):


  1. Good stuff, Russel. Was making a shutdown button for my OSMC Raspberry Pi based on the article in MagPie57. Then, it occurred to me that it would be great to have one button rather than separate shutdown and reset buttons as mentioned there. After dabbling for a while (and learning lots about the GPIOzero library), I came across your post. The hold_repeat option was the bit that I was missing.
    Now it all works beautifully.
    Remark regarding systemd: I appended the /etc/rc.local file to start up the little program at boot. Seems to work just fine. Any thoughts on systemd vs. rc.local?

  2. Thanks scruss! saved me a lot of time trying to create this myself (my python sucks).

    Question: was the indent on line 23 intentional? Did you intend to only clear the held_for timer for the case of 2 secs, the held_for gets locked at that value regardless of how long the next the button press was.

    For my testing I moved ‘held_for = 0.0’ outside of the if/else loop and it worked more like I expected.

Leave a comment

Your email address will not be published. Required fields are marked *