Presence and State Automations

I am attempting to setup automations for when I leave and arrive at home. I would like the garage door and deadbolt to close/lock on departure and open/unlock on arrival. I know that I can use my phone to check multiple things there, but as a safeguard, I also have an esp32 device that is in my truck that I would like to use as an additional check.

For departure, if I change from home to away and esp32 changes from online to offline trigger the departure routine. This seems to work reliably.

For arrival, my logic was that if phone changes from away to home and esp32 changes from offline to online, consider me home and trigger automations. Due to the home radius, which I have at 15 meters, I get into a race condition where geolocation shows I’m home before the esp32 connects and the automation fails.

Any suggestions?

Trigger on both the ESP and zone. Have both as conditions as well. This is how you AND triggers.

Below are the two automations that I have in place. I think the problem is the state change from away to home with the zone that causes the race condition. I set it up this way so that I could differentiate the me starting my vehicle to leave versus me arriving home. The departure worked when I left today, but the arrival did not.

Arrival Automation

alias: Shaun Arrival
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.vger_tracker_status
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - person.shaun
    from: not_home
    to: home
condition: []
action:
  - service: automation.trigger
    metadata: {}
    data:
      skip_condition: true
    target:
      entity_id: automation.automation_garage_car_door
  - device_id: bbbc338e485c93623d8d22f03883c0cd
    domain: lock
    entity_id: 7e041359e16c26eaccbbaf45d4d61a2c
    type: unlock
  - service: notify.mobile_app_sn_pixel7
    metadata: {}
    data:
      message: Preparing for your arrival.
mode: single

Departure Automation

alias: Shaun Departure
description: ""
trigger:
  - platform: state
    entity_id:
      - person.shaun
    for:
      hours: 0
      minutes: 1
      seconds: 0
    from: home
    to: not_home
  - platform: state
    entity_id:
      - binary_sensor.vger_tracker_status
    from: "on"
    to: "off"
condition: []
action:
  - service: automation.trigger
    metadata: {}
    data:
      skip_condition: true
    target:
      entity_id: automation.automation_garage_car_door
  - device_id: bbbc338e485c93623d8d22f03883c0cd
    domain: lock
    entity_id: 7e041359e16c26eaccbbaf45d4d61a2c
    type: lock
  - service: notify.mobile_app_sn_pixel7
    metadata: {}
    data:
      message: House is secured.
mode: single