[Solved] Timer Demo Broken?

The rule “Timer Demo” in the demo.rules file is not working for me in (v1.7.1).

An error, Could not invoke method: org.openhab.model.script.actions.Timer.reschedule…
is reported when running the “Timer Demo” rule.

Is a separate download or addon needed for timer functions?

What is the full error message. Unfortunately the most important bit is in the “…”.

Rich

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

Thank you!

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.

} else {
    timer.cancel
    timer = createTimer(now.plusSeconds(5)) [|
        sendCommand(switch2_112, OFF)
    ]
}

In this version, instead of trying to reschedule it, you cancel the existing timer and create a new one.

Good luck!

Rich

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. :smile: