Simple Zwave Un/Lock Door Automation

Hi All,

Still very new to HA as I am a recent convert from SmartThings.
All I’m doing at the moment is what I think to be a very simple automation but I can’t seem to get it right. I’ve got 2 automations, one for when I leave the house to lock a z-wave lock, and the second is to unlock when I arrive home. My cell phone is what is being tracked for presence.

The “Leaving” automation seems to trigger very well. I notify myself that the door is being locked behind me and I verify it’s state after I leave, and I am also verifying that my status is actually showing as not home. The issue I am having is that my “Arrival” automation never triggers. The odd thing is all I’ve done is copy the Leaving automation and just flip the to/from trigger and the lock state. When I check my status, HA sees that I am home. Below is what’s in my automation.yaml file.

I’m sure it’s just something obvious, but this has not been fun times trying to figure out a simple automation like this :confused:

Leaving Automation:

- id: '1613771085138'
  alias: Lock Door when Leaving
  description: ''
  trigger:
  - platform: state
    entity_id: person.jack
    from: home
    for: 00:01:00
    to: not_home
  condition:
  - condition: state
    entity_id: binary_sensor.garage_entry
    state: 'off'
  action:
  - service: notify.mobile_app_oneplus_7pro
    data:
      title: Left the House
      message: Door locked as you left the house.
  - device_id: ---------------------------------------------
    domain: lock
    entity_id: lock.garage_entry_lock_current_lock_mode
    type: lock
  mode: single

And this is the Arriving automation that never triggers:

- id: '1613771310663'
  alias: Unlock Door when Arriving
  description: ''
  trigger:
  - platform: state
    entity_id: person.jack
    from: not_home
    for: 00:01:00
    to: home
  condition:
  - condition: state
    entity_id: lock.garage_entry_lock_current_lock_mode
    state: 'off'
  action:
  - service: notify.mobile_app_oneplus_7pro
    data:
      title: Welcome Home
      message: Welcome home, let me get the door for you!
  - device_id: ------------------------------------------------------
    domain: lock
    entity_id: lock.garage_entry_lock_current_lock_mode
    type: unlock
  mode: single

You should also change the condition in your arrival automation, currently you check whether it is off (=unlocked), but you should check if it is on (=locked).

Thanks for catching that!
I revised and reloaded the automation.yaml file and tested it this morning but to no avail.
I think I’ll try just removing the condition altogether and see if that makes a difference.

Also check if the action part works, by executing the automation manually.

Yes, I tested that when I wrote the automation and I also tested it again just now to be sure.

As much as I am enjoying how much stuff can be integrated into HA as compared to SmartThings and how much freedom there is to mix and match the interface, it’s little things like this I am finding it very difficult to get used to because of how much effort it takes. Sensing my wife’s presence (through her iPhone) has also not been fruitful … but that’s for another topic i’ll need to start up.

If your lock is a lock entity, use the lock.unlock and lock.lock service to unlock and lock.

Unlock automation

- id: '1586073483037'
  alias: arriving home disarms alarm and unlocks front door
  description: ''
  trigger:
  - entity_id: person.person_name
    platform: state
    to: home
  condition: []
  action:
  - data:
      code: xxxxx
    entity_id: alarm_control_panel.home_alarm
    service: alarm_control_panel.alarm_disarm
  - data: {}
    entity_id: lock.front_door_lock
    service: lock.unlock

That’s what he is doing, but he uses UI automations that’s why it looks different.

You can try removing the condition, the unlock command should be a no-op on an already unlocked door (except in this automation you will get the notification even if the door is already unlocked).
Then if that works, try the condition of ‘locked’ rather than ‘off’.
At least in my automations for door locked/unlocked, I test for the lock state being ‘locked’ or ‘unlocked’ rather than ‘on’ or ‘off’.
But I use the (deprecated) Zwave built-in integration, so I don’t know if that makes any difference.

So the removal of the conditions from both automations seems to trigger the automations correctly the past couple days (although I haven’t been out that many times).

Yes, those automations were through the UI. I’m very slowly delving into writing my own code because of how newb i am :smiley:

I guess if the locks dont unlock if it is already unlocked (and vice versa), it’s not really necessary for me to check for that in a condition then i suppose. I’ll just leave that part out completely.
I will leave this for the time being and monitor.

If there’s any more inconsistencies, i’ll report back. Thanks for everyone’s input!


On a side note, I’m not sure the community needs another topic about presence detection, so instead of starting something new, I’ll ask it here since it is somewhat related to my (un)lock automations.

Assuming everything above checks out and triggers, it is all well for detecting my presence.
The problem I face is that HA is not able to detect my wife’s device’s presence reliably. Her presence, like mine, is just attached to our mobile device (I have an android device, she has an iOS device).

For example, see the history bar graph of our two devices. Green is “home”, red is “not_home” and the purple is “work” (setup as a zone). My wife, “D”, somehow was able to make it to work Harry Potter style by disapparating from “home” to “work”. Not to mention, when you actually dive deeper into the actual time, she was at “work” 20+ minutes late so HA thinks she disapparated to work late.

Would this have to do with the fact that she does not have a data plan :roll_eyes: and thus makes tracking the device much less accurate? And why does it not pick up the “not_home” part when going from home to work?