Need some help with Door State Timer please

  • Platform information:
    • Win10 - Intel Core i3, 16 GB Ram
    • Zulu 8.26
    • openHAB version: 2.5

I monitor our Frontdoor with the following little script:

// var timer
var Timer eingangstuerTimer = null

// rule
rule "Eingangstuer seit 10 min offen"
    when
        Item Eingangstuer changed
    then 
        if(Eingangstuer.state===CLOSED) {
            if (eingangstuerTimer!==null) {
                eingangstuerTimer.cancel
                eingangstuerTimer=null
            }
        }
    else if (Eingangstuer.state===OPEN) {
        if (eingangstuerTimer===null) {
            eingangstuerTimer=createTimer(now.plusMinutes(10)) [
                sendTelegram("botben","Eingangstuer seit 10 min offen")
               ]
        }
    }
    end

I found the script here > /Rule optimization: Window OPEN reminder

It worked like it should for some month, but since a few days, i get 2 or 3 times a day the message, Door is open, but the Door is still closed, when i check it.
How could i check the State in the script again, before it sends a message?
Thank you!
Ben

  1. Only use === when comparing to null

  2. What states are Eingantgstuer going through ten minutes before the alert? If it changes to NULL or UNDEF the Rule will still trigger and the timer will not be cancelled.

The same way you do in the Rule.

            eingangstuerTimer=createTimer(now.plusMinutes(10)) [
                if(Eingangstuer.state == OPEN) {
                    sendTelegram("botben","Eingangstuer seit 10 min offen")
                }
            ]