I have an automation that’s triggered when zone.home > 0.
I’d like it to fire a TTS notification that mentions whoever just got home by (friendly) name, but I haven’t been able to find a way to do it.
Does anyone know how I could do this please?
and
Is there a way to trigger an automation when any user enters zone.home, without the automation having to include a list of users that would have to be maintained please?
The zone has an attribute called persons that contains a list of the people in the zone. From that list you can get the person entity and announce the friendly name.

Test 1:
{% set last_home = states.person | selectattr('state', 'equalto', 'home') | sort(attribute='last_changed', reverse=True) | list %}
{% if last_home | length > 0 %}
{{ last_home[0].attributes.friendly_name }} just returned home at {{ last_home[0].last_changed.strftime('%H:%M') }}.
{% else %}
No one has returned home yet.
{% endif %}
Test2:
{% set last_home = states.person | selectattr('state', 'equalto', 'home') | sort(attribute='last_changed', reverse=True) | list %}
{{ last_home[0].attributes.friendly_name if last_home | length > 0 else 'No one yet' }}
2 Likes
Thanks. I’d seen mention of doing it like that, but hadn’t got anything based on it to work.
Just what I needed, thanks