Auto restart router or modem when internet down?

how to auto restart router or modem when internet down?

Using Tasmota:

Watchdog for Wi-Fi router~

A Tasmota socket can ping a remote host (router itself or something else connected to the router) and power cycle the socket to reboot the router. In this example, ping interval of 3 minutes is used. The simplest watchdog rule does not use variables:

Rule1
  ON Time#Minute|3 DO Ping4 192.168.1.10 ENDON
  ON Ping#192.168.1.10#Success==0 DO Backlog Power1 0; Delay 10; Power1 1; ENDON
Rule1 1