Templating: Show name of entities in a group?

I have this markdown card:

  - type: markdown
    content: |-
      **Group Members:**
      {{ states.group.test_group.attributes['entity_id'] }}

This will show the entities in the group, but not in a very nice way. This is how it is listed:
How can I format the lovelace card to do somthing like:
If not possible, at lest:

The name can be friendly_name or somthing custom I set for each entity in the template.

Try this

 {{ expand('group.test_group')|selectattr('state')|map(attribute='name')|list|join(', ') }}

name will be the friendly_name if the entity has one, otherwise it will fall back to the entity id.


works, thanks :grin:

That’s a clever use of selectattr() to filter for any entities that are currently on (at least I think that was the intention), but is that what the OP wanted?

I also thought it might be some deft Jinja-fu but (after testing it) it doesn’t do that.

Which leads me to ask why is it there? The template produces the same result without it. Perhaps a fragment from some other template that was used to create this one?

Good point - I tested it with one of my groups and didn’t realize that it didn’t even work the way I surmised it did. Since it seems to pass everything, it must either interpret the string as boolean “true”, or simply pass it straight through because it’s not the type it was expecting (as templates sometimes do, but less so in 2021.10).

Copy paste error.

The codeblocks editor Home Assistant uses is extremely janky and has been for some time.

In the template editor on my iPad if I try to delete something from the middle of a line it deletes from the end of the line instead. Copy an replace have unpredictable results.

Even in my main web browser on my desktop sometimes typing comes out backwards in the Lovelace editor. e.g. entity: comes out as :ytitne.

@flemmingss if you have been following along, the template should be:

{{ expand('group.test_group')|map(attribute='name')|list|join(', ') }}
1 Like

I am :slight_smile:

Can also make a list with this:

<li>{{ expand('group.test_group')|map(attribute='name')|list|join('<li>') }}