Restart Home Assistant (Pi 4 + UPS) after power outage

So my configuration is as follows:

  • Raspberry Pi 4 with Home Assistant OS
  • UPS battery, connected via USB and NUT
  • Automation that tells HA to shut down the host when the UPS goes below 30%

This is working fine and shuts down HA in a sane manner before the power is completely lost. However, when the power is restored and the UPS charges again, HA does not boot again, because the Raspberry was still technically connected to a power source all the time. I then have to manually unplug and replug the Raspberry power supply to boot everything up again.

While this works well enough when I’m at home, I would like a solution that also reliably works completely unattended.

Any ideas on how to achieve this?

Thanks, Eiko

1 Like

How long do your power outages last?

Your Pi draws very little power and should be able to run for quite a while on a UPS battery. If the more power-hungry devices on the UPS shut down at 30%, maybe your Pi can continue going until say 5% or 10% which hopefully outlasts 99% of power-cuts??

edit: Another thought. You could have an automation which disables all other automations when running on UPS battery (thereby reducing the power usage of the Pi to it’s minimum) and re-enables them when the Pi is back on mains? Now, 30%➜10% on the UPS battery is even longer.

My Pi is on a UPS as well, but when the UPS battery has gone, my Pi just stops. This rarely happens, but at least it powers-up again automatically.

My Home Assistant Pi (that also runs some Docker images like Homematic) is the only device connected to the UPS. Unfortunately it either draws quite some power or my USV has a really bad battery. Here is the graph:

So it takes exactly 30min from 100% to 30% with a load of “5%” (whatever that means in Watt). Since the load always is in the 4% to 5% range I suspect that disabling automations won’t do much.

I really don’t want the Pi to turn off tue to power loss. My last experiences with that included broken SD cards, filesystem errors and hard to trace down weird bugs in Homematic (which runs as an Addon / Docker image on that Pi).

I just had a thought:

Maybe I can put a Shelly Plug S between the UPS and the Pi so that in case of a power outage (which I’m notified about somehow) I can use my Fritz!Box VPN and the Shelly web interface to recycle power and thus restart the Raspberry Pi. Now I would just need to find a way to automate that…

I’m guessing the UPS never disconnects power to the Pi. Hmmmm Chicken and Egg problem… Time to think…

Hello,

I’m also interested in this topic.

I have approximatively the same configuration:

  • HA on Pi 3 with UPS on USB
  • No automation for shutdown Pi, this is done by the NUT add-on when UPS power is low
  • Also a Synology as a UPS client that listen for “shutdown” event from UPS server (on NUT add-on on HA)

The fact is the same: HA + Synology shuts down when receiving UPS event, but when power comes back while the UPS is still alive, none of the Pi or Synology wake up.
Keeping the Pi online is not a priority for me, so no problem if it stops, as long as it is able to start again when i’m not at home.

On Synology, when you set it with UPS on USB, it is possible to send a shutdown command to UPS: so it stops, and everything stops. When power is back, everything start again.
But with NUT with HA, it is not possible.
A PR has been made some time ago for that about the NUT add-on but not accepted (Shutdown ups by abhi23768 · Pull Request #36 · hassio-addons/addon-nut · GitHub).

Same issue here.
My rpi4 can last around 4 hours on 2x18659 3000 mAh, but when I shut it down it doesn’t boot up back. Maybe I should leave some USB light on so it drain the battery.

As for the Synology UPS client, I have a solution:

  1. my APC UPS connected via USB to HASSIO.
  2. I’m running NUT server on HASSIO
  3. My Synology is connected to Network NUT and configured to shutdown after 10 minutes on battery

I’m using this action to shutdown the UPS

  - type: shutdown_reboot
    device_id: 1a5fc62def0e5cb3305b6270df784e09
    domain: nut

Not sure to understand when you say you use that action to shutdown the ups: who launches that action ? Hassio ? How can it launch that if it is itself shutdown by the nut event ?

I’m running hassio on rpi4 with UPS hat.
I have a dedicated APC UPS which supply the Synology NAS
APC UPC connected to HASSIO via USB.
On power outage I’m sending command from Hassio to APC UPS to shutdown
I’m using INA219 UPS HAT Integration to monitor UPS hat and when it’s close to the end I’m shutting down HASSIO

But hassio won’t start itself on power back as UPS Hat never drain itself to 0

Just wondering if anyone has figured this out? I’m running HAOS on a bare metal NUC11 connected via USB to a APC BackUPS 1350. I can create an automation to shutdown the host but once the host is shutdown I don’t see anyway to boot the host again after power is restored.

Also looking for a solution to this. It’s nice to shut down the system, but how do I restart it once power is back?

Never tested, but using esp32 sending WOL if power comes on

esphome:
  name: bleproxy3
  friendly_name: Ble proxy 3
  platformio_options:
    board_build.f_flash: 40000000L
    board_build.flash_mode: dio
    board_build.flash_size: 4MB
  on_boot:
    priority: 200
    # ...
    then:
      - delay: 5min
      - lambda: !lambda |-
          if (id(ble_proxy_status_3).state) {
            ;
          } else {
            id(start_proxmox_huis3).press();
            id(start_proxmox_ha3).press();
          }

esp32:
  variant: ESP32C3
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  - platform: esphome
    password: !secret ota_password

safe_mode:

wifi:
  networks:
  - ssid: "SNOW"
    password: "xxx"
  - ssid: "dd-wrt"
    password: "xxx"

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Bluetooth Fallback Hotspot"
    password: "xxx"

  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 10.0.0.174
    # Set this to the IP address of the router. Often ends with .1
    gateway: 10.0.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0
    dns1: 1.1.1.1
    dns2: 8.8.8.8


esp32_ble_tracker:  

bluetooth_proxy:
  active: true
  
button:
- platform: safe_mode
  name: Safe Mode Boot 3
  entity_category: diagnostic

- platform: restart
  name: "BLE Proxy Restart 3"

- platform: wake_on_lan
  name: "Start Proxmox HA 3"
  id: start_proxmox_ha3
  target_mac_address: 68:1D:EF:37:B3:7C
  
- platform: wake_on_lan
  name: "Start Proxmox Huis 3"
  id: start_proxmox_huis3
  target_mac_address: C8:CB:B8:31:44:45
  

binary_sensor:
  - platform: status
    id: ble_proxy_status_3
    name: "BLE Proxy Status 3"

# Text Sensors.
text_sensor:
  - platform: wifi_info
    ip_address:
      name: Ble proxy 3 IP Address
      id: ble_proxy_3_ip_address
      icon: mdi:ip-network


  

Hi there, this is an old thread but with no definitive answer AFAICS, and it’s an important subject for me since I need a 99.9 confidence in the fact that my HAOS NUC will reboot upon power return without any human intervention.

So, if anyone is willing to share, I’m all ears.

Maybe something like a device plugged into the main power (not the UPS), that would send a WOL signal to the NUC? But I’ve read that WoL is not always reliable…
Or a smart device that sits between the HAOS machine and the UPS, and that, if informed that the HAOS machine was shut down, and that the main power has returned, would just stop and restart the UPS → HAOS power line?

The esp32 script in the post above yours worked perfectly when I tested it.

1 Like

Thanks for your feedback. I’m noobish (but excited by the seemingly wide range of uses they offer) with these ESP32 things.

It seems to me ble_proxy_status_3 is key in your script since it triggers the WOL signals to your HA machine. However, in its definition

I don’t see where it gets its value.

And also, could you point me to a reliable device that would be able to run this script? And if WOL is not an option for my NUC, any suggestion of an ESP device that would follow the same logic but stop and then restart the NUC’s power?

I’m also considering a noobisher but probably more expensive alternative that seems reliable to me: a Shelly Plus Plug S (I’ve read online it’s very reliable, and it’s important for this critical role), located between the UPS and the NUC, that will run a local script that:

  • waits for internet access to stop (pings to both 1.1.1.1 and 8.8.8.8 fails), meaning that the router, that has a UPS that holds charge about 5 mn, is also out of power.
  • then, waits for internet access to be restored (pings to either 1.1.1.1 or 8.8.8.8 pass), meaning the power is restored,
  • then, if the NUC power consumption is 0, meaning the NUC is off, then:
    • turn off NUC’s power for a couple of seconds
    • turn on NUC’s power, hence making for the seemingly more reliable BIOS function “boot on power restore” to do its job.

ble_proxy_status_3 is just the internal state of Esphome’s connection to the mqtt broker. The important thing is the on_boot procedure where the esp32 checks if it is connected to the API, and if not issues a WOL for my proxmox servers.

Oh, smart. So this ESP thingie is conscious of the fact that it’s connected (or not) to HA’s mqtt broker.
What’s the device you use for this?

A simple esp32-c3, about €2 at AliExpress. I have 4 of them, used as bluetooth proxy, but doing double duty as WOL in case power failure.

1 Like

But wait: so if the HA device gracefully shuts down when the UPS reaches critical status, but is still powered by the USP that still has some juice, would your system not force it to start before main power is actually restored?

The ESP32 are not behind the UPS, so they power up when power is restored.

1 Like