I know this has been covered already, but two points:
writing the state to flash - people seem to think this wears the flash memory prematurely.
setting default to always on can damage the switch in some situations (programming?)
So I’d like to avoid both and simply - if possible - when the power comes back on, the sonoff should turn on power, but perhaps after a short delay to protect it?
I don’t know what’s the best solution - please advise?
Read here. You don’t provide any info on what this Sonoff 31 is.
There are at least 2 versions: Wifi and Zigbee, based on a google search. Tell us which one you have and which integration you are using to get it in HA. There are power_on behaviour settings available in both ESPHome (wifi) and ZHA/Z2M (zigbee) which you could use.
Even without the power_on setting, you can write a simple automation when your plug goes from unavailable to off for eg. 5 minutes, then turn on plug.
It’s a SONOFF S31 WiFi Smart Plug15A Smart Outlet IFTTT Supporting, 2.4 Ghz Wi-Fi .
I reflashed it with esphome and it works.
However leaving the default to always=ON is not recommended.
Its fine to set restore_mode: to ALWAYS_ON. After the S31 is programmed and sealed up.
The issue is USB to UART adapters aren’t meant to drive relays. Doing so can destroy the adapter, the S31, cause inability, not work at all, or work fine.
I’m open to ways to better express this in the documentation as it seems I’ve left room for confusion.