Reboot router when Internet is DOWN - Xiaomi plug

Hi all !

I often have my Internet box that lost the Internet connectivity and I have to physically disconnect / reconnect it …

I want to do this with a connected Xiaomi Plug (recognized in HA) automatically.

I am thinking of doing this:

  • ping of 8.8.8.8
  • If down for 5 min
  • Switch off the Xiaomi plug
  • Wait 30 seconds
  • Switch on the Xiaomi plug

But I can’t figure out how to do it.

For information :

  • My internet box is used as a modem
  • All LAN network is managed by Firewall
  • WiFi is managed by two Access points

Thanks in advance !

Create a ping binary sensor that pings 8.8.8.8. Create an automation that turns off the plug, waits 30 seconds and turns on the plug whenever the binary sensor changes to ‘off’. The default scan interval for the binary ping sensor is already 5 minutes.

Thank you for your quick reply !

But I don’t find the ping binary sensor.

I used HA CORE version, is it compatible ?

You don’t have to find it you have to type it in your configuration.yaml.
@Burningstone already posted a link on how to do it.
(you have to restart HA after you have made changes to your configuration.yaml)

1 Like

Did you have a chance to write the automation? Would you mind sharing the code ?

You shouldn’t ping 8.8.8.8. It is possible for Google’s DNS to go down (or perhaps they just get tired of all the ICMP traffic and stop returning pings?) which will leave your router rebooting.

Ping the first ISP gateway past your router. That is the standard method for determining a connection is IP.

Also make sure you aren’t using wireless anywhere in that chain. HA and the device used to switch should be connected via Ethernet.