good evening, I have this rule and I need to be alert when the device is offline and then offline when it’s 5 minutes offline and then online when it’s offline.
works: The device is offline and the device is online
does not work: Your device is offline for 5 minutes
please tell me where I’m doing wrong?
thank you very much mIREK
vysvětlení - router patro is router on first floor
import org.eclipse.smarthome.model.script.actions.Timer
val String mailTo = "XXX.cz@gmail.com"
var Timer Router_patro_Online = null
rule "Router patro status offline"
when
Item Router_patro_Online changed from ON to OFF
then
sendNotification(mailTo, "Router patro je offline!")
if(TimerRouter_patro_Online == null || TimerRouter_patro_Online.hasTerminated) {
TimerRouter_patro_Online = createTimer(now.plusMinutes(5), [|
TimerRouter_patro_Online = null
if(Router_patro_Online.state == OFF){
sendNotification(mailTo, "Router patro je offline 5 minut!!!")
}
])
}
end
rule "Router patro status online"
when
Item Router_patro_Online changed from OFF to ON
then
sendNotification(mailTo, "Router patro je online")
end
You’re Tiimer variable is named Router_patro_Online (which is also the name of an Item), but in the rule, you are using TimerRouter_patro_Online. So, it looks like you need to just rename the Timer variable to TimerRouter_patro_Online. You’ll then likely get a warning about using === for null comparisons, but it will still work even if you don’t correct it, but you should.
rule "Router patro status offline"
when
Item Router_patro_Online changed from ON to OFF
then
Router_patro_Online_Timer.sendCommand(ON) //Start timer
sendNotification(mailTo, "Router patro je offline!")
end
rule "Router patro status online"
when
Item Router_patro_Online changed from OFF to ON
then
Router_patro_Online_Timer.postUpdate(ON) //Stops timer
sendNotification(mailTo, "Router patro je online")
end
rule "Router online timer expired"
when
Router_patro_Online_Timer received command OFF // Timer expires
then
sendNotification(mailTo, "Router patro je offline 5 minut!!!")
end
If we’re talking alternatives… another option, assuming OP is using the Network binding (you could, if you’re not), is to just set the poll interval to 5 minutes, no retry. Or 2.5 minutes with one retry. No timer needed.