Rule to lock the door not working as expected, need help spotting my logic error

Hi, I set up a simple rule and can't seem to figure out why it is not behaving as expected. I have a Zigbee contact sensor and a Schlage zigbee lock on my front door. Both work perfectly. I set up a rule to lock the door after a 30 second delay only if the contact sensor is closed and the door is unlocked. However the behavior I am seeing is the door locks after 30 seconds whether the contact sensor shows open or closed. Obviously I don't want the door to locked when it is still ajar. Here is the rule I set up. Anybody see the problem in this logic?

Thanks!

Change your triggers to changed.(You actually shouldn't need to make it changed I just think it makes it easier to troubleshoot) You do need 'canceled delayed actions' in there though.

Edit: You actually do need to make the triggers 'changed' because that is what will cancel the delayed actions. You want the delay canceled if the door is opened or locked by some other means.

Here is an example of my rule to do the same thing.

Rule Example

Lots of ways to do it but here is how I see it. Looks as if you would want to trigger off of the door sensor exclusively but also checking that the door is unlocked.

If sensor changes or lock unlocked

If sensor closed and lock unlocked then
lock door delayed 30
Else
cancel delayed actions
endif

To put it another way....the reason this is happening is because when you unlock the door, the rule is triggered because the lock is unlocked. At that moment the door is both closed and unlocked. That's when the delay starts.

The only thing i would add to @razorwing's is to make sure to put the "cancelable" on the delay.

Whenever you add a delay, ask yourself "Why am i putting that in" . If it's to give you time to do something, odds are you'll want to have something in the rule to also cancel the actions after the delay.

What you could also do is do a wait....if door is unlocked, wait for EVENT door closed. This would only lock the door after it is opened and closed again. It would not immediately lock the door after it was unlocked. Make sure you pick event and not condition in this case though, as the condition will be true immediately. Event waits for the next matching event from the device.

1 Like

Thanks for catching that.

1 Like

Thanks all for the quick and great replies. All is working as expected now.

3 Likes

Got my C7 and converting all my rules. My old rule was on rule machine 2.5 and I'm having trouble finding my logic issue. I have a contact sensor and each time the contact sensor changes state, I want my 60 minute lock delay to restart. This all starts from when the lock is unlocked. Right now it's just locking 60 minutes after unlocking.

Think I just add another trigger which would cancel the current wait and restart the clock. I'll try that.

you should look at event engine,, this is very easy to do there and if you put in a delay for an action it automatically reset the rule status so you dont have to use cancel, etc. I use it to do the things quiet down at night with a 10 minute delay, so if motion starts up again the clock is reset before arming the house. Much easier to do here than in rule machine..

1 Like

I love and use Event Engine, but the easiest way by far to lock a door that is verified closed, after a delay, is the app: Auto Lock Door.

Choose the lock, choose the contact sensor to confirm it's closed, and set the lock delay. Done, works 100% of the time for me, never seen it fail.

But DO check out Event Engine...a great app that provides tons of control very easily, and has a very active developer.

1 Like

I use the following logic and it works well.