# Simple watchdog using Sonoff

**URL:** <https://community.openhab.org/t/simple-watchdog-using-sonoff/46247>\
**Category:** Tutorials & Examples\
**Tags:** rules, openhab2\
**Created:** [June 10, 2018, 12:56pm UTC](https://community.openhab.org/t/simple-watchdog-using-sonoff/46247 "2018-06-10T12:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmknowles](https://community.openhab.org/user_avatar/community.openhab.org/pmknowles/32/19462_2.png) [@pmknowles](https://community.openhab.org/u/pmknowles)\
**Post date:** [June 10, 2018, 12:56pm UTC](https://community.openhab.org/t/simple-watchdog-using-sonoff/46247/1 "2018-06-10T12:56:03Z")

</div>

I have been having a problem with a Z83-V running Windows 10 sometimes freezing. This obviously stops openHAB from running. I’ve been looking for a simple watchdog timer (without having to flash non-standard Tasmota firmware.  
Tasmota has two useful features Blink and Backlog. Blink allows the output to be blipped for a variable time and Backlog allows a series of MQTT commands to be stored in the Sonoff.

First we need to set up the Sonoff in the Sonoff console to blink once for 1 second

1. Set up the Blink for 1 second  
cmnd/sonoff/blinktime 10
2. Set the Sonoff to resume after 1 blink  
cmnd/sonoff/blinkcount 1

Then to setup the Sonoff in Items. This will tell the Sonoff to blink for 1 second after a 6 minute delay.

```csv
Switch Watchdog "Watchdog" <switch> (GroundFloor) {mqtt=">[mosquitto:cmnd/sonoff-watchdog/backlog:command:ON:delay 3600;power1 3],<[mosquitto:stat/sonoff-watchdog/POWER:state:default]"}

```

Then we need to set up a rule which will run every 5 minutes. The first command clears any delayed commands in the Sonoff and the second then starts the 6 minute delay to blink the Sonoff output. If everything is running OK then openHAB will cancel the backlogged command after 5 minutes. However, if openHAB has stopped, the Sonoff will blip the power supply for 1 second and restart the PC.

```php
rule "Watchdog"
when
	Time cron "0 0/5 * * * ? *"
then
		publish("mosquitto","cmnd/sonoff-watchdog/Backlog","")
		sendCommand(Watchdog, ON)

end

```

The PC power supply is connected to the normally closed contacts of the Sonof and set to auto start on power fail. Obviously the trigger could be anything that can be set to repeat (provided it is a shorter interval than 6 minutes). I presume that the Sonoff could ‘stack’ the delays, but the 5 minute repeat seems reasonable anyway.

---

<div class="post-metadata">

**Author:** ![Thedannymullen](https://community.openhab.org/user_avatar/community.openhab.org/thedannymullen/32/73361_2.png) [@Thedannymullen](https://community.openhab.org/u/Thedannymullen)\
**Post date:** [June 11, 2018, 2:57am UTC](https://community.openhab.org/t/simple-watchdog-using-sonoff/46247/2 "2018-06-11T02:57:48Z")

</div>

why not just buy a pi and put openhab there? Or put linux on you z83? I have by far found linux more stable vs windows.

---

<div class="post-metadata">

**Author:** ![pmknowles](https://community.openhab.org/user_avatar/community.openhab.org/pmknowles/32/19462_2.png) [@pmknowles](https://community.openhab.org/u/pmknowles)\
**Post date:** [June 11, 2018, 12:06pm UTC](https://community.openhab.org/t/simple-watchdog-using-sonoff/46247/3 "2018-06-11T12:06:45Z")

</div>

Over the years I have tried linux in several guises (Mandriva, Red Hat, Ubuntu). I hate having to delve into the OS to have to add things like a USB wifi adaptor. The PC has frozen twice since I started in January – I think it is the Z83-V not Windows which is the issue.. On both occasions it was overnight with the result that the water heater didn’t come on and there was cold water. I have since modified the rule so that it now looks for an MQTT status update every five minutes from the watchdog so it tests the whole system rather than relying on a cron..

If you search openHAB and Tasmota watchdog solutions you’ll find people with issues with Pis and Linux too
