Pysical pushbutton on GPIO to shut down Home Assistant?

I have Home Assistant running on a Pi 4b+, running off a deep cycle battery, and a solar panel. We recently had a storm, and the power went out before I could shut down the HA Pi. I have no kvm on that Pi, so I had no way to safely shut it down. It might be OK to leave it on, but with close lightning, I would rather just un-plug it.

To that end, I would like to put a physical button on the GPIO pins to safely shut down the Pi.

I found this option, but was not sure it is best to modify this on a Raspberry Pi running HASSIO?

Or is there a much easier way within HA itself to achieve this goal?

Thank you

You don’t have much access to the host OS to do that. It would be much better done from within HA.

You can call the shut-down service from an automation, service: hassio.host_shutdown. The way you trigger that automation to be convenient and rapid is up to you but some ideas:

Note: this is shut-down only. To power up again simply power cycle the pi.

1 Like

Thanks for the help tom. I rules out the ESPhome, mainly because I am fairly certain I cannot make that work if the router is off.

The GPIO button is my preferred option, so I will look at your link, thank you. My other thought was to use a zigbee button, as it is battery, and will work even if the network is already down. Only down side is that this is a rarely used button, but important tech safety button, and it’s possible the zigbee battery will be flat when needed.

[edit]: I wonder why the GPO integration was removed from Home Assistant in 2022? A little too hardware specific, unused in most integrations?

Thanks

That’s correct. Apologies I thought all your critical infrastructure would have the backup power.

You can create automations to alert you to low battery or lost connections to devices.

Hey, I really appreciate your help with this tom_l. Many thanks.

I laughed at your critical infrastructure comment. Nothing here is critical, I am just tinkering. :slight_smile: I slowly built up the solar setup out of older camping solar parts, with an oven and a fridge, and figured I would push the Home Assistant onto that too. I do have one of the Orbi wifi satellites running off the solar, and the Pi is using Ethernet cable to that, but unfortunately, the cabling from the internet is nowhere near my solar setup, so no battery backup on the router.

I managed to get it to work by:

  • Wired up a momentary switch with a 1kohm resister inline
  • Plugged that into physical pins 1 and 36
  • I had already installed HACS
  • Installed “Raspberry Pi GPO Integration” and reboot Home Assistant
  • Used the already-installed editor to edit configuration.yaml and added
# HACS Raspberry Pi GPIO Integration 
binary_sensor:
  - platform: rpi_gpio
    sensors:
      - port: 16              # Phisical pin 36
        name: "HA Safe Shutdown Button"
        unique_id: "ha_safe_shutdown_button"
        bouncetime: 80
        invert_logic: false   # ACTIVE HIGH
        pull_mode: "DOWN"     # Pull down resistor
  • Checked the config for restart and restart Home Assistant
  • Added that new switch to an entities card
  • Pushed the button a couple of times, and watched the UI change, Awesome, it works!
  • I then started to use Node-red to perform the shutdown, as it is what I am used to using for automation. But it looked like I would have to install another add-in to Node Red to get that to work, and the workflow is super simple, message, shut down, so I just created that in HA Automation.

Works a treat! I will keep in mind that this does complicate the HA install in my case, and likely the zigbee button is the better option, but I enjoyed the learning process implementing this. I have hooked up temperature sensors to the Pi, but no buttons till this one.

Cheers!

3 Likes