Our stable running HA instance had to be restarted after a short breakdown of electricity in the house. So also the router that provides internet connection had to reboot. As it happened HA restarted when the router was not yet able to provide the connection. During the restart HA tried to install something from pypi, that failed due to the missing internet connection and then HA failed alltogether. After a while everything in the whole network worked again, except HA, which still was frustrated that had no connection the moment it wanted to start.
I could later reproduce that. When I cut off my HA instance from the internet, and then try to restart the HA service, it simply won’t restart. It fails with
Dec 17 20:45:57 cerbo hass[204675]: 2024-12-17 20:45:57.391 ERROR (SyncWorker_5) [homeassistant.util.package] Unable to install package pyotp==2.8.0: error: Failed to fetch: `https://pypi.org/simple/pyotp/`
Dec 17 20:45:57 cerbo hass[204675]: Caused by: Request failed after 3 retries
Dec 17 20:45:57 cerbo hass[204675]: Caused by: error sending request for url (https://pypi.org/simple/pyotp/)
Dec 17 20:45:57 cerbo hass[204675]: Caused by: client error (Connect)
Dec 17 20:45:57 cerbo hass[204675]: Caused by: tcp connect error: Network is unreachable (os error 101)
Dec 17 20:45:57 cerbo hass[204675]: Caused by: Network is unreachable (os error 101)
Dec 17 20:46:00 cerbo hass[204675]: 2024-12-17 20:46:00.988 ERROR (SyncWorker_5) [homeassistant.util.package] Unable to install package pyotp==2.8.0: error: Failed to fetch: `https://pypi.org/simple/pyotp/`
And after a couple of retries:
Dec 17 20:46:15 cerbo hass[204675]: 2024-12-17 20:46:15.632 ERROR (MainThread) [homeassistant.bootstrap] Home Assistant core failed to initialize. Further initialization aborted
What can I do to make HA restart properly even if there is no internet connection the moment it needs to restart?
HA needs access to the Internet for various reasons. It needs an NTP server for time, access to repositories for updates, etc. There are various things that can be done to work around each of the various reasons but I solved this by having my router and HA on a UPS. Than I can detect when there is a power failure to ensure HA performs a proper shutdown when the UPS is almost out of power.
When power is restored, my router usually boots before HA. But I could delay HA startup until the router is online.
I know that HA needs internet connection. But it should at least start and do all the stuff that work without net connection and retry on the things that do need it. Just failing because in that very moment there is no connection is not an option IMHO? Is this a bug?
Not sure it’s a bug, but I probably found a solution.
Previously I’ve been using Miniconda to setup a Python environment to install HA into. As it turns out, homeassistant.util.package.is_virtual_env() does not recognize a conda environment as virtual environment. Therefore it installed stuff into the <ha-config>/deps. I don’t completely understand why that is a problem, but now I setup a new environment using uv and the problem vanishes. HA now starts even if there is no internet connection the moment it restarts.
My guess is that in an environment of varying complexity, especially for people that may have things installed from a poorly written integration or HACS, it’s possible that “working without the internet” is very difficult to ensure 100% reliability by the Nabu Casa team - also other IOT items on a network that don’t have good exception management built in, may be actually causing a local network storm