Automation seems to skip an action

I have an automation that is supposed to unlock my front door if my Apple Watch or iPhone are within range of any of three bluetooth proxies. It seems to work sometimes, but mostly reports that the automation has unlocked the front door when in fact it is still locked.

The trigger is if a Reolink camera senses motion or a person. It then checks to see if the room where the door is has no motion in it, and if the door is closed.
The idea is that I only want the automation to unlock the door if there is no one present in the room where the door is or if the door is closed. This is intended to differentiate when I am inside or outside and within the range of the bluetooth proxy. I’m using Bermuda Trilateration.

The reason I have three rooms as conditions for my Apple Watch or iPhone is that the devices may report being in the vicinity of any of those three rooms when I am near the front door (ie workshop, garage or kitchen).

I have set up a notification to my iPhone if the automation runs to completion. Despite that being the last step in the automation, it often sends the notification even if the action to unlock the door has not been successful.

I can’t figure out why the behavior is inconsistent. Sometimes the door unlocks, sometimes it doesn’t.

If I approach the door, I get a notification from Reolink that the camera has detected motion. This happens very consistently, the camera motion sensing seems to work very well. If I test the various conditions in the automation, they all pass. But the door mostly remains locked, despite the notification being sent that the door is unlocked.

I am wondering if this is a timing issue or if there is another way to structure the automation such that the door actually unlocks when all the conditions are met.

Here is the YAML for the automation. I created the automation using the UI.

alias: Apple Watch or iPhone Unlock Workshop Door
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.reolink_driveway_person
      - binary_sensor.reolink_driveway_motion
    to: "on"
    enabled: true
conditions:
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.applewatch_area
        attribute: area_id
        state: workshop
      - condition: state
        entity_id: sensor.applewatch_area
        attribute: area_id
        state: garage
      - condition: state
        entity_id: sensor.applewatch_area
        attribute: area_id
        state: kitchen
      - condition: state
        entity_id: sensor.10063b1e9a3e020d_area
        attribute: area_id
        state: workshop
      - condition: state
        entity_id: sensor.10063b1e9a3e020d_area
        attribute: area_id
        state: garage
      - condition: state
        entity_id: sensor.10063b1e9a3e020d_area
        attribute: area_id
        state: kitchen
    enabled: true
  - condition: state
    entity_id: binary_sensor.workshop_presence_sensor_motion
    state: "off"
    enabled: true
  - condition: state
    entity_id: binary_sensor.workshop_motion_sensor_motion_2
    state: "off"
    enabled: true
  - condition: state
    entity_id: binary_sensor.workshop_entry
    state: "off"
    enabled: true
actions:
  - device_id: lock device id
    domain: lock
    entity_id: lock entity id
    type: unlock
    enabled: true
  - action: my_iphone
    metadata: {}
    data:
      message: Reolink Person or Motion detected, unlocked workshop door
      title: Workshop unlocked
mode: single

Other than the ID’s (which you don’t need to obfuscate), is that the actual action’s configuration? It looks like you deleted the action: device line form the unlock action.

FWIW, you can condense your conditions by including all acceptable values in a list:

  - alias: Check that Apple Watch is in one of the defined areas 
    condition: state
    entity_id: sensor.applewatch_area
    attribute: area_id
    state: 
      - workshop
      - garage
      - kitchen
      - workshop garage
      - kitchen
  - alias: Check that all workshop motion sensors are off
    condition: state
    entity_id: 
      - binary_sensor.workshop_presence_sensor_motion
      - binary_sensor.workshop_motion_sensor_motion_2
      - binary_sensor.workshop_entry
    state: "off"
    match: all  #This line is optional, 'all' is the default value

Thanks for the assist! I fiddled with the automation to try to condense it as you suggested, here is what I came up with. I’m still learning more about YAML so no doubt it can be condensed further. I wonder if that contributed to the issue where the unlock action was skipped occasionally? I just tried it and it worked to unlock the door. I’ll try it some more and see if it works consistently.

alias: Apple Watch or iPhone Unlock Workshop Door
description: Trigger is if AppleWatch or iPhone is in Workshop, Garage or Kitchen
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.reolink_driveway_person
      - binary_sensor.reolink_driveway_motion
    to: "on"
    enabled: true
conditions:
  - condition: device
    device_id: 9de2d1119b1984389d8acc9e09b708ca
    domain: lock
    entity_id: a8fe9925bd2f89716fc4ad4ee7b3b98c
    type: is_locked
    enabled: true
  - condition: state
    entity_id:
      - binary_sensor.workshop_presence_sensor_motion
      - binary_sensor.workshop_motion_sensor_motion_2
    state: "off"
    enabled: true
  - condition: state
    entity_id: sensor.applewatch_area
    attribute: area_id
    state:
      - garage
      - kitchen
      - workshop
  - condition: state
    entity_id: sensor.10063b1e9a3e020d_area
    attribute: area_id
    state:
      - garage
      - kitchen
      - workshop
  - condition: state
    entity_id: binary_sensor.workshop_entry
    state: "off"
    enabled: true
actions:
  - device_id: 9de2d1119b1984389d8acc9e09b708ca
    domain: lock
    entity_id: a8fe9925bd2f89716fc4ad4ee7b3b98c
    type: unlock
    enabled: true
  - action: notify.mobile_app_iphone
    metadata: {}
    data:
      message: Used Ring camera motion as trigger, AppleWatch area as condition
      title: Workshop unlocked
mode: single