Last active
April 15, 2026 15:33
-
-
Save boltronics/18cb09762f5c6567025d5bec73243986 to your computer and use it in GitHub Desktop.
Tasmota Berry script to restart an attached unresponsive host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var host = "192.168.0.2" | |
| var host_short = "my-host" | |
| var wap = "192.168.0.1" | |
| var fail_count = 0 | |
| var fail_threshold = 5 | |
| var check_interval = 30000 | |
| var off_duration = 15000 | |
| var boot_delay = 300000 | |
| var cycling = false | |
| tasmota.add_rule("Ping#" + host + "#Reachable", | |
| def(value, trigger, msg) | |
| if cycling return end | |
| if value == true | |
| if fail_count > 0 | |
| print(host_short + " recovered after", fail_count, "failures") | |
| end | |
| fail_count = 0 | |
| else | |
| fail_count += 1 | |
| print(host_short + " unreachable, fail count:", fail_count) | |
| if fail_count >= fail_threshold | |
| cycling = true | |
| print("Threshold reached, power cycling " + host_short) | |
| tasmota.cmd("Power off") | |
| tasmota.set_timer(off_duration, def() | |
| tasmota.cmd("Power on") | |
| fail_count = 0 | |
| print("Power restored, waiting " + | |
| str(boot_delay / 60000) + | |
| " minutes before resuming checks") | |
| tasmota.set_timer(boot_delay, def() | |
| cycling = false | |
| print("Resuming ping checks for " + host_short) | |
| end) | |
| end) | |
| end | |
| end | |
| end) | |
| tasmota.add_rule("Ping#" + wap + "#Reachable", | |
| def(value, trigger, msg) | |
| if value != true | |
| print("WAP unreachable, skipping " + host_short + " check") | |
| else | |
| tasmota.set_timer(1000, def() | |
| tasmota.cmd("Ping " + host) | |
| end) | |
| end | |
| end) | |
| def check_pi() | |
| if !cycling | |
| tasmota.cmd("Ping " + wap) | |
| end | |
| tasmota.set_timer(check_interval, check_pi) | |
| end | |
| tasmota.set_timer(10000, check_pi) | |
| print(host_short + " watchdog started") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment