Hi all,
i try to create a looping timer within a lambda. I already implemented a looping timer following the looping timer design pattern. But i have to created the timer in multiple rules, so i want to extract the logic into a global lambda which will run in every rule separately. Unfortunately i get a nullpointer while running the lambda.
This is my code:
var Timer nightFadingTimer = null
val createNightFadingTimer = [|
nightFadingTimer = createTimer(now, [|
//do stuff
//loop timer
nightFadingTimer.reschedule(now.plusSeconds(2))
])
]
rule "Presence"
when
Item Motion_Any changed to ON
then
if(nightFadingTimer === null || nightFadingTimer.hasTerminated) {
createNightFadingTimer.apply()
}
end
This is the exception:
2021-01-06 19:50:37.618 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.NullPointerException: cannot invoke method public abstract boolean org.openhab.core.model.script.actions.Timer.reschedule(java.time.ZonedDateTime) on null
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1161) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1151) ~[?:?]
[...]
at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:47) ~[?:?]
at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:30) ~[?:?]
at com.sun.proxy.$Proxy640.apply(Unknown Source) ~[?:?]
at org.openhab.core.model.script.actions.ScriptExecution.lambda$0(ScriptExecution.java:82) ~[?:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:166) ~[bundleFile:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:76) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
Its strange that it works if i replace the createNightFadingTimer.apply() call inside the rule by the code of the lambda itself.
Does anybody have an idea how to make it work?