Please be aware that offTimer.hasTerminated
will never be true. This condition is only true if the timer has run its code. The timer code first deletes the pointer offTimer
, so this will never be true.
Your rule "Reset Benachtiigung2"
cancels the timer, but does not delete offTimer
, so the condition is not met after this rule was executed.
It’s better to use changed
instead of received update
, because you want to trigger to the change, not the update.
So, the rules would be better something like this:
var Timer offTimer = null
rule "Benachrichtigung_2" // 15 Minuten nach öffnen des Tores
when
Item Sensor_Garagentor changed
then
logInfo("Hinweise", "Sensor Garagentor ist: {}",newState)
offTimer?.cancel
if(newState == OPEN) {
offTimer = createTimer(now.plusMinutes(15), [|
val telegramAction = getActions("telegram","telegram:telegramBot:89b7b984")
telegramAction.sendTelegramQuery("Das Garagentor steht noch auf. Soll das Tor jetzt geschlossen werden?", "Reply_Garagentor", "Ja", "Nein")
logInfo("Hinweise", "Sensor Garagentor ist: {}", Sensor_Garagentor.state)
])
} else {
val telegramAction = getActions("telegram","telegram:telegramBot:89b7b984")
telegramAction.sendTelegram("Das Garagentor wurde geschlossen.")
}
end
/* ---------------------------------------------------------------------------------------------------------------------------- */
rule "Reply handler for Garagentor"
when
Item telegramReplyId received update Reply_Garagentor
then
val telegramAction = getActions("telegram","telegram:telegramBot:89b7b984")
if (telegramMessage.state.toString == "Ja") {
Garagentor.sendCommand(ON)
telegramAction.sendTelegramAnswer(telegramReplyId.state.toString, "Ok, das Garagentor wird geschlossen.")
} else {
telegramAction.sendTelegramAnswer(telegramReplyId.state.toString, "Ok, das Garagentor bleibt offen.")
}
end