Potential Issue with Automation

so i created this automation, and have recently noticed after the lock unlocks due to home-away status, it nearly immediately unlocks itself.

Code looks ok to me, but I am brand new at this so I’m likely missing something. Please help!!

- id: door_lock_presence
  alias: Unlock door on arrival
  trigger:
    platform: zone
    entity_id: device_tracker.life360_ken, device_tracker.life360_katie, device_tracker.addieiphone
    zone: zone.mt_airy_home
    event: enter
  action:
    service: lock.unlock
    entity_id: lock.frontdoor_lock_locked
- id: door_lock_nopresence
  alias: Lock door on departure
  trigger:
    platform: zone
    entity_id: device_tracker.life360_ken, device_tracker.life360_katie, device_tracker.addieiphone
    zone: zone.mt_airy_home
    event: leave
  action:
    service: lock.lock
    entity_id: lock.frontdoor_lock_locked

could you explain with more details what exactly did you do and what happened?

so when any of the aforementioned entities leave zone: “mt_airy_home” the service: lock.lock is called and locks the door.

However, immediately after said lock is locked, it then auto-unlocks.

by the first automation or by something else?

What if for all the people who remain at home, their device_tracker regularly reports “enter”. It means that just a moment after your device_tracker reports “leave” (and the lock is locked) someone else’s device_tracker reports “enter” (and the lock is unlocked).

I don’t know for a fact if that is how your device_trackers work but it would explain the behavior you’re observing.

I believe you can replace the two automations you are using with this one (untested because I don’t have device_trackers and zones):

- id: auto_lock_control_presence
  alias: automatic lock control
  trigger:
  - platform: zone
    entity_id: device_tracker.life360_ken, device_tracker.life360_katie, device_tracker.addieiphone
    zone: zone.mt_airy_home
  action:
  - service_template: "lock.{{'unlock' if trigger.event == 'enter' else 'lock'}}"
    entity_id: lock.frontdoor_lock_locked
  - service: system_log.write
    data_template:
      level: warning
      message: "{{trigger.entity_id}} reported {{trigger.event}}"

It will also report (to the system log) which device_tracker did what (enter or leave). You can then refer to the log to see which entity is responsible for unlocking the lock.

1 Like

Check out the 10:16 timestamps

Silly question…does the door lock work normally? i.e. if you manually push the lock button, does it stay locked?

Is it possible it tries to lock, but the door isn’t fully aligned so it fails then switches back?

What kind of lock is this? How is it integrated?

It’s a Schlage connect connected via zwave USB. Yes it always works on its own like it should.

I’m going to try to observe it when I get home I almost wonder if somehow homeassistant is not reporting the state correctly or the lock is not recording the state correctly

That’s the Logbook, not the system log. The automation I offered you reports which tracker did what.

Anyway, solve it whatever way you feel is best for you. Good luck.

Can I ask why not use “home” and “not_home” as the trigger vs the zone enter/exit? That’s what I use although I don’t automate unlocking my house…

I dont know, I’m still new to this…is one better than the other?

I will give it a try, thanks.

I mean it should work pretty much the same … but from my personal experience to accomplish having something happen when someone comes or goes I use “home” and “not_home” with the person entity with a couple device_trackers in it to prevent it falsely or briefly switching back and forth … there is also a consider_home option to delay the marking of someone as “not_home” which may be what’s happening if a phone briefly switches WiFi, goes to sleep, etc… and the automation @123 showed you will help you troubleshoot that.