I had thought about this, but my car requires a cable for Android Auto, and I wasn’t sure if a BT connection would always be present. I guess that’s the best that is currently possible? I’m tryingt to implement this generically (using templates) so that it also works for my wife’s phone.
For anyone else who’s interested, here’s what I have so far:
A template sensor for all mobile_app
devices connected to Android Auto:
{{ integration_entities('mobile_app')
| select('contains','_android_auto') <--- gets only the android auto sensor entity
| select('is_state','on') <--- only if that sensor is 'on'
| map('device_id') <--- Get the device ID so we can later
| list retrieve the bluetooth sensor
}}
This is what I set my automation trigger to monitor:
trigger: template
value_template: '{{ states('sensor.android_auto_connected_devices') | length > 0 }}'
for:
seconds: 30
Then, in my automation, I set up some variables to map the devices to their bluetooth sensors:
variables:
connected_device_bluetooth_sensors: >-
{% set connected_device_sensor_groups = states('sensor.android_auto_connected_devices')
| map('device_entities') -%}
{# flatten the list, because 'sensor_groups' is actually a list of lists #}
{% set var = namespace(flat = []) -%}
{% for sublist in connected_device_sensor_groups -%}
{% set var.flat = var.flat
+ sublist | select('contains', '_bluetooth_connection') | list
-%}
{% endfor -%}
{{ var.connected_device_bluetooth | unique | list }}
vehicle_mentions: >-
{{ connected_device_bluetooth_sensors
| select('contains', 'connected_') <--- Look for the 'connected' attributes
| map('state_attr') <--- Get the value of those attributes
| default([], true) <--- Empty list if they are not present
| select('contains', CAR_MAC) <--- If they contain my car's BT MAC addr.
| list }}
Then finally, a condition to ensure that the Android Auto-connected devices are ALSO connected to the car’s bluetooth
- condition: template
value_template: "{{ vehicle_mentions | length > 0 }}"
I was just hoping for a simpler method like
{{ state_attr('sensor.android_auto', 'car_id') | contains("MY CAR") }}
