You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 7, 2020. It is now read-only.
when
Item Utetemperatur changed
then
sendHttpGetRequest("http://www.temperatur.nu/rapportera.php?hash=supersecret&t=" + Utetemperatur.state)
logDebug("temprule", "Sending " + Utetemperatur.state + " to temperatur.nu")
if(timer_u == null) {
logDebug("temprule", "Setting timer")
timer_u = createTimer(now.plusMinutes(19)) [|
sendHttpGetRequest("http://www.temperatur.nu/rapportera.php?hash=supersecret&t=" + Utetemperatur.state)
logDebug("temprule", "Resending " + Utetemperatur.state + " to temperatur.nu and rescheduling timer")
timer_u.reschedule(now.plusMinutes(19))
]
} else {
logDebug("temprule", "Rescheduling timer")
timer_u.reschedule(now.plusMinutes(19))
}
end
(timer_u is declared as a global Timer)
What this is supposed to achieve is the following:
Every time the sensor reading changes, send the reading to temperatur.nu
If the reading has not changed for 19 minutes, send the reading anyway and reschedule the Timer
This means that during normal operation (ie the sensor is changed more often than every 19:th minute) the Timer is never executed, it's just rescheduled forward forever. If the temperature doesn't change in 19 minutes the Timer executed but is also rescheduled. So no matter what, it's supposed to be rescheduled indefinitely.
This almost always works the way it's supposed to. But then suddenly it happens that the Timer is supposed to be executed and simply doesn't. The last thing I see from this rule in the log is "Rescheduling timer" and then after 19 minutes when it's supposed to execute I get nothing. Everything seems to start working like it should again the next time I actually get a new reading.
I'll simply close this one. Turned out the problem was me rescheduling a timer from inside the timer's body, which I thought I could do. Apparently a timer is only executed once so that's never gonna work...
I have the following code in a openHAB rule:
(timer_u is declared as a global Timer)
What this is supposed to achieve is the following:
This means that during normal operation (ie the sensor is changed more often than every 19:th minute) the Timer is never executed, it's just rescheduled forward forever. If the temperature doesn't change in 19 minutes the Timer executed but is also rescheduled. So no matter what, it's supposed to be rescheduled indefinitely.
This almost always works the way it's supposed to. But then suddenly it happens that the Timer is supposed to be executed and simply doesn't. The last thing I see from this rule in the log is "Rescheduling timer" and then after 19 minutes when it's supposed to execute I get nothing. Everything seems to start working like it should again the next time I actually get a new reading.
The theory from the forum thread where this has been discussed (https://community.openhab.org/t/eliminating-lingering-timers/33755/19?u=danielmalmgren) is that maybe Timers are being garbage collected? If so, that's no good. When writing a rule you should be able to trust a Timer always being executed, no matter what.
The text was updated successfully, but these errors were encountered: