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

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

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

  3. Hello! Unfortunately it does not work! The ping is unknown. It does not accept telegram api code either! I accept all help! Thank you.

    20:25:52.485 QPC: Reset
    20:25:55.396 MQT: tele/tasmota_7C19B4/STATE = {“Time”:”2023-04-02T20:25:55″,”Uptime”:”0T00:00:10″,”UptimeSec”:10,”Heap”:25,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:1,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”D4:5D:64:C5:8F:F0″,”Channel”:9,”Mode”:”11n”,”RSSI”:38,”Signal”:-81,”LinkCount”:1,”Downtime”:”0T00:00:05″}}
    20:27:00.416 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.2”
    20:27:00.425 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
    20:30:00.458 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.2”
    20:30:00.470 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
    20:30:55.401 MQT: tele/tasmota_7C19B4/STATE = {“Time”:”2023-04-02T20:30:55″,”Uptime”:”0T00:05:10″,”UptimeSec”:310,”Heap”:24,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:1,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”D4:5D:64:C5:8F:F0″,”Channel”:9,”Mode”:”11n”,”RSSI”:54,”Signal”:-73,”LinkCount”:1,”Downtime”:”0T00:00:05″}}
    20:33:00.429 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.2”
    20:33:00.440 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
    20:34:10.383 WIF: AP-hoz csatlakozás:1 Zsolt Channel 9 BSSId D4:5D:64:C5:8F:F0 mód: 11n mint tasmota-7C19B4-6580…
    20:34:19.286 WIF: Sikertelen csatlakozás, AP nem elérhető
    20:34:19.625 WIF: AP-hoz csatlakozás:1 Zsolt mód: 11n mint tasmota-7C19B4-6580…
    20:34:24.022 WIF: Csatlakoztatva
    20:34:24.273 MQT: Csatlakozás…
    20:34:24.291 MQT: Csatlakoztatva
    20:34:24.295 MQT: tele/tasmota_7C19B4/LWT = Online (megtartott)
    20:34:24.299 MQT: cmnd/tasmota_7C19B4/POWER =
    20:34:25.410 MQT: stat/tasmota_7C19B4/STATUS = {“Status”:{“Module”:12,”DeviceName”:”Tasmota”,”FriendlyName”:[“Tasmota”],”Topic”:”tasmota_7C19B4″,”ButtonTopic”:”0″,”Power”:0,”PowerOnState”:3,”LedState”:1,”LedMask”:”FFFF”,”SaveData”:1,”SaveState”:1,”SwitchTopic”:”0″,”SwitchMode”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],”ButtonRetain”:0,”SwitchRetain”:0,”SensorRetain”:0,”PowerRetain”:0,”InfoRetain”:0,”StateRetain”:0,”StatusRetain”:0}}
    20:34:25.483 MQT: stat/tasmota_7C19B4/STATUS1 = {“StatusPRM”:{“Baudrate”:115200,”SerialConfig”:”8N1″,”GroupTopic”:”tasmotas”,”OtaUrl”:”http://ota.tasmota.com/tasmota/tasmota-HU.bin.gz”,”RestartReason”:”Software/System restart”,”Uptime”:”0T00:08:40″,”StartupUTC”:”2023-04-02T19:25:45″,”Sleep”:50,”CfgHolder”:4617,”BootCount”:15,”BCResetTime”:”2023-02-05T19:31:15″,”SaveCount”:81,”SaveAddress”:”F9000″}}
    20:34:25.549 MQT: stat/tasmota_7C19B4/STATUS11 = {“StatusSTS”:{“Time”:”2023-04-02T20:34:25″,”Uptime”:”0T00:08:40″,”UptimeSec”:520,”Heap”:25,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:35,”MqttCount”:2,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:86,”Signal”:-57,”LinkCount”:2,”Downtime”:”0T00:00:22″}}}
    20:34:25.603 MQT: stat/tasmota_7C19B4/STATUS2 = {“StatusFWR”:{“Version”:”12.4.0.4(tasmota)”,”BuildDateTime”:”2023.04.02 14:56:00″,”Boot”:31,”Core”:”2_7_4_9″,”SDK”:”2.2.2-dev(38a443e)”,”CpuFrequency”:80,”Hardware”:”ESP8266EX”,”CR”:”366/699″}}
    20:34:25.657 MQT: stat/tasmota_7C19B4/RESULT = {“Time”:”2023-04-02T20:34:25″,”Uptime”:”0T00:08:40″,”UptimeSec”:520,”Heap”:23,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:42,”MqttCount”:2,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:86,”Signal”:-57,”LinkCount”:2,”Downtime”:”0T00:00:22″}}
    20:35:44.128 APP: Soros naplózás kikapcsolva
    20:35:55.065 MQT: tele/tasmota_7C19B4/STATE = {“Time”:”2023-04-02T20:35:55″,”Uptime”:”0T00:10:10″,”UptimeSec”:610,”Heap”:24,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:2,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:86,”Signal”:-57,”LinkCount”:2,”Downtime”:”0T00:00:22″}}
    20:36:00.066 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.2”
    20:36:00.074 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}

    • 00:00:00.541 WIF: AP-hoz csatlakozás:1 Zsolt Channel 4 BSSId 04:D9:F5:C8:92:40 mód: 11n mint tasmota-7C19B4-6580…
      00:00:01.753 WIF: Csatlakoztatva
      00:00:02.005 HTP: Webszerver aktív: tasmota-7C19B4-6580 IP cím: 192.168.0.129
      21:09:38.030 MQT: Csatlakozás…
      21:09:38.052 MQT: Csatlakoztatva
      21:09:38.055 MQT: tele/tasmota_7C19B4/LWT = Online (megtartott)
      21:09:38.057 MQT: cmnd/tasmota_7C19B4/POWER =
      21:09:38.063 MQT: tele/tasmota_7C19B4/INFO1 = {“Info1”:{“Module”:”1 Channel”,”Version”:”12.4.0.4(tasmota)”,”FallbackTopic”:”cmnd/DVES_7C19B4_fb/”,”GroupTopic”:”cmnd/tasmotas/”}}
      21:09:38.094 MQT: tele/tasmota_7C19B4/INFO2 = {“Info2”:{“WebServerMode”:”Admin”,”Hostname”:”tasmota-7C19B4-6580″,”IPAddress”:”192.168.0.129″}}
      21:09:38.122 MQT: tele/tasmota_7C19B4/INFO3 = {“Info3”:{“RestartReason”:”Software/System restart”,”BootCount”:16}}
      21:09:38.148 MQT: stat/tasmota_7C19B4/RESULT = {“POWER”:”OFF”}
      21:09:38.151 MQT: stat/tasmota_7C19B4/POWER = OFF
      21:09:38.164 RUL: SYSTEM#BOOT performs “Var1 3”
      21:09:38.169 MQT: stat/tasmota_7C19B4/RESULT = {“Var1″:”3”}
      21:09:38.178 RUL: SYSTEM#BOOT performs “Var2 0”
      21:09:38.183 MQT: stat/tasmota_7C19B4/RESULT = {“Var2″:”0”}
      21:09:38.194 RUL: SYSTEM#BOOT performs “tmchatid 621828742”
      21:09:38.202 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
      21:09:38.213 RUL: SYSTEM#BOOT performs “tmstate 1”
      21:09:38.222 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
      21:09:38.236 RUL: SYSTEM#BOOT performs “tmtoken bot6012918400:AAF0ejXn_dGY1_gh2QFvBcT4ZyAtKeBb28”
      21:09:38.242 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
      21:09:38.254 RUL: SYSTEM#BOOT performs “tmsend Router booted up”
      21:09:38.260 MQT: stat/tasmota_7C19B4/RESULT = {“Command”:”Unknown”}
      21:09:39.190 MQT: stat/tasmota_7C19B4/STATUS = {“Status”:{“Module”:12,”DeviceName”:”Tasmota”,”FriendlyName”:[“Tasmota”],”Topic”:”tasmota_7C19B4″,”ButtonTopic”:”0″,”Power”:0,”PowerOnState”:3,”LedState”:1,”LedMask”:”FFFF”,”SaveData”:1,”SaveState”:1,”SwitchTopic”:”0″,”SwitchMode”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],”ButtonRetain”:0,”SwitchRetain”:0,”SensorRetain”:0,”PowerRetain”:0,”InfoRetain”:0,”StateRetain”:0,”StatusRetain”:0}}
      21:09:39.261 MQT: stat/tasmota_7C19B4/STATUS1 = {“StatusPRM”:{“Baudrate”:115200,”SerialConfig”:”8N1″,”GroupTopic”:”tasmotas”,”OtaUrl”:”http://ota.tasmota.com/tasmota/tasmota-HU.bin.gz”,”RestartReason”:”Software/System restart”,”Uptime”:”0T00:00:06″,”StartupUTC”:”2023-04-02T20:09:33″,”Sleep”:50,”CfgHolder”:4617,”BootCount”:15,”BCResetTime”:”2023-02-05T19:31:15″,”SaveCount”:81,”SaveAddress”:”F9000″}}
      21:09:39.323 MQT: stat/tasmota_7C19B4/STATUS11 = {“StatusSTS”:{“Time”:”2023-04-02T21:09:39″,”Uptime”:”0T00:00:06″,”UptimeSec”:6,”Heap”:25,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:36,”MqttCount”:1,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:78,”Signal”:-61,”LinkCount”:1,”Downtime”:”0T00:00:03″}}}
      21:09:39.382 MQT: stat/tasmota_7C19B4/STATUS2 = {“StatusFWR”:{“Version”:”12.4.0.4(tasmota)”,”BuildDateTime”:”2023.04.02 14:56:00″,”Boot”:31,”Core”:”2_7_4_9″,”SDK”:”2.2.2-dev(38a443e)”,”CpuFrequency”:80,”Hardware”:”ESP8266EX”,”CR”:”366/699″}}
      21:09:39.434 MQT: stat/tasmota_7C19B4/RESULT = {“Time”:”2023-04-02T21:09:39″,”Uptime”:”0T00:00:06″,”UptimeSec”:6,”Heap”:26,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:43,”MqttCount”:1,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:80,”Signal”:-60,”LinkCount”:1,”Downtime”:”0T00:00:03″}}
      21:09:41.440 QPC: Reset
      21:09:42.404 MQT: tele/tasmota_7C19B4/STATE = {“Time”:”2023-04-02T21:09:42″,”Uptime”:”0T00:00:09″,”UptimeSec”:9,”Heap”:26,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:1,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:76,”Signal”:-62,”LinkCount”:1,”Downtime”:”0T00:00:03″}}

      • Looks to me you are not building your own Tasmota, or not using my builds (if they are valid for your devices).

        Neither PING or Telegram commands are available in the standard tasmota images.

  4. Hello!
    Yes, yes I did! I put up your modified program. It will start. But the Telegram messages are not coming! The telegram Api token and ID are good because the synonas can send the messages. What could be the problem? Thanks!
    RSL: RESULT = {“TmSend”:”Failed”}

    19:14:39.095 RUL: SYSTEM#BOOT performs “Var1 3”
    19:14:39.099 RSL: RESULT = {“Var1″:”3”}
    19:14:39.107 RUL: SYSTEM#BOOT performs “Var2 0”
    19:14:39.111 RSL: RESULT = {“Var2″:”0”}
    19:14:39.120 RUL: SYSTEM#BOOT performs “tmchatid REDACTED”
    19:14:39.124 RSL: RESULT = {“TmChatId”:”REDACTED”}
    19:14:39.133 RUL: SYSTEM#BOOT performs “tmstate 1”
    19:14:39.137 RSL: RESULT = {“TmState”:{“Send”:”ON”,”Receive”:”OFF”,”Echo”:”OFF”}}
    19:14:39.148 RUL: SYSTEM#BOOT performs “tmtoken botREDACTED:REDACTED”
    19:14:39.153 RSL: RESULT = {“TmToken”:”botREDACTED:REDACTED”}
    19:14:39.164 RUL: SYSTEM#BOOT performs “tmsend Router booted up”
    19:14:39.168 TGM: Started
    19:14:39.822 RSL: RESULT = {“TmSend”:”Failed”}
    19:14:42.649 QPC: Reset
    19:14:43.410 RSL: STATE = {“Time”:”2023-04-04T19:14:43″,”Uptime”:”0T00:00:08″,”UptimeSec”:8,”Heap”:19,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:32,”MqttCount”:0,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:100,”Signal”:-48,”LinkCount”:1,”Downtime”:”0T00:00:03″}}
    19:15:35.428 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.52”
    19:15:35.434 RSL: RESULT = {“Ping”:”Done”}
    19:15:39.618 RSL: RESULT = {“Ping”:{“192.168.0.52”:{“Reachable”:true,”IP”:”192.168.0.52″,”Success”:4,”Timeout”:0,”MinTime”:6,”MaxTime”:110,”AvgTime”:69}}}
    19:15:39.650 RUL: PING#192.168.0.52#SUCCESS>0 performs “backlog; Var1 3; Var2 0”
    19:15:39.669 RSL: RESULT = {“Var1″:”3”}
    19:15:39.870 RSL: RESULT = {“Var2″:”0”}
    19:18:00.430 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.52”
    19:18:00.437 RSL: RESULT = {“Ping”:”Done”}
    19:18:04.615 RSL: RESULT = {“Ping”:{“192.168.0.52”:{“Reachable”:false,”IP”:”192.168.0.52″,”Success”:0,”Timeout”:4,”MinTime”:0,”MaxTime”:0,”AvgTime”:0}}}
    19:18:04.645 RUL: PING#192.168.0.52#SUCCESS==0 performs “backlog; tmsend Router: Device is unresponsive…; Add2 1”
    19:18:05.325 RSL: RESULT = {“TmSend”:”Failed”}
    19:18:05.373 RSL: RESULT = {“Add2″:”1.000”}
    19:19:43.439 RSL: STATE = {“Time”:”2023-04-04T19:19:43″,”Uptime”:”0T00:05:08″,”UptimeSec”:308,”Heap”:18,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:0,”POWER”:”OFF”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:100,”Signal”:-48,”LinkCount”:1,”Downtime”:”0T00:00:03″}}
    19:20:05.430 CMD: ping4 8.8.8.8
    19:20:05.437 RSL: RESULT = {“Ping”:”Done”}
    19:20:09.671 RSL: RESULT = {“Ping”:{“8.8.8.8”:{“Reachable”:true,”IP”:”8.8.8.8″,”Success”:4,”Timeout”:0,”MinTime”:10,”MaxTime”:20,”AvgTime”:13}}}
    19:21:00.456 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.52”
    19:21:00.463 RSL: RESULT = {“Ping”:”Done”}
    19:21:04.644 RSL: RESULT = {“Ping”:{“192.168.0.52”:{“Reachable”:false,”IP”:”192.168.0.52″,”Success”:0,”Timeout”:4,”MinTime”:0,”MaxTime”:0,”AvgTime”:0}}}
    19:21:04.674 RUL: PING#192.168.0.52#SUCCESS==0 performs “backlog; tmsend Router: Device is unresponsive…; Add2 1”
    19:21:05.323 RSL: RESULT = {“TmSend”:”Failed”}
    19:21:05.352 RSL: RESULT = {“Add2″:”2.000”}
    19:21:05.431 RUL: VAR2#STATE > 1 performs “backlog Mult1 3; tmsend Router: Device is unresponsive, restarting power; Power1 0; Delay 10; Power1 1; Var2 0”
    19:21:05.451 RSL: RESULT = {“Mult1″:”9.000”}
    19:21:06.324 RSL: RESULT = {“TmSend”:”Failed”}
    19:21:06.371 RSL: RESULT = {“POWER”:”OFF”}
    19:21:06.374 RSL: POWER = OFF
    19:21:06.572 RSL: RESULT = {“Delay”:10}
    19:21:07.627 RSL: RESULT = {“POWER”:”ON”}
    19:21:07.630 RSL: POWER = ON
    19:21:07.878 RSL: RESULT = {“Var2″:”0”}
    19:24:34.411 APP: Serial logging disabled
    19:24:43.429 RSL: STATE = {“Time”:”2023-04-04T19:24:43″,”Uptime”:”0T00:10:08″,”UptimeSec”:608,”Heap”:18,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:21,”MqttCount”:0,”POWER”:”ON”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:96,”Signal”:-52,”LinkCount”:1,”Downtime”:”0T00:00:03″}}
    19:27:08.410 RSL: RESULT = {“POWER”:”OFF”}
    19:27:08.412 RSL: POWER = OFF
    19:27:09.109 RSL: RESULT = {“POWER”:”ON”}
    19:27:09.112 RSL: POWER = ON
    19:29:43.429 RSL: STATE = {“Time”:”2023-04-04T19:29:43″,”Uptime”:”0T00:15:08″,”UptimeSec”:908,”Heap”:18,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:0,”POWER”:”ON”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:98,”Signal”:-51,”LinkCount”:1,”Downtime”:”0T00:00:03″}}
    19:30:00.425 RUL: TIME#MINUTE|%VAR1% performs “Ping4 192.168.0.52”
    19:30:00.432 RSL: RESULT = {“Ping”:”Done”}
    19:30:04.674 RSL: RESULT = {“Ping”:{“192.168.0.52”:{“Reachable”:false,”IP”:”192.168.0.52″,”Success”:0,”Timeout”:4,”MinTime”:0,”MaxTime”:0,”AvgTime”:0}}}
    19:30:04.704 RUL: PING#192.168.0.52#SUCCESS==0 performs “backlog; tmsend Router: Device is unresponsive…; Add2 1”
    19:30:05.324 RSL: RESULT = {“TmSend”:”Failed”}
    19:30:05.352 RSL: RESULT = {“Add2″:”1.000”}
    19:34:43.432 RSL: STATE = {“Time”:”2023-04-04T19:34:43″,”Uptime”:”0T00:20:08″,”UptimeSec”:1208,”Heap”:18,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:20,”MqttCount”:0,”POWER”:”ON”,”Wifi”:{“AP”:1,”SSId”:”Zsolt”,”BSSId”:”04:D9:F5:C8:92:40″,”Channel”:4,”Mode”:”11n”,”RSSI”:100,”Signal”:-49,”LinkCount”:1,”Downtime”:”0T00:00:03″}}

    • Be aware: I had to change your message to remove the telegram bot credentials.

      About what the problem could be, it could be a lot of things:
      – Wrong bot credentials
      – Wrong target for the bot
      – Firewalling in your network
      – Telegram not available in your country.

      I’d recommend using curl to test the credentials, target and network status:

      /usr/bin/curl -s –data chat_id=”” –data “text=Test!” “https://api.telegram.org/bot:/sendMessage”

      This will return like the following, if the message was sent:

      {“ok”:true,”result”:{“message_id”:48131,”from”:{“id”:,”is_bot”:true,”first_name”:”“,”username”:”“},”chat”:{“id”:101122071,”first_name”:”“,”last_name”:”“,”username”:”“,”type”:”private”},”date”:1684100887,”text”:”Test!”}}

  5. Is there a chance to install the Script/ Firmware on an Shelly Plus Plug S?
    I think the normale Plug S is discontinued?

  6. HI

    I tried to install your firmware on a sonoff Basic R3 module, but I get error for exceeding memory size, how can I fix it?

    • I don’t have such device.

      All I can think of is that you need to flash first tasmota-minimal.bin, but in such cases the error you’d get if you are already running tasmota would be “Upload buffer miscompare”, as described at as instructed at https://tasmota.github.io/docs/Upgrading/#upgrade-by-file-upload

      If you are not using tasmota already, but the original firmware, then update first to an official tasmota, then try to apply my firmware from tasmota.

      • Hi, I have already installed tasmota, the minimal version is everything ok. If I try to install your modified version, it is not successful, there is not enough memory.

        • It could be the device does not have enough storage to use my firmware. Not all devices supported by tasmota have the same amount of memory.

          I stripped my firmware with what I know for a fact that didn’t know, and enough to make a firmware that fits for the Sonoff S2X switches, as well as the Shelly Plug S.

          But for other devices with less memory, then more stuff needs to be disabled before building the firmware, so it the resulting firmware is smaller.

          First thing would be knowing the specifications of your device, to know how many else things would need to be removed. Then you can add those to things the https://jenkins.juliogonzalez.es/job/tasmota-sonoffS2X-watchdog/lastSuccessfulBuild/artifact/tasmota/user_config_override.h file I use, and rebuild the firmware.

  7. HI
    Good news, I managed to install your Firmware, it was enough to use the compressed.gz file instead of the bin file.
    Now the internet connection is monitored with the 8.8.8.8 ping and the router is restarted correctly.
    I still haven’t been able to get the message to telegram to work.
    I have a question, Chatid and UserId are the same thing?
    I see in the rules that you set the following string:
    ON system#boot DO tmchatid ENDON
    I don’t want to be misunderstood, I put my UserId as the value, is that correct?

    • Ah, yeah. The firmware is big, so you must always upload it as .gz, which is why I provided that, and not the uncompressed binary anymore.

      tmchatid is the target for the telegram messages.

      That target can be another bot, a group, a supergroup, a user…

      So if you want to send messages to your Telegram account, then yes, tmchatid value must be your Telegram user ID (which is neither your username if you have it, or your phone number, but rather a number provided by telegram for each user, and can be retrieved as described at the link on the article: https://www.alphr.com/telegram-find-user-id/

  8. Hi juliogonzález
    to operate the notification with Telegram, i changed the following parameter, “SetOption132 1”.
    Now the notification works correctly, even with the tmsend command from the console it works perfectly. There is still one problem, i get a notification only when I restart the module, “Router booted up”, but simulating the lack of internet connection, I receive no other notifications. In the console history, i understand that the code tries to send the module status when it detects that there is no network for 6 minutes, and fails precisely because the network is missing.
    How can I fix it?
    Thanks for your support.

    • The message “Router: Device is unresponsive…” and “Router: Device is unresponsive, restarting power” requires some sort of internet to be available. It is enough as long as there’s some kind of redundant internet.

      In theory, you could improve the code to wait a few minutes before sending another message to tell you that the router “was rebooted”, but this message could also be missing if the router does not boot fast enough, or if the network access doesn’t go up fast enough.

      So other option would be to improve the code even more, and send a message as soon as ping works again.

  9. Brilliant article – thanks, works a treat. And thanks for compiling up BIN with USE_PING (that was a step too far for me). Any chance you’ll recompile for 13.4.0 which includes the DevGroup functionality – so I can use that and PING together! 🙂

    • Ok, for now I am fixing the build for what I have, as it seems last time it failed (most likely because of an old version of the container image definition I’m using, as I have it fixed to a certain commit that I change when I need something newer of the build crashes).

      Next, I will check how much extra storage DevGroup requires. I don’t use it, so that’s the reason I am not including it, but if it doesn’t take much space and I can still use the resulting binary with my smart plugs, then I will enable it.

Leave a Reply

Your email address will not be published.


*


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