What I am trying to achieve: I occasionally get a new mobile phone. If and when I do, I am trying to avoid having to search/replace or rewrite all my YAML.
What I have tried: I created a list of people and their devices in configuration.yaml, example:
group:
# for each user, defining list of each user' devices so that primary device
# only needs to be set once (hopefully) in dashboards and such
user_devices_ndrs:
name: nrds' devices
entities:
- device_tracker.ndrs_pixel_9_pro_xl
- device_tracker.ndrs_samsung_flip_phone
etc
Then, in a dashboard card config, I have tried referencing the “top” device like so:
type: custom:stack-in-card
card_mod:
style: |
ha-card {
{# Get the first device tracker entity from the 'user_devices_ndrs' group. #}
{% set device_tracker_entity = state_attr('group.user_devices_ndrs', 'entity_id')[0] %}
{% set longitude = state_attr(device_tracker_entity, 'longitude') | float(0) %}
{% set latitude = state_attr(device_tracker_entity, 'latitude') | float(0) %}
This does not seem to work. Is there any best practice for solving this use case (except “have only one phone at a time and call it ‘phone’” or similar?