Hello there,
I am looking for a hint how to create a timer in a groovy based script.
My initial attempt was
createTimer(org.joda.time.Instant.now().plus(2000)) {
logger.warn("timer expired")
}
but this leads to
Error: java.lang.NoClassDefFoundError: org/joda/time/Instant: org/joda/time/Instant
Dumping joda-time-2.10.2.jar into runtime/lib/ext
solves this error (so is that really required?) but createTimer
is still unavailable:
Error: groovy.lang.MissingMethodException: No signature of method: MyRule.createTimer() is applicable for argument types: (org.joda.time.Instant, MyRule$_execute_closure2) values: [2019-06-12T19:19:05.004Z, MyRule$_execute_closure2@3248f52a]: No signature of method: MyRule.createTimer() is applicable for argument types: (org.joda.time.Instant, MyRule$_execute_closure2) values: [2019-06-12T19:19:05.004Z, MyRule$_execute_closure2@3248f52a]
I guess I need to call createTimer
on a ScriptExtension Object (https://www.openhab.org/docs/configuration/jsr223.html#scriptextension-objects-all-jsr223-languages), but which one?
Sources reveal just one possible Match: the static org.eclipse.smarthome.model.script.actions.ScriptExecution#createTimer
… but ScriptExecution
is not immediately available to my script:
org.eclipse.smarthome.model.script.actions.ScriptExecution.createTimer(org.joda.time.Instant.now().plus(2000)) {
logger.warn("timer expired")
}
results in Error: java.lang.NoClassDefFoundError: org/eclipse/smarthome/model/script/actions/ScriptExecution: org/eclipse/smarthome/model/script/actions/ScriptExecution
Thanks