Show Friendly Name in Lovelace Card

I’ve created a template sensor to list entities in a group with a state of 'on' but in a Lovelace markdown card it shows the entity_id instead of the friendly name.

Can someone please advise what I need to change or add to get the friendly name to show in the card?

Template Sensor

- platform: template
      friendly_name: "List Doors Open"
      value_template: "{{ state_attr('binary_sensor.doors', 'entity_id') | selectattr('is_state', 'on') | list }}"

Markdown Card Code

   content: '{{ states(''sensor.list_doors_open'')}}'
      grid-area: warning```

Markdown Card View
Screenshot 2023-05-09 at 11.53.52

friendly_name: "List Doors Open"
      value_template: "{{ state_attr('binary_sensor.doors', 'entity_id') | selectattr('is_state', 'on') | map('attribute', 'eq', 'name') | list }}"

Thanks Tom, but the output from that is ‘unavailable’Screenshot 2023-05-09 at 13.41.03

*edited to add screenshot

Try | map(attribute='attributes.friendly_name') | list

No, still ‘unavailable’.

Not sure if any of these factors make a difference but the devices are zigbee binary sensors and I created a binary sensor group via ‘Helper’.

Do the binary sensors actually have friendly names?

Check Developer Tools-> States.

Yes, they all have friendly names, for example:

And when I try {{ states('sensor.list_doors_open')}} in Developer Tools > Templates it also returns ‘unavailable’

Bump this one because I’m scratching my head at how to resolve it and I’m desperate to get it sorted to finish off my dashboard

Try this:

value_template: "{{ expand(state_attr('binary_sensor.doors', 'entity_id')) | selectattr('is_state', 'on') | map('attribute', 'eq', 'friendly_name') | list }}"

Thanks Tom, but that again still returns ‘unavailable’


value_template: "{{ expand(state_attr('binary_sensor.doors', 'entity_id')) | selectattr('state', 'eq', 'on')  | map('attribute', 'eq', 'friendly_name') | list }}"

Sorry Tom, but that’s also returning ‘unavailable’.

I’ve even tried creating the group the “old way” in `groups.yaml’ and the suggested codes still show ‘unavailable’. I’ve also cleared the cache and restarted HA each time.

To try and isolate the issue, I have created a new group of different binary sensors, and used the same template sensor code for that group and it still shows ‘unavailable’ in the dashboard and Developer Tools > Templates.

I then created a new dashboard and tried adding both a template card and markdown card but still getting ‘unavailable’.

I’m assuming the issue is one of three things:

  • A bug in the latest HA release (unless it’s only happening to me)
  • An issue with my template sensor code
  • An issue with my code in the dashboard card

If someone could please help me solve this I would be grateful as it’s making me age quickly.

I’ve opened an issue case for this because it is not the coding that’s the issue, I’m guessing.

Issue Case

It’s select('is_state', 'on')


{{ expand('binary_sensor.doors')
  |selectattr('state', 'eq', 'on') |map(attribute='name') |list }}

1 Like

Brilliant, that worked. Thanks so much.