Hopefully a quick one. I want to space out a command and have the spacing set a 1 second,
timer1 = createTimer(now.plusSeconds(1), [ |
but would like to reduce the delay to 250 milliseconds. I tried
timer1 = createTimer(now.plusMillis(250), [ |
but got an error in the log
script execution of rule with UID 'Kitchen_motion-2' failed: 'plusMillis' is not a member of 'java.time.ZonedDateTime';
After a lot of google, but I can’t seem to find an example of the ZonedDateTime member I need.
As a side note I have tried Thread :: sleep(250), but also must not be doing something right. Script execution of rule with UID 'Kitchen_motion-1' failed: The name 'thread' cannot be resolved to an item or type;
I have the timers setup and working, so prefer sticking with them, if possible, before finding the problem with the thread idea.
I have been meaning to update this: Nanos is a solution in the sense that it does not cause an error. However, at least with DSL, it does not appear to be recognized. I reverted to Thread::sleep( ).
I created this rule
rule "Test of Nanos vs seconds"
when
Time cron "0 43 15 ? * * *"
then
var Timer timer1 = null
var Timer timer2 = null
logWarn("events", "Pretimer")
if (timer1 === null) {
timer1 = createTimer(now.plusSeconds(1), [ |
logWarn("events", "One second timer")
])
timer1 = null
}
if (timer2 === null) {
timer2 = createTimer(now.plusNanos(2000000), [ |
logWarn("events", "two million nanos timer")
])
timer2 = null
}
end
With the following output
2022-01-18 15:43:00.407 [WARN ] [org.openhab.core.model.script.events] - Pretimer
2022-01-18 15:43:00.513 [WARN ] [org.openhab.core.model.script.events] - two million nanos timer
2022-01-18 15:43:01.410 [WARN ] [org.openhab.core.model.script.events] - One second timer
I know folks are migrating to other rule languages and the Thread::sleep() is an alternative, so it is not a big deal, but looks to be a bug.