[SOLVED] Need help with a rule. only after 1 min

hello

i have this rule

rule "rain stop"
when
Item Rain_indicator changed to OFF
then
if (Tellmewhenitsstop.state == ON){
sendNotification("rain stopped")
Tellmewhenitsstop.postUpdate(OFF)
}
 else{  
return;
}
end

so when its stop to rain and “Tellmewhenitsstop” is on. i receive notification. i what to change it to if Rain_indicator changed to OFF for 1 minute. only then send me notification

thanks

You could setup a new item with an expire of 1 min and have that trigger a notification to you when it changes to OFF after 1 min.

1 Like

Use a timer:

rule "rain stop"
when
    Item Rain_indicator changed to OFF
then
    createTimer(now.plusMinutes(1), [ |
        sendNotification("rain stopped")
    ])
end
1 Like

but i also need to add the Tellmewhenitsstop.state == ON. so it will be like this ?

rule "rain stop"
when
Item Rain_indicator changed to OFF
then
if (Tellmewhenitsstop.state == ON){
createTimer(now.plusMinutes(1), [ |
    sendNotification("rain stopped")
 ])
}
end

and another question. does it send the alert in the end of the timer regardless of the Rain Indicator status? or only if its stay off for 1 min ?
thanks

It will send a notification if one minute before the " Rain_indicator changed to OFF".

If you need something to cancel the timer if “Rain_indicator changed to ON” again you have to enhance your rule.

Yes

No only when it changed to OFF as your rule says

i know. but i need this to send notification if the Rain_indicator stay off for 1 min. not 1 min after it changed to OFF

so if the “Rain_indicator” changed to OFF (and stay off for 1 min without changing to ON again) and “Tellmewhenitsstop” is ON, only then send the notification

Sorry if that was not clear

If Rain_indicator goes ON in the meantime, cancel timer by checking “changed to ON” in a rule.

so this is the 2 rules i need ?

rule "rain stop"
when
Item Rain_indicator changed to OFF
then
if (Tellmewhenitsstop.state == ON){
Rain_timer = createTimer(now.plusMinutes(1), [ |
sendNotification("rain stopped")
])
}
end

rule "rain stop 2"
when
Item Rain_indicator changed to ON
then
Rain_timer.cancel()
end

there is a way i can check the3 timer status ?

rule "rain stop"
when
    Item Rain_indicator changed to OFF
then
    if (Tellmewhenitsstop.state == ON){
        createTimer(now.plusMinutes(1), [ |
            if (Rain_indicator.state == OFF) { // It is still not raining after 1 minute
                sendNotification("rain stopped")
            }
        ])
    }
end
1 Like

That’s essentially right, but you can improve it

// global var so rules can share it
var Timer Rain_timer = null

rule "rain stop"
when
   Item Rain_indicator changed to OFF
then
   if (Tellmewhenitsstop.state == ON){
      Rain_timer = createTimer(now.plusMinutes(1), [ |
         sendNotification("rain stopped")
         Rain_timer = null  // clear timer away
      ])
}
end

rule "rain start"
when
   Item Rain_indicator changed to ON
then
   if (Rain_timer != null) {
      // timer is running
      Rain_timer.cancel()
      Rain_timer = null
   }
end

The rain can stop and start as often as it likes; you will get a notification 1 minute after the last time it stops. Personally I’d make that a bit longer but I’m in the UK :slight_smile:

1 Like

thanks!