Watchdog for network devices with Tasmota

I don’t know how many times I had routers providing access to the internet that would not reboot in case there are problems. Or sometimes the problem is a Raspberry crashing from time to time that I don’t have time to debug.

If it’s the router, the solution would be replacing the router, but it’s not always so trivial. Sometimes you are forced to use your ISP’s router. Sometimes the technology your ISP is using makes very difficult considering an alternative. Remember: here in Spain they sometimes do not disclose connection details or VoIP configuration details. And if you problem is with a Raspberry, you

First advice: if your problem is a router and if you can replace it, go ahead. And consider buying one that supports OpenWrt.


If not, maybe you already considered some options. Ubiquiti’s mFI mPower used to be a nice option and I even still have one. But they are usually expensive and hard to find nowadays, and (worst of all) the firmware is not maintained at all.

NETIO products seem like a nice alternative but well, the only have three products that allow watchdog. The two most interesting for home use are EoL (NETIO4 and NETIO4All) and the third one is a nice PDU (PowerPDU 4C) so you will need adapters.

You could also consider WiReboot, but it seems it’s not available in Europe and I don’t want to mess with customs.

And if you keep looking, you will see more and more alternatives, most of them complex. Because yes, we have “smart” sockets, but it seems that they do not provide this kind of feature.

So if you want to play a little, you can also consider hacking one of such “smart” socket. There are a lot of models and a lot of them are based on the Tuya platform. Ignore those. Changing the firmware can be easy, or just impossible.

Tasmota and Sonoff S26

WARNING: Be aware that you will be working under your exclusive responsibility, and that by doing this you can be violating some local regulations. I do not take any responsibility or liability for following the instructions. Make sure you know what you are doing, and just do not proceed if you are not sure.

WARNING: Never, ever, tinker or try to flash a device using the serial programming interface while it is connected to MAINS ELECTRICITY (AC power).

WARNING: The Sonoff S26 supports a maximum load of 2200W and 10A. Do not connect any devices exceeding that load and do not connect more than one device at the same time.

Go for those with a Serial Port. In my case I considered the Sonoff S26, which accepts Tasmota, and Tasmota accept rules and those can be used to create a watchdog.

So what do you need?

UPDATE: Now I am using some Shelly Plug S as well. Such devices can be flashed with the web browser. The corresponding build is at available at


As you noticed above, my build includes USE_TELEGRAM, as I want to get notifications to telegram when the Watchdog is acting, and I also want the watchdog to verify that the ping fails two times before restarting the device.

For that, I used the console to create a rule:

ON system#boot DO Var1 3 ENDON
ON system#boot DO Var2 0 ENDON
ON system#boot DO tmchatid <MY_TELEGRAM_ID> ENDON
ON system#boot DO tmstate 1 ENDON
ON system#boot DO tmtoken <TELEGRAM_BOT_API_TOKEN> ENDON
ON system#boot DO tmsend Router booted up ENDON
ON Var1#State>1439 DO Var1 1439 ENDON
ON Time#Minute|%var1% DO Ping4 <IP> ENDON
ON Ping#<IP>#Success==0 DO backlog; tmsend Router: Device is unresponsive...; Add2 1 ENDON
ON Ping#<IP>#Success>0 DO backlog; Var1 3; Var2 0 ENDON
ON Var2#State > 1 DO backlog Mult1 3; tmsend Router: Device is unresponsive, restarting power; Power1 0; Delay 10; Power1 1; Var2 0 ENDON

Replace <MY_TELEGRAM_ID> with your telegram ID, which is not your alias or your phone number. You can use a bot to get your ID.

Replace <TELEGRAM_BOT_API_TOKEN> with the bot token can easily be retrived from Telegram’s Botfather bot.

Replace <IP> with the IP of the device you want to check.

Then enable the rule and reboot:

Rule1 1
Restart 1

And ready!


  1. Trying to get your Rule going.
    Can please you explain the behavior (how minutes or ping failures before the restart)?
    I uploaded your ping/telegram enabled bin, pasted your config on my Tasmota basic with Telegram id/api, set ip address but I am not seeing the switch restarting.
    Any help I would appreciate it

    • Did you enable the rule and restarted? Do you see anything at the logs?

      This is basically pinging the device initially each 3 minutes. If the ping fails after two attempts the device is restarted and the interval for the ping is multiplied by 3.

      So the first restart happens after 6 minutes (ping failed twice), and after that the ping interval will be 9 minutes (so next restart will happen in 18 minutes if ping fails twice), and so on.

  2. Thanks for your very nice tutorial.
    I have found just one problem. When I use my S26 and I simulate my network down (=drop all packets from my S26 to the internet), then my S26 first waits to get proper time from NTP before starting to ping in the script. That means after proper turning on and off and the internet will still not be available, another restart will not be performed.
    I reconfigured the NTP server path to my local NTP in my network (router has service as NTP) with the command in the console “NtpServer1 your_ntp_server_name_or_ip”. This can be a temporary solution for me. Do you have any other suggestions?

    • I am not aware my needs NTP, as it performs actions after X seconds, so it the date and time does not really matter.

      How did you notice NTP is a requirement for the the ping functionality? Do you have any logs?

      Truth to be told, I run my own NTP on my local network, so that could explain why I never noticed this. But if NTP is required for the rules or ping, no matter what, it could be a bug that needs to be reported to the tasmota developers.

      Other option is that the rule fails to initialize because when NTP is not available because NTP is a requirement for the Telegram functionality (otherwise tasmota can’t connect to the Telegram servers as the certificate validation will fail).

      But without more information or logs, it’s hard to say what is going on.

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.