Shutdown HA and Raspberry Pi during a Power Loss

In a power loss situation, I understand that it is important to do a graceful shutdown of HA so you don’t have corrupted database files. My understanding the same is true for a Linux OS, but maybe not so critical.

I want to implement a procedure to handle a power loss situation for my Raspberry Pi 5 running the HA OS. Here’s my setup:

  • Raspberry Pi 5 with HA OS installed. Pi is plugged into a Sonoff WiFi Smartplug, which is plugged into a Tripp-Lite UPS battery.
  • I also have a Zigbee device to detect power loss in my home.
    The UPS can power my Wifi Router, Cable Modem, and Raspberry Pi 5 for about 45 minutes.

The method I’m trying to implement with an HA automation is this:

  1. When there is a home power outage my sensor triggers an HA automation.
  2. The automation sends me a notification, and starts a 30 minute countdown.
  3. If the power isn’t restored by that time, the automation does a graceful HA shutdown.
  4. When the home power returns, I can toggle the switch on the Sonoff WiFi outlet to restart the Pi and HA.
  5. If the home power doesn’t return before the UPS’ battery is exhausted, the Pi will be turned off.

With this approach I’m not doing a graceful shutdown of the Linux system on the Pi, which might be a problem. Should I be concerned about the Pi? If so, is there a way I can start a cron job from HA to shutdown the Pi after HA has shutdown?

Thanks.

HA OS is a self contained OS. See here: Home Assistant Operating System

If you shutdown the Pi using the action hassio.host_shutdown, HAOS and the Pi will be shutdown gracefully.

1 Like

Wonderful! That’s exactly what I need. Thank you for the reply.

1 Like