EspHome reboot relay if internet lost

I have a board with esphome with esp32 and 4 relays, on a relay is connected to the router which sometimes crashes. I would like to know if esp32 is able to try to access the internet and if it doesn’t succeed for 1 minute it turns off the router relay for 30 seconds and then turns it on again.
I did something similar using tasmota on the console.
Home assistant and board are on different links so I can’t do it by Home assistant.
I need to do in Esphome

Obvious solution would be to get a router that doesn’t crash. I’m no longer recommending Ubiquiti gear due to the direction the company seems to be taking, but my home USG only ever gets rebooted for firmware updates, same with the USG-Pro at my church. I hear similar reports for Mikrotik routers: not expensive and they do the job properly.

To try to help with the question you’re actually asking, would it be enough to check the wifi link?

There is no ping sensor in ESPHome unfortunately, although this has been asked for:

I think your only solution to test for internet connection would be to spin up an HTTP connection in a lambda, which isn’t simple.

Thanks for your help
I’m going to try this alternative creating an http connection, would you have any information on this subject?

2 Likes

Hi did you manage to make it work?
I have the same issue with an external access point…
Thanks

One might want to use this custom component then:

1 Like

I use this ESPhome code to switch off particular relays if the connection to the HA server dies. Not quite what you want but can help with the automation side of things. This switches off the relays if the ESPhome node loses contact with the HA server.

interval:
  - interval: 10s
    then:
      if:
        condition:
          api.connected:
        then:
          #nothing if connected
        else:
          - switch.turn_off: p1
          - delay: 3s
          - switch.turn_off: s1
          - switch.turn_off: s2
1 Like

Thanks, it will probably get the job done!