Another Timer Reschedule Question (Help)

Hi,

I’m running official OH 3.1.0 and Java:
openjdk version “11.0.11” 2021-04-20 LTS
OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS)
OpenJDK Client VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)

I have a rule whereby I want to perform a lock (zwave) only if the door is fully closed. If the door is open then wait 10 seconds and check again if the door is open. I’ve created a simulation rule which I’m hoping someone here can help me identify the cause of the error.

Many thanks for helping me here… Kind of not sure what I’m doing incorrectly.

rule "SIMULATION"
when
 Item TestSwitch changed to OFF
then
 val itm = triggeringItemName
 var Timer tmr = null
 val sec = 10

 logInfo("Simulation","[A] STARTING SIMULATION.")

 if (tmr === null) {
  tmr = createTimer(now.plusSeconds(sec), [ |
  val now = TestDoor.state
  logInfo("Simulation","[B] ITEM: {}, DOOR: {}", itm, now)

  if ( now == CLOSED ) { itm.sendCommand("ON")
   tmr = null
  } else {
   logInfo("Simulation","[C] THIS DOOR IS OPEN, RETRYING IN [{}] SECONDS.", sec)
   tmr.reschedule(now.plusSeconds(sec))
  } ] )
 }
end

And my items file:


Switch  TestSwitch
Contact TestDoor

And the error:

14:43:59.165 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'TestSwitch' received command OFF
14:43:59.194 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'TestSwitch' changed from ON to OFF
14:43:59.197 [INFO ] [.openhab.core.model.script.Simulation] - [A] STARTING SIMULATION.
14:44:09.222 [INFO ] [.openhab.core.model.script.Simulation] - [B] ITEM: TestSwitch, DOOR: OPEN
14:44:09.259 [INFO ] [.openhab.core.model.script.Simulation] - [C] THIS DOOR IS OPEN, RETRYING IN [10] SECONDS.
14:44:09.335 [WARN ] [core.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.reflect.UndeclaredThrowableException: null
        at com.sun.proxy.$Proxy1347.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:184) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:87) ~[?:?]
        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:829) [?:?]
Caused by: org.openhab.core.model.script.engine.ScriptExecutionException: 'plusSeconds' is not a member of 'org.openhab.core.types.State'; line 20, column 19, length 20
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:133) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:878) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:243) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluateArgumentExpressions(XbaseInterpreter.java:1222) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1152) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1098) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:878) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:243) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:475) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:251) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:492) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:267) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:475) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:251) ~[?:?]
        at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:227) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:213) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:47) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:30) ~[?:?]
        ... 10 more
at org.openhab.core.model.script.actions.ScriptExecution.lambda$0(ScriptExecution.java:82) ~[?:?]

The first part of the error tells you that it occurred inside a lambda. Any time you have [ | ] that’s defining a lambda. The only lambda in this code is passed to createTimer. Notice how lambda appears in most of those lines.

The second part of the error, the “caused by” tells you what went wrong inside that lambda. This is one of the cases where it’s a pretty good error message telling you exactly what’s wrong.

Caused by: org.openhab.core.model.script.engine.ScriptExecutionException: 'plusSeconds' is not a member of 'org.openhab.core.types.State'; line 20, column 19, length 20

The problem is you are trying to call plusSeconds on a variable that is of type State (i.e. it’s the state of an Item). And it goes on to tell you that it’s on line 20 column 19 in the .rules file.

Armed with this knowledge the error becomes obvious.

val now = TestDoor.state

You’ve overridden the implicit variable now with the state of TestDoor.

1 Like

Rich. Thank you so much. I can’t believe I didn’t see I was doing exactly that (now.). Wow. Much appreciated. I corrected my variable and this works perfect now…