Relays automatically switch if no Home Assistant present

I had a major outage of my home assistant yesterday for several hours.
I heard my sonoff basics’ and Tuya plugs’ relays switch about every 10 minutes.
the ESPHome firmware was very simple, 100% copied from the examples on the website.

This is not good, since this means, my infrastructure does not really function without HA present. I had to remove/unplug all devices until my HA was operational gain. This would be particularly cumbersome with switches mounted in walls.
It seems my most attached devices (f.e. my router) survived the switch, but my stereo always switched of, when this happened.

Is there any reason for this behavior or is this a bug?

Check reboot_timeout parameter in configuration.
Here
Helped me with sonoffs

I have it under api (in case HA is down) and wifi (in case WiFi is down) section in node configuration

Maybe also check restore_mode parameter for switch component configuration

1 Like

Oh, the reboot_timeout seems to be the culprit.
I will give this a try.
the restore_mode was already defined as always on.
Thanks!

I’d like to understand this better.
By default restore_mode should be RESTORE_DEFAULT_OFF as in the docs says: Attempt to restore state and default to OFF if not possible to restore

So what this means is that after a restart the thing will try to keep the same state it had before restarting, if it cannot recover then it will default to OFF.

Now, a device like yours has an ESP8266 and how it works with this?
When ESPHome reboots the ESP8266 in an attempt to get the Wifi working again, it will save the current state of the outputs to some kind of memory that does survive reboots, so the state of the relays should be keep with no problem.

Unfortunately in the case of a power failure, this memory goes blank, and in this case ESPHome will default the relay to off.

In case you want, you can setup ESP to save the relay states to flash, and keep the relay state even after a power failure, but this wears flash memory.

I am using several of the nodes and they certainly reboot when HA is offline and my relays keeps the states between reboots properly. To do so I did nothing, just using defaults.

I set the restore_mode to always ON.
When no client is connected to the API of the ESPHome-Device, the device will reboot by default after 5 minutes.
When it reboots, it switches the relay OFF and ON (because of Restore_mode).

My stereo is connected to a master/slave-power-strip.
The pulse, that is generated by the relay switching OFF and ON triggers the relay in my powerstrip, which in return turns of my stereo.

All other Devices (router, fridge, etc) are not affected.

Deactivating reboot on connection-loss on api, as suggested by MrUkleja solved my problem.

Do you know why other devices are not affected?

Because they are not connected to a master/Slave-powerstrip, that has a seperate relay that is designed to react to fluctuations in the current.