Rich is right. You should use more logInfos to get the information about the system…
One logInfo could be right at the beginning of the rule.
After “then” you can have a logInfo to log your item state and the timer state. This is the base for the further computing… When these states are not in the requested state things go wrong…
At the end of the day adding .state obviously did the trick. Added some loginfos but sometimes this obviously isnt logging anything.
However, I tested both to notify if 15 minutes are reached or not notify if closed before and everything seems to work.
Thanks a lot to everyone guiding me.
For the records and in case someone stumbles over this, final rule at the end.
Cheers,
Ben
var Timer gaestewc_Timer = null
var Timer haustuer_Timer = null
rule "Notify if window in guest toilet is open for too long"
when
Item fenster_gaestewc changed
then
if (fenster_gaestewc.state==CLOSED)
{
if (gaestewc_Timer !==null)
{
logInfo("timer","[Timer] Fenster Gäste-WC geschlossen. Timer wird abgebrochen...")
gaestewc_Timer.cancel
gaestewc_Timer=null
}
}
else if (fenster_gaestewc.state==OPEN)
{
if (gaestewc_Timer===null)
{
gaestewc_Timer=createTimer(now.plusMinutes(15))
[|
logInfo("timer","[Timer] Fenster Gäste-WC über 15 Minuten offen. Sende Notification...")
sendTelegram("bot2", "Das Fenster im Gäste-WC ist seit 15 Minuten offen!")
]
}
}
end
rule "Notify if frontdoor is open for too long"
when
Item hausflur_haustuer changed
then
if (hausflur_haustuer.state==CLOSED)
{
if (haustuer_Timer !==null)
{
logInfo("timer","[Timer] Haustür geschlossen. Timer wird abgebrochen...")
haustuer_Timer.cancel
haustuer_Timer=null
}
}
else if (hausflur_haustuer.state==OPEN)
{
if (haustuer_Timer===null)
{
logInfo("timer","[Timer] Haustür geöffnet. Starte Timer...")
haustuer_Timer=createTimer(now.plusMinutes(15))
[|
logInfo("timer","[Timer] Haustür über 15 Minuten offen. Sende Notification...")
sendTelegram("bot2", "Die Haustür ist seit 15 Minuten offen!")
]
}
}
end