Re-Lock After A Certain Time If Lock is Unlocked

I am having some trouble wrapping my mind around how to do this. I have a simple rule that locks my August door locks at 9pm. I want to create a rule the re-locks the doors if they become unlocked between the hours of 9pm and 9am. Maybe delay them for a minute after they become unlocked.

Welcome to the community!
This rule was created in Rule Machine. It is set to lock the door if conditions are met. The doors need to be closed via contact sensors. If the door opens, then the lock will cancel the timer.. Otherwise it locks after two minutes.
I hope this helps you.

There are other recommendations because this rule isnt set up to the new way, and I'm not good at it. I suggest checking out the video on the youtube channel about keeping your rules simple, but feel free to use this rule until you get your feet under you. I don't use this rule any more, but it's worked for over two years flawlessly. Unless I ran into communication issues. I just tested it and it's rock solid, but just not in the simple way that's recommended now.
you would just need to add a condition to the bottom part for the time restriction. And the time is between _and _ then lock delayed 2 minutes


@mitch - welcome to Hubitat!

So I think this would be a simplified rule to run your automation that is only triggered when the lock is unlocked.

Screen Shot 2020-05-22 at 9.46.04 PM

Caveat emptor - I'm not a rule machine expert.

Also, this is the episode of Hubitat Live! that @april.brandt referred to, in which @bravenel demonstrated how to simplify rule machine automations. My take home message from that episode is that a trigger value of *changed* is not the best choice in most cases. And to coalesce conditions to minimize the overall number of conditions.


I have a contact sensor on my front door which is rarely delivery/package pickups...this is the rule I use

Thanks everyone. I will check into these.

Can someone walk me through the logic for the highlighted portion below. I'm a new to Hubitat and I'm trying to figure out how the cancel works. What does the wait for events and cancel do exactly?

Logic Question

My rule initially stopped after the delayed lock and didn't have a cancel.

Cancel delayed actions cancels the top if that line evaluates to false during that 1 minute delay.
The wait for events will time out if it does not happen within the minute ten and will then need another trigger event before anything happens again.

1 Like

I set up a very simple auto-locking rule under the Rule Machine by:

-Creating a "Periodic Schedule" for every 15 mins
Hubitat auto-lock1

-The I created an action to lock with two conditions (the lock is unlocked and the time is between 9pm to 7am)


Welcome to Hubitat.

Just as an FYI - your role isn’t going to work that way you believe it is. You need to make use of the conditions in the rule using IF blocks.

simple and works every time on both my locks,

Thank you! I just realized that the next day and fixed it using IF, THEN statements :wink:
Hubitat auto-lock2

1 Like

The only issue with your rule is that every 15 minutes during the day it will attempt to relock the door even if it is already locked. This may put drain on the lock battery (depending on your specific lock type). Something like the rule from the community member directly above your post :point_up_2: is worth considering because it only tries the relock if the lock is indeed unlocked. I think however, if the door is manually locked during that 15 minutes delay then it may still trigger because there is no cancel action set up. Lock rules can get quite complicated quite quick!


I would change your rule to this:


That way you're not unnecessarily locking the door every 15 minutes.

In this example, my door lock is named "Garage Door Lock Reliable". I also forgot to add an "END IF" when creating my example, but you get the point.

Thank you!
I actually had already changed it to something similar. I too added the condition where it checks to make sure the lock is unlocked before trying to lock it. I had forgotten to update this thread.
Hubitat auto-lock3