When I issue a Lock command only trigger if the door is closed

We have an outbuilding that we want to have unlocked while we are in the yard. I have several automations and buttons that I use to lock the lock. I am struggling with how to create some routine that will only allow the lock to lock if the door is closed. Can someone point me in the right direction?

Typically I see this done as a virtual switch, used as an override in the rules/logic. However, that override virtual switch would have to be incorporated into each rule that can lock the door.

There is no way to prevent a rule from locking the door external of that rule.

Another options would be to make a Virtual Lock driver with integrated override switch (if there isn't one somewhere already), and have all logic write to that virtual lock driver, instead of directly to the physical lock. Then the virtual lock would be what actually sends the command to the physical lock.

1 Like

I have a lot of Rule understanding to go. What at first seems so simple, "don't lock the door unless it is closed" takes much more logic work. Thanks. I will begin again and puzzle through.

Within one rule, that logic is easy - you just add door contact closed as a condition for locking. Preventing the door locking if the door is not closed on a system-wide basis is where it gets challenging.

Another thought is if you only LOCK it via RM rules, you could easily make one rule that turns off the Private Boolean on the other rules any time the door contact is OPEN. And then add the Private Boolean as a run condition in each of those other rules.

That is about the same amount of work as I originally posted, but doesn't need the virtual lock / virtual switch to use as an override.

If you lock it from other places (apps other than RM, user apps, dashboard, etc) then the first path I mentioned is the only option I can think of.

1 Like

Thanks. I think I may be able to tackle the Private Boolean route. It seems more straight forward in my brain. I truly appreciate the pointers.

It might be easier to use a boolean variable rather than trying to use PB. Setting PB won't re-evaluate the rule when it changes. So, if the rule would have locked the lock while it's PB is false, it won't lock the lock when the PB is set to true. Learned that little tidbit the hard way.

The Boolean variable would be easiest if you do everything within RM. This way, you don't have to mess with another driver. Of course, that only works if all your buttons/automations are in RM. If they're anywhere else, the virtual lock devices @JasonJoel suggested is the way to go (IMHO). That way you won't loose the lock command form a button or other automation when the door is opened. Basically, you modify all your existing automations to lock the virtual lock then create a rule that when the virtual lock is locked and the door is closed, lock the real lock. To close things off you would need a trigger for when the real lock unlocks to unlock the virtual lock.

(i've now said lock more times in one paragraph than socially acceptable) :stuck_out_tongue_winking_eye:

1 Like

Thanks. I am getting closer to being even more unsure of how to do what might have seemed to be a simple task. I will give everything a try and see if I can get this worked out. The re-evaluating the rule part certainly makes sense so I will keep that in mind. Thanks again.

1 Like