My rule, only modified from original for switch name.
rule "Timer Demo"
when
Item switch2_112 received command
then
if(receivedCommand==ON) {
if(timer==null) {
// first ON command, so create a timer to turn the light off again
timer = createTimer(now.plusSeconds(5)) [|
sendCommand(switch2_112, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
timer.reschedule(now.plusSeconds(5))
}
} else if(receivedCommand==OFF) {
// remove any previously scheduled timer
if(timer!=null) {
timer.cancel
timer = null
}
}
end
The error:
2015-08-20 22:08:25.814 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Timer Demo’: Could not invoke method: org.openhab.model.script.actions.Timer.reschedule(org.joda.time.base.AbstractInstant) on instance: 0
That is odd behavior. I’ve seen some weird stuff with Timers but never this error, though I usually don’t reschedule Timers. Hopefully someone else can be of help. I’ve stumped.
In the mean time you can change the rule to the following which does essentially the same thing.
I am running java 1.8.0_51.
It complains about the ‘null’ keyword when initializing some other uninitialized variables during startup.
I changed the keyword ‘null’ to ‘0’ with the suggested modification and the rule now works.
The original Timer Demo rule works as well with all null keywords changed to 0.
I look forward to learning more about the Xtend language now!
I have tried at least four other home automation programs lately and openHAB is the only one still installed.