openHAB 2.4.0.
I have a rule that can monitor “open” items (windows) and count how many minutes it is open. However, it seems when I open 2 windows at the same time, then after a while the rule runs into an exception and it stops monitoring one window.
For each item to monitor, it has to be in the group “Timed” and there must be a helper item with the name “_Minutes” appended.
import java.util.Map
val Map<String, Timer> timers = newHashMap
rule "Timed"
when
Member of Timed changed
then
if(triggeringItem.state == ON || triggeringItem.state == OPEN) {
logWarn("Timed", triggeringItem.name + " = " + triggeringItem.state.toString)
val minutes = TimedMinutes.members.findFirst[ dt | dt.name == triggeringItem.name + "_Minutes" ]
minutes.postUpdate(0)
val timer = createTimer(now.plusSeconds(60), [|
logWarn("Timed", triggeringItem.name + " Timer fired")
val minutes = TimedMinutes.members.findFirst[ dt | dt.name == triggeringItem.name + "_Minutes" ]
val current = minutes.state as Number
val newValue = current + 1
logWarn("Timed", "New value = " + newValue)
minutes.postUpdate(newValue)
val timer = timers.get(triggeringItem.name)
timer.reschedule(now.plusSeconds(60))
])
timers.put(triggeringItem.name, timer)
} else {
logWarn("Timed", triggeringItem.name + " = " + triggeringItem.state.toString)
val timer = timers.get(triggeringItem.name)
if(timer !== null) {
timer.cancel()
timers.remove(triggeringItem.name)
}
val minutes = TimedMinutes.members.findFirst[ dt | dt.name == triggeringItem.name + "_Minutes" ]
minutes.postUpdate(0)
}
end
When the problem happens, I get 2 exceptions and I can see this in the log (I have reduced the output of the exception):
2019-07-10 09:49:44.729 [WARN ] [eclipse.smarthome.model.script.Timed] - HM_FensterSchlafzimmerLinks_1_StateContact Timer fired
2019-07-10 09:49:44.729 [WARN ] [eclipse.smarthome.model.script.Timed] - HM_FensterSchlafzimmerMitte_1_StateContact Timer fired
2019-07-10 09:49:44.730 [ERROR] [org.quartz.core.JobRunShell
java.lang.IllegalStateException: null
at org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference.doCopyInto(UnboundTypeReference.java:677) ~[?:?]
2019-07-10 09:49:44.730 [WARN ] [eclipse.smarthome.model.script.Timed] - New value = 225
2019-07-10 09:49:44.748 [ERROR] [org.quartz.core.ErrorLogger
threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
One of the timers continued to work and the other one got the exception and so stopped monitoring the open window.
I can only imagine that perhaps triggeringItem was null for one timer in the short lambda code.
What is the definition, meaning what is supposed to happen if 2 items of a group fire at the same time when I am using “Member of abc changed”?
Any ideas? Thanks!