I would like to write on a card that: They are currently at home: Person 1, Person 2, Person 3
How can I solve this?
I’ve tried it, but I just managed to write out how many people are at home: They are currently at home: 3
{% set person = [
states.person.1,
states.person.2,
states.person.3,
] %}
<h2>They are currently at home: {{ person | selectattr('state','eq','home') | list | count }}
{{ person | selectattr('state','eq','home') | list | count }}
to
{{ person | selectattr('state','eq','home') | map(attribute='attributes.friendly_name') | list | join(', ') }}
the count filter counts the number of people. The map gets the friendly name and the join adds them together with a comma.
EDIT: Actually, you can change this a bit to be easier to write:
{% set person = expand('person.1', 'person.2', 'person.3' %}
{{ person | selectattr('state','eq','home') | map(attribute='attributes.friendly_name') | list | join(', ') }}
and if you make a group of persons…
{% set person = expand('group.persons' %}
or if you just want all the people without specifying a group…