Help. Automatically locking back door

I have a rule to lock the back door 10 minutes after it closes. The rule locks the door 10 minutes after the door contact senses the door is closed. The problem is that, if I come and go, the door locks 10 minutes after the door closes the first time, regardless of what has happened in the meantime. This means that if I'm going in and out, the door will lock at inopportune times, including when it's open.
How do I build the rule so that if the door opens again, the timer resets. I built a IF THEN condition that if the door contact changes to open, then the rule exits. now it doesn't seem to lock at all.
I'm sure it's simple, but I can't figure it out.

Here is the rule I use

1 Like

Thank you JNS. My issue may be with using an 'exit rule ' command, rather than a 'cancel delayed action' command. Too many choices sometimes when you are trying to build rules. I'll spend some time tomorrow trying to build something that works better.


Sounds like you're using "Exit Rule." Lots of people seem to think this does something that it doesn't. What it does do is stop running additional actions/steps in your rule; what it doesn't do is un-schedule anything that may have been scheduled or "subscribed" to by previous actions: delays/delayed actions, waits, etc. To cancel a delay, you need to set the "Cancel?" flag on your delay or delayed action (there are subtle differences between the two, but that's another story and generally inconsequential if there is nothing after it), and then you need a "Cancel Delayed Actions" action somewhere to actually do it. (You'll see some people use the "Cancel Rule Timers" action here, which will cancel any delay with or without "Cancel?"/"cancelable" set on it. This also does a lot more, and I would not recommend using it unless you know what it entails; people presumably arrived at this by trial and error, not by reading the documentation.)

The Rule 4.0 docs (forum thread or official wiki docs--about the same but the inline screenshots on the forum are probably easier to read) are something I'd recommend reading. Some parts of them are geared towards Rule 3.0 readers and show how to upgrade or re-think rules, but you can ignore the previous-version comments and just see examples of how to do things in 4.0. While it's a different outcome, in your case, I think the motion lighting examples with cancelable delays would be a good place to start. You want almost the same thing, except you want a trigger for "lock changed" instead of "motion changed," an IF that checks for lock state instead of motion sensor state, and actions that either lock the lock after a delay (say, under "IF unlocked...") or cancel that delay (say, under "ELSE") instead of turning on/off lights--different devices, events, and actions, but it just shows you the most common paradigm in RM for delays and cancellations.

Hope this helps!


Wow! Thank you for the detailed reply. I'll be trying to rebuild my auto-lock rule tomorrow. While I am really enjoying Hubitat, every time I build a rule I'm reminded of just how amazing Stringify was. The 'killer app' for Hubitat would be a Stringify-style graphical interface for basic rules.

1 Like


Use the original author's new updated code so it gets updated.
I'll be switching soon.


Thanks for this, as you say it would be nice if it was built-in and not something you have to hunt for.
Certain simple functions, like Auto Door Lock, are usually not that simple with this hub.

Yea they've got a list of priorities, currently they're tracking down some major issues that I've luckily been avoiding.
I also wonder if there's some sort of liability they'd want to avoid, but then again they've got HSM, so I don't know where they draw the line on security and safety features.

The hub is mostly an open canvas and Rule Machine is a good tool for accomplishing most of the needs of most people.
They may have added a way to share rules but I think that'd be a killer feature if you could share rules like you could with WebCoRE and just swap out the devices for your own.

Rule Machine is also proving to be a little slower than Home Assistant talking directly to the Hubitat devices through the Maker API, which is blowing my mind.
So they've got their work cut out for themselves. :stuck_out_tongue_winking_eye:

I'm going to highjack this thread a bit for some help with an auto-lock rule I just created based on @JNS 's post here. I've created several so far (one works but it locks the front door whether it's locked or unlocked after 15 minutes) and finally decided to come on here for some help.

Can anyone tell me if this should work? I can test it out in the morning but I was unable to find some of the exact verbiage that JNS's image showed.



Caveat emptor - I don't know Rule Machine very well. However, I think a simple rule like this will do what you want.

  1. If the back door is closed (as indicated by a contact sensor on the door)
  2. Then after a 10 minute cancelable delay the lock is locked
  3. During those 10 minutes, if the door is opened, then the lock action is canceled.


1 Like

Thanks I'm going to try this after work. I was using Cancel Timed Actions which seems to be different than Cancel Delayed Actions. After reviewing the Rule4.0 documentation I see I chose the wrong Action category.

1 Like

@aaiyar, I like the simplicity of your rule, but would worry about the slim chance of the lock command being cancelled just as time runs out. I'd change the timeout on the "wait for the door to open" to 10:10 so there is no chance it will time out before the lock delay. Nice use of delay and timeout though.

Well, this is cool. I've been out of the home automation world for a few years - had some moves and rentals that I couldn't do much in - and completely forgot I wrote this app. Now I'm back in it and now on Hubitat, so very cool to see this being useful. Thanks to @danabw for messaging me about this - I'm going to work on getting a Release thread in code share and see if I can figure out how to get this onto Hubitat Package Manager.


Welcome back!
I had to check my post to make sure I was respectful to the original author and I think I was.
Hubitat is picky about running code ported from SmartThings but yours hasn't been the cause of any slow downs on my hub... I think...
Looking forward to any official changes you make!


You definitely were, thanks for the credit. :slight_smile:


Been running perfectly for me, and haven't noticed any ill affects on my hub. Love the app's simplicity and reliability! Thanks for posting the app, and funny how perfect the timing was on my reaching out to Chris just as he's joining HE. :slight_smile:

Just found this thread. I will be installing door strikes on my front and back doors. These will be operated by a relay on an Arduino. I will have a magnetic reed switch to indicate when the door is shut or not. How can I use this without a real "Lock" device??

Download the Hubitat app