Do all ESPHome plugs automatically reboot if WiFi is lost?
I’m thinking of plugging my router into an ESPHome smart plug. If my WiFi goes down, the plug would not be able to connect and would reboot my router.
Can I set a rule where it waits X minutes before trying to connect to WiFi or rebooting my router?
Tasmota has this ability. Does such a thing exist for ESPHome?
Watchdog for Wi-Fi router or modem~
A Tasmota plug can check a remote host (router itself, something else connected to the router, or a site on the Internet) via an ICMP Ping or loading a URL and can power cycle the router or modem if the remote host isn’t responding. In this example, an interval of 3 minutes is used. The simplest watchdog rule does not use variables:
Rule1
ON Time#Minute|3 DO backlog 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
However, if the endpoint becomes unreachable for a long time, the watchdog will keep cycling it every three minutes. This could reduce the watchdog’s relay lifetime to months, at most years. A safer option would be to use an exponential backoff algorithm. Var1
contains the current interval in minutes, which is tripled after each failed query, but limited to 1439 minutes (1 day).
Rule1
ON system#boot do Var1 3 ENDON
ON Var1#State>1439 DO Var1 1439 ENDON
ON Time#Minute|%var1% DO backlog Ping4 192.168.1.10 ENDON
ON Ping#192.168.1.10#Success==0 DO backlog Mult1 3; Power1 0; Delay 10; Power1 1 ENDON
ON Ping#192.168.1.10#Success>0 DO Var1 3 ENDON
If your Tasmota doesn’t have ping compiled in and your remote host has an HTTP server you can access, you can use WebQuery as below:
Rule1
ON system#boot do Var1 3 ENDON
ON Var1#State>1439 DO Var1 1439 ENDON
ON Time#Minute|%var1% DO backlog WebQuery http://192.168.1.10/ GET ENDON
ON WebQuery#Data$!Done DO backlog Mult1 3; Power1 0; Delay 10; Power1 1 ENDON
ON WebQuery#Data=Done DO Var1 3 ENDON
Triggering off the JSON response to webquery (and other commands) may require wrapping the command in backlog, as per example above