Power Outage Recovery

I recently had a power outage overnight and my hassio 0.84.6 on raspberry PI 3 did not startup the furnace next morning. My router showed that by hassio instance was not connected by the Ethernet cable. Using a hard reboot of the raspberry PI restored the hassio operation. Further testing showed that home assistant requires a network connection to restart properly and will not recover if the network is restored. This is undesirable behavior that I did not observe in early versions of Home Assistant.
Other than an expensive UPS to keep router and raspberry powered continuously has anyone found a solution?
How does one configure a raspberry PI 3 to wait for a network connection upon reboot? Hassio does not support sudo raspi-config. I am trying to get an automation to restart hassio periodically until the network is detected. So far no luck.

Edit:
Here is the last part of homeassistant.log when hassio hangs and refuses to connect to Ethernet after a power outage. I see this after a manual power reset but before homeassistant starts up again:

2019-01-09 15:43:17 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/discovery.py", line 172, in scan_devices
    results = await hass.async_add_job(_discover, netdisco)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/discovery.py", line 198, in _discover
    netdisco.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/discovery.py", line 63, in scan
    self.gdm.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/gdm.py", line 22, in scan
    self.update()
  File "/usr/local/lib/python3.6/site-packages/netdisco/gdm.py", line 79, in update
    sock.sendto(gdm_msg, (gdm_ip, gdm_port))
OSError: [Errno 101] Network unreachable

I have an automation which uses a PING binary sensor to detect the network and restart Homeassistant if the network is not found but the above error seems to prevent Homeassistant from starting since I observed in the log that the PING sensor did not work. (I assume I can’t comment out discovery:)

Even a UPS solution would fail once the battery is drained and you power up router and Raspberry PI simultaneously after power is restored.

I am contemplating using a ESP8266 module and a relay to power up the Raspberry PI only after a WIFi connection is established with a router.

I consider the current behavior to be a BUG that should be fixed in software. Who wants their Home Automation system to go down due to a power interruption while out of town on vacation?

Edit:
My attempts at an automation work around have failed because Home Assistant won`t even start unless you have the Ethernet cable connected. This was confirmed by checking the log. The PING sensor says still connected since Home Assistant never started to check the connection.

1 Like

Possiby a similar issue as mine: https://github.com/home-assistant/hassos/issues/224

Here is my issue on GitHub.
This my issue is totally repeatable. The router has to be stable when HassOS is started since it appears that it only checks the LAN connection once.

For what it’s worth, I use an Amazon Basics UPS that I got for <$40 USD and it works great!

Definitely recommend to have your critical systems on battery backup!

https://www.amazon.com/dp/B073Q48Z95/ref=twister_B079Z981R2?_encoding=UTF8&psc=1

This is only a partial solution for short power interruptions. If the UPS battery drains this system will not shutdown your Home Assistant device gracefully and (more important) will not insure that your router and Home Assistant device reboot in the right sequence.

Also, I’ve never experienced what you describe, and I constantly am rebooting any/all of my devices including my raspi and an ubuntu VM both running hass.

So, using my Rpi 3 B running hass.io image, can you provide me recreation steps? I’d like to see if I can reproduce and help solve the git issue you raised.

Thanks for your interest.
To reproduce:

  1. Safe shutdown raspi or just disconnect power.
  2. Disconnect Ethernet cable to router.
  3. Reboot raspi.
  4. Wait 5 minutes
  5. Reconnect Ethernet cable to router.
  6. Wait 5 minutes.

After this sequence, WEB browser connect to your router to see if your raspi is connected to the LAN. Mine is not. I have to do another raspi reboot with Ethernet cable to the router connected to restore the LAN connection and see HA running again.

I don’t consider my configuration that complicated. I just have a few Z-wave and MQTT Wifi connected devices.
My Addons are

  • Dnsmasq
  • DuckDns
  • Mosquitto
  • NGNIX
  • SSH

I built a “Power UP Controller” using a ESP8266 module and a relay to power up the Raspberry PI only after a WIFi connection is established with a router. The delayed power worked but hassio still did not start reliably even with a stable router. See related issue.

Other possible ways to delay reboot?

  1. Add boot_delay=60 to config.tx file in the hass-boot partition of the SSD.
  2. Hardware control the “RUN” pin on the Raspberry PI to delay its start. (This would eliminate the need for a relay.)
2 Likes

I’m not seeing this behaviour on my system but I think I know why.

If you have a dumb (unmanaged) switch you could try connecting this between the pi and the router. The unmanaged switch should boot a lot quicker than your router or pi. So it will be available to negotiate a connection before your pi requires it. There won’t be a connection to the router until it comes up but this should not matter to the pi.

It’s an ugly workaround.

SOLVED!!!
I rebuilt my HA system using the latest hassio image here.
Not too difficult if you have a recent snapshot saved on your Windows 10 PC.
The HassOS image version shows up under Hass.io -> SYSTEM

My theory is that the image I was using had a defect in the Ethernet driver.

I would encourage everyone to use the hassos 1.13 image for their Raspberry Pi 3

Thanks for your responses.

It’s 2023 and I’ve been noticing this behavior as well since I started using hass earlier this year. I too find this to be kind of a deal breaker in replacing my ISY/Smartthings combo as both of those recover just fine after a power outage. Whatever fix was done in 2019 has apparently been unfixed in more current versions. I’m on Rpi4

1 Like

I have the same issue!

Bumping as I cannot find a solution to this either. If I power cycle my RPi 3 with the switch on the USB power cable, it starts up again just fine. But if there is a power outage, after the power is restored, HA is not available until I manually restart the RPi 3. I think that this is because my network router is still starting up while the pi has already rebooted.

How can I tell HA to look for a LAN connection in an automation and, if no LAN connection is present, reboot itself?

You could use the PING integration to check for a connection to something else on your LAN and then with an automation call the homeassistant restart service with that connection fails after a few attempts. In my case, I reinstalled the software from a fresh image and the problem never repeated.
I retired my RPI3 about 2 years ago and replaced it with a BEELINK MINI PC with an added 64 GB 2.5" SSD. It has been fast and reliable. Also, I added a 600W UPS which keeps my MINI PC and router running through power interruptions.

1 Like