Timer.cancel not working

this rule worked fine in OH1.8:

import java.util.Timer
var Timer frontdoor_timer = null

rule "Door left opened too long"
when
    Item HM_Frontdoor_State changed
then
    if(HM_Frontdoor_State.state == OPEN) {
        frontdoor_timer = createTimer(now.plusSeconds(240)) [|
        	pushover("Haustür steht noch offen")
        	frontdoor_timer = null
        ]
    } else {
        if(frontdoor_timer!= null) {
            logInfo("FRONTDOOR","Canceling the Timer")
            frontdoor_timer.cancel()
            frontdoor_timer = null
        }
    }
end

since switching to OH2beta5 got the following error:

12:13:27.923 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Door left opened too long’: An error occured during the script execution: Could not invoke method: java.util.Timer.cancel() on instance: org.eclipse.smarthome.model.script.internal.actions.TimerImpl@38bcf6

Any clues?

This is definitely a wrong import.
Try org.eclipse.smarthome.model.script.actions.Timer instead (if it is necessary at all).

1 Like

Hello!
Not sure, but you can try
frontdoor_timer.cancel

I am with Kai, just delete the import line, than it should work in OH2

Thomas

Thanks Kai. Perfect! Solved the Problem.
Wonder why I pasted that import line :wink:

1 Like