[SOLVED] "cancel" not working for timer anymore?

I’m just setting up openHABianPi and am copying some rules across from my current LIVE system.

I have a basic rule that checks to see if a door has been open longer than a certain time…
I’m receiving the following error on the new system…

Rule ‘Stairs Door Timer’: ‘cancel’ is not a member of ‘java.lang.Object’; line 43, column 9, length 23

But it works fine on the old system?

rule "Stairs Door Timer"
    Item Xiaomi_WindowSwitch01_Status changed
    if(Xiaomi_WindowSwitch01_Status.state == OPEN){
        // a Timer isn't already running
        if(stairdoortimer === null) {
            stairdoortimer = createTimer(now.plusMinutes(1), [|
                // send alert
				Echo_Kitchen_TTS.sendCommand('The stairs door has been open for a minute. Please can you close it!')
                stairdoortimer = null // stairdoortimer the timer variable so we know the timer is no longer running
    else if(Xiaomi_WindowSwitch01_Status.state == CLOSED){
        stairdoortimer.cancel() // cancel the timer if it is running
        stairdoortimer = null

Is it a persistent problem or does it only occur during startup? Or does it occur when the .rules file is loaded?

What version of OH are you coming from and migrating to?

Is it safe to assume that stairdoortimer is declared as a global in this .rules file?

Hey Rich,

Am migrating from a windows machine running 2.3.0 to the openHABian which is 2.4.0 Build #1400

The stairdoortimer is declared at the top of my rules file…

I’ve done a reboot and the error seems to occur every time the rules fires…

How is it declared?

var Timer stairdoortimer = null


var stairdoortimer = null

or some other variant?

Currently I have it set as…

var stairdoortimer = null

I’m surprised this ever worked. When you initially assign a variable null there is nothing to tell the Rules DSL what type you really want so it reverts to the lowest common denominator, Object.


var Timer stairdoortimer = null

and that should fix this problem.

Thanks @rlkoshak this fixes the issue… Makes me wonder how it’s working on my old system? But it’s working on the new system so I’m happy… Thanks for your assistance!