List of people at home

Hello!

I need a little help.

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 }}

Thanks for the help!

Try this as the loop for just getting you the names of the people @ home:


{% for state in states.person -%}

  {%- if loop.first %} {% elif loop.last %} & {% else %} & {% endif -%}
  {{ state.name | lower }}
{%- endfor %}.

Alternatively you can also employ a conditional card to only show the people who are home

2 Likes

change

{{ 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…

{{ states.person | selectattr('state','eq','home') | map(attribute='attributes.friendly_name') | list | join(', ') }}
4 Likes

Thank you very much!

Working perfectly :slight_smile: