Determine device sensor based on state trigger when user enters zone

I want to create an automation to open the garage door when a user comes home in the car. The users have the Android Companion App and they expose the Android Auto sensor. I’m using this as the heuristic to know they are in the car when they arrive.

I trigger the automation based on the person entering the home zone. At that point, I want a condition that uses that person’s device’s Android Auto sensor. If they are connected to Android Auto, then the condition is met and the garage door opens.

alias: Garage arrival
description: ""
  - platform: state
    entity_id:
      - person.alice
      - person.bob
    to: home
    alias: The car returns home
    id: car_return
action:
  - choose:
    - conditions:
          - condition: trigger
            id: car_return
          - condition: state
            entity_id: <the android auto sensor of the person who triggered this>
            state: "on"
        sequence:
          - device_id: 1e26c93b3dbd46291bf969d4cc7f9e90
            domain: cover
            entity_id: cover.garage_door
            type: open

I can’t figure out how to associate the Android Auto sensor with the person. I looked at the trigger variables that are created from the state trigger, but couldn’t seem to make the connection between binary_sensor.pixel_6_android_auto and person.bob.

I’m not sure if templates is possible in entity_id. I have been burned on this before but you could give it a try.

          - condition: state
            entity_id: "{{ 'binary_sensor.pixel_6_android_auto' if trigger.entity_id == 'person.bob' else 'some other binary sensor' }}"
            state: "on"

That is one approach that would work. What I was hoping to achieve is to not have to hardcode the person’s device sensor. If Alice gets a new phone, I don’t want to have to remember to go update automations and templates.

If you name your phone then you won’t have that issue.

Ah, good point. Thanks for the help! I’ll standardize the device names to be device agnostic and then use some logic around matching the person to the device’s android auto sensor.

Thanks to @Didgeridrew’s response in this post, I was able to do this programattically instead of relying on naming conventions.

alias: Garage arrival
description: ""
  - platform: state
    entity_id:
      - person.alice
      - person.bob
    to: home
    alias: The car returns home
    id: car_return
action:
  - variables:
      users_aa_sensor: |
        {% set x = trigger.to_state.attributes.source %} 
        {{ 'binary_sensor.' + states[x].object_id + '_android_auto' }}
  - choose:
    - conditions:
          - condition: trigger
            id: car_return
          - condition: template
            value_template: "{{ is_state(users_aa_sensor, 'on') }}"
        sequence:
          - device_id: 1e26c93b3dbd46291bf969d4cc7f9e90
            domain: cover
            entity_id: cover.garage_door
            type: open
mode: single