#How to auto lock door when it's been closed for some time?

1 messages · Page 1 of 1 (latest)

fair siren
#

I have a smart lock and it has an auto-lock feature that locks itself after a set period of time. This has lead to some unfortunate cases where the door is thrown closed with the deadbolt out. I'm hoping someone knows how to author an automation that can do the auto locking but only when the door is closed. My first attempt made it seem easy where I can easily check that the door has been closed for 2 min and lock the door if it's unlcoked. But this now means any time the door is unlocked it's immediately locked again since it's been more than 2 minutes! I figure there's some condition I'm missing but nothing jumps out at me. Help would be appreciated!

wise plover
#

Share the YAML of your attempt

dry helmBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

wise plover
#

That's what you should do, and it won't act as you've described

fair siren
#
alias: Front Door Autolock
description: ""
triggers:
  - type: not_opened
    device_id: ********************************
    entity_id: ********************************
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - device_id: ********************************
    domain: lock
    entity_id: ********************************
    type: unlocked
    trigger: device
conditions: []
actions:
  - device_id: ********************************
    domain: lock
    entity_id: ********************************
    type: lock
mode: single
wise plover
#

all those things that you ***'d out aren't sensitive

fair siren
#

ah, ok

wise plover
#

in any case, that won't do what you were concerned about

#

But this now means any time the door is unlocked it's immediately locked again since it's been more than 2 minutes!

#

that's not how that trigger works

fair siren
#

oh interesting. Whenever I unlocked the door manually it would immediately lock again

#

until I disabled the automation

wise plover
#

taht's because of the second trigger

#

it will trigger when the door is unlocked and immediately lock it

#

what's the point of that trigger?

#

your requirement was:

My first attempt made it seem easy where I can easily check that the door has been closed for 2 min and lock the door if it's unlcoked.

#

that doesn't require that second trigger

#

there's no need to check if it was unlocked or locked, just lock it

#

Seems like maybe you added the second trigger to see if it was unlocked when you really wanted to add a condition for that. Which you could do. But I wouldn't bother

fair siren
#

ooooh, I think i get it now

#

so only at the 2 min mark will this fire now?

#

if it's been locked for more time, it's still != 00:02:00

wise plover
#

when the door transitions to "closed" and stays that way for 2min

#

there's nothing about it being locked, just closed

fair siren
#

this might just be a logical question but can in the same automation I handle the case where it's unlocked but the door is never opened?

wise plover
#

you can add a trigger for the lock transitioning to "unlocked", but then you should add a condition that the door is closed to avoid the problem that you mentioned originally

fair siren
#

so it's

if door.is_closed_for(120) or (door.is_closed and lock.is_unlocked)
    lock.lock

?
I don't seem to be able to set a duration for the lock being unlocked

#

Or is that a limitation in the visual editor?

#

I'm kinda using that to discover what I can and can't do

wise plover
#

Should be exactly the same. As I pointed out in the docs, a state trigger is a state trigger

#

And no, I wouldn't characterize it that way

#

Two triggers

#

Door is closed for two minutes

#

Lock is unlocked for two minutes

#

One condition

#

Door is closed

#

One action

#

Lock the door

fair siren
#

Aaah, I see now

#

now I know what triggers and conditions are

#

I was trying to add a duration to a condition

wise plover
#

Conditions are instantaneous