Help with Temp Alarm Notifications - Push once every 'x' minutes


I have been reading up on creating threshold alarms for temp, humidity, etc and from what I have found it seems somewhat straightforward. What I would like more help on is finding and example code of this but with some delay on the push notifications so I don’t get a bunch of them every time my sensor updates (every minute). For example, if the temp falls below freezing, only send an notification every ‘x’ minutes. Any example code or detailed explanation would be helpful.


I would add a DateTime Item, at the point the temperature is below your treshold then update this with the actual date and a Switch item set to ON.

Add a rule in where - e.g. all 5 minutes - you check if the Switch item state is ON, then check if the refresh rate of your notifications is reached (e.g. 15 minutes) and send push, refresh the datetime item.
If the temerature treshold is above then set Switch to OFF.

From here:

var t1 = (SOULISS_TIMESTAMP.state as DateTimeType).calendar.timeInMillis
var DateTime t2 = new DateTime()
var DateTime diff = t2.minus(t1)


I do something similiar for my sensors using the expire binding to create timers.

1hr timer is switched on for the first notification and is automatically switched off after 1hr

Switch RainGaugeEmail_Timer "Rain gauge notifications paused 1hr" <time> {expire="1h,command=OFF"}

rule code to only send email if its been longer than 1hr since the last email ie timer has to be off

if ( RainGaugeEmail_Timer.state !== ON) {
                        sendNotification('xxxt@xxx' , 'Rain gauge tipped. New total = ' +  String.format("%.3f", newraintotal) + ' mm')
                        logInfo("Mobile_Alerts" , 'email & notification sent. Notifications now paused 1hr')
1 Like
1 Like


So this is what I got to work thank you

Switch Temp_Notify_Delay “Temp Notifications paused for x” {expire=“1m,command=OFF”}

rule “Low Temp Notification”


Item Temperature_FF_Office changed


if (Temperature_FF_Office.state < 9) {


     Send_via_App_Switch.state == ON

     logInfo("notifications", "Sending notification via app.")

     sendNotification("email", "Low Temp Alarm Office")




Also thanks to everyone else for the input as well :slight_smile:


on quick item, my alarm should have triggered every minute for the test but my log shows some gaps, any reason why this would happen ?.

2020-04-10 08:04:00.310 [INFO ] [smarthome.model.script.notifications] - Sending notification via app.

2020-04-10 08:05:00.310 [INFO ] [smarthome.model.script.notifications] - Sending notification via app.

2020-04-10 08:08:00.310 [INFO ] [smarthome.model.script.notifications] - Sending notification via app.

2020-04-10 08:10:00.335 [INFO ] [smarthome.model.script.notifications] - Sending notification via app.

Disregard, I think it is because I have my when statement looking for a change in the value not when it rcvd and update

That looks wrong. Is the statement with == in it supposed to be part of an if()? It does nothing useful as it stands.

As rossko said. Its not correct and I would do the test for not equals like I posted so that a null state does not cause problems.

Sorry I am not following, can you put it in “dummy” terms :).

Send_via_App_Switch.state == ON, this was part of another piece of code, I removed it and everything still works as it should.

Thanks for catching it

This means “Does Send_via_App_Switch.state equal ON?” and it returns either true or false. And you don’t save the returned true/false so that line effectively does absolutely nothing.

Send_via_App_Switch.state = ON means “Assign the value ON to the variable Send_via_App_Switch” which is closer to what you want. But as the docs say, that’s not how you change the state of an Item. To change the state of an Item you use either postUpdate when you just want the Item to change or sendCommand when you want the device that is linked to that Item to do something.

You almost certainly want to use Send_via_App_Switch.sendCommand(ON).

You actually do it right just a few lines later.