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.
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)
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.