ESPhome - Switch OFF/ON with delay after reboot

Is there a way to to turn OFF the switch for 5 seconds and turn it back to ON after reboot.

I want to the switch to really perform a direct OFF/ON after a reboot even if the switch had a state ON allready.

I don’t really understand what you want to do.
Do you want to turn off an output (switch) wait 5 seconds, then reboot the ESP and then the output to be turn on after the ESP boots?
Please describe exactly the sequence you want to accomplish.
While this is possible, it’s not clear why you want a combination of this reboot / delay.

Anyway you can use the on_boot: to perform an automation, like delay then turn switch on/off.

For reboot you can have an automation toggle a reboot switch

Another option will be to delay before rebooting, automations can contain several steps, if an step is a delay, the next step will be executed after the delay, so you can have tree steps:

     - switch.turn_off: my_switch
     - delay: 5s
     - switch.turn_on: my_switch`

Another option that can be useful for you are GPIO Switch’s restore_mode, so you can turn off the switch, wait, reboot and it will be set to on by ESPHome immediatly on boot, if you configure it as ALWAYS_ON

If you just want to reboot, say your wifi router, I don’t see a need to reboot the ESP itself.

The Sonoff S20 flashed with ESPhome is connected to the router. I want to ensure the router is rebooted properly.

this the current config for the moment
image

Should I put your config below switch platform?

You can add the tree steps there to power cycle the router. You need a trigger, like internet down detector?

how does the trigger look like either for internet of wifi connection down in ESPhome ?
can’t get the ESPhome config done correctly

You need one - for each item I guess

Esphome itself does not have internet check components

It can check if it is connected to HA only

Hmm, maybe sending a periodic mqtt ‘internet on’ beacon from HA might work. In arduino this would be pretty easy; just add another topic to the sub callbacks, then code your ‘internet down’ loop(s) accordingly. Not sure how you’d go about subbing to such a ‘virtual topic’ in esphome, etc.

There are some applications that I think are just easier to do from scratch (esp module + IDE + code from scratch), and this may be one of those. I’m a beta-noob when it comes to esphome, so maybe someone with more expertise can shed light on this idea wrt esphome.