Restore entities state after a power outage (power on behavior: recover)

It isn’t very confortable to have all lights on in the middle of the night after a power outage. After the power comes back, I want the lights and switches/relays to remain the same state before the power outage. Something like the Power loss recovery from Philips Hue (“hue_power_on_behavior”: “recover”) but done from HA.

It would be great to add this option to lever on HA to manage the state restoration.

It could be “as easy” to configure as adding a flag, and when a device is unavailable, after it becomes available again, force to set the last state. I say force because some devices don’t report their state/values.

Maybe this helper could help: https://github.com/home-assistant/core/blob/e64b8774ec045c14cbbca2d76741ed1801048560/homeassistant/helpers/restore_state.py

Hi there! I’d say this can be achieved by already existing functionality.

  1. Add an input boolean helper for a light bulb
  2. Create an automation using a template. Inside that template put a condition helper state does not equal to bulb’s state.
  3. Inside action just toggle the bulb.

This way you are forcing HA to synchronize bulb’s state with the helper. I.e. helper is the master now, not the bulb.

But this isn’t a perfect solution. If there’s a power outage, then after the power turns back on it will take some time for the bulb and HA to recover the connection. Meaning all that time the bulb will keep being turned on. :frowning:

1 Like

For me, after reboot it is better to have state turning_on, and automatically try to turn on devices. turning_on state will be useful for all switches, because sometimes it takes 30 seconds to turn on (especially, for devices with WIFI), when I turn on wall switch, lamps receive wifi connection after 30 and ready to change colors.

Not in the night after a power outage.

This is clearly something useful - in my case I have some devices that turn on after a power outage and I can not configure them to do something else.

I commented here on a method I implemented using a scene, the home assistant start event, and the uptime (snmp) of my printer: