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.

Alternatives

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 https://jenkins.juliogonzalez.es/job/tasmota-shellyplugs-watchdog/lastSuccessfulBuild/artifact/.pio/build/tasmota/firmware.bin.gz

Bonus

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:

Rule1
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!

2 Comments

  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.

Leave a Reply

Your email address will not be published.


*


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