Timers and cancel 2 doorlocks

You cannot assign a Timer to an Item. You can make an Item behave like a Timer using the Expire Binding but that isn’t what you are doing here. You have defined two global variables at the top of your Rules file but if you have also defined those two as Items then that is the source of your error.

If I were to implement this I would:

  1. put the two lock switches into a Group Group:Switch:AND(ON,OFF) Locks. Locks will then be ON if both locks are ON and OFF if any one of them is OFF

  2. Trigger your Rule using changes to Locks.

  3. Use Design Pattern: Expire Binding Based Timers

Switch Unlocked_Timer {expire="5m,command=OFF"}
Switch Locked_Timer {expire="1m,command=OFF"}
  1. The rule becomes:
rule "door locks state changed"
when
    Item Locks changed
then
    // Both locks are unlocked, set the unlocked timer
    if(Locks.state == ON)  Unlocked_Timer.sendCommand(ON)

    // One lock was locked
    else {
        // The timer has gone off, set the locked timer
        if(Unlocked_Timer.state == OFF) {
            // Turn xiaomi gateway light to green

            // Set Locked timer
            Locked_Timer.sendCommand(ON)
        }
        else {
            // cancell the unlocked timer
            Unlocked_Timer.postUpdate(OFF)
        }
    }
end

rule "doors have been unlocked too long"
when
    Item Unlocked_Timer received command OFF
then
    // set the Xiaomi gateway light to red
end

rule "door was locked"
when
    Item Locked_Timer received command OFF
then
    // turn off the Xiaomi gateway light
end
3 Likes