I would like to get or develop a watchdog timer app

I have a Raspberry Pi that monitors the temperature inside my freezer in the garage. That temperature is sent to my Hubitat every 5 minutes. I have code that will set an alarm and do a notification if the temperature exceeds a specified value. What is missing is the ability to detect if the Raspberry Pi fails to send updates.

I would like to get or create (with some guidance) an app that serves as a watchdog timer. It would allow input to set the timeout interval and to start, stop, and reset the timer. If the timer is not reset before it expires it would set an alarm variable that would allow for actions to be taken (flash a light, sound a buzzer, send a notification, etc.).

When working correctly, the app (Maker App) receiving the temperature would reset the timer each time a new value was received. In my case, I would set the timer interval to allow for a few missed values before going off and triggering an alarm.

I have searched here and using Google to find an app to do this but have either overlooked or not discovered one.

Thanks for any information and/or guidance.

Maybe use Rule Machine instead of Maker API to update the value. As your trigger, create a "Local Endpoint" trigger, then have your HTTP call pass that value to the Rule. I might have the exact format wrong, but it would be something like this:

http://<hubIP>/apps/api/<appID>/trigger/<yourValue>?access_token=<accessToken>

Where all fields denoted with <...> are filled in with your actual values. In particular, yourValue here would be the temperature from the device.

Then, in your Rule Actions, the built-in %value% variable will be set to this value. I'm not exactly sure what you're doing with the device on the hub, but something like using "Run Custom" action to call setTemperature() on your virtual temperature device and passing in this variable should work:

Then after this add action, add something like:

Wait for event: elapsed time --> 0:05:00
Notify (mobile app device): "Temperature not sent after 5 minutes"

This works because a trigger cancels waits, so those 5 minutes will never pass if another event is sent within that time. (You might want to make this at least a few seconds longer -- or even longer -- if your device only sends out temperatures every 5 minutes, otherwise milliseconds of difference might get you in trouble, and I'm guessing you don't care that much -- but this is the general idea.)

4 Likes

I've been writing my own apps for automations, and once you get the basics down there is not much to it. I'm no expert, but I had some Java background and just started fiddling until I figured it out.

Start by looking at the Hubitat documentation on writing your own apps. If you can find code for a sync app between two devices, that will teach you a lot. I found an app that syncs a dimmer to a virtual fan controller when I was learning apps. That taught me how to add a device input, how to subscribe to an attribute in that device, and how to run a method when an event happens from that subscription.

In the app, you can use the runIn(seconds, method) method. It sets a schedule to run the method in how ever many seconds were set whenever it is called. So runIn(300, alarmHandler) would run the alarmHandler method in 5 minutes.

The nice thing about runIn(), the default is to update when you call the same method twice. So every time you call runIn(), it will delete the current schedule to run the method, and create a new one to run in the seconds from current time. So, if the temperature keeps changing, every time it changes it would call runIn() again to update when the alarm method will fire, which is what you are looking for. When no temp update happens, the method will run when the schedule finally fires since it is no longer being pushed out by new temps coming in.

The App would have a preference for one device with the capability of Temperature Sensor, and one device which is your variable. You can make a variable connector to make the variable a device with a variable attribute. When you run the app, you choose the temperature device and the variable device as devices.

In initialize() of the app, you create a subscription to "temperature" for the temp device, to run a method that will call the runIn() method.

subscribe(freezerTemp, "temperature", temperatureHandler)

In the temperatureHandler() method, that runs every temp update from the subscription to the temperature event, you call runIn().

runIn(300, alarmHandler)

In the alarmHandler method, when it finally actually gets called when the timer is no longer getting pushed out, you update the variable device. If you use a string variable, it could get set to ALARM, which is your trigger in some other automations to actually make something alarm. You can call this attribute whatever you want, and that is what your automation will work with. Maybe just call it "alarm" and make it a boolean value for true and false.

You will also need to set some preferences in the app for the time to alarm that will be a variable to use in your runIn() method, like a wait time. runIn(waitTime, alarmHandler).

You will also need a way to reset the alarm. You could do it manually in the variable device, or add a virtual button to the app, subscribe to it, and then when pressed, resets the variable to OK or false.

I probably could have written this app in the time it took to write this :smiley:

1 Like

OK, this took me about five minutes. You can add a reset to it, I didn't add that.

Freezer Alarm.groovy

Thanks for the information!

Thanks for the suggestion!

I might have taken you a bit too seriously on that statement! A rule can do it for sure. I would just do that in Webcore as a one off, unless it fit into an existing app I could just throw it into.

I sort-of interpreted your statement as you wanted to do it with an app and you wanted to learn how to do it, so I guess my bad.

This app available in hubitat package manager might work for you. I use it on most of my devices with good success.

1 Like