List attribute instead of entity name in Markdown card

Hi all,

I’m trying to make a list off devices that are on my WiFi. I have a Markdown card that lists the name of the entities:

<table> {% for state in states.device_tracker|selectattr('entity_id', 'match',
'device_tracker.amplifi.*')  |selectattr('state', 'eq', 'home') %} </tr>
{{state.name}} </tr> {% endfor %}

That works but I’d like to have it list an atrribute, in this case the Description attribute, instead of the entity name. So far I’m not succeeding.

Any tips?

Make sure to select for entities that have the attribute you want to return defined, otherwise you will get None-related errors.

<table>
{% for state in states.device_tracker
| selectattr('entity_id', 'match', 'device_tracker.amplifi.*')
| selectattr('attributes.description', 'defined')
| selectattr('state', 'eq', 'home') %}
  <tr>
    <td>{{ state.name }}</td>
    <td>{{ state.attributes.description }}</td>
  </tr>
{% endfor %}
</table>

Thank you for your help but unfortunately I still can’t get it to work. If I use your code it doesn’t give any output. I can get this to work:

<table>
{% for state in states.device_tracker
|selectattr('entity_id', 'match','device_tracker.amplifi.*')  
|selectattr('state', 'eq', 'home') %}
 </tr>{{state.name}} </tr>
 </tr>{{state.attributes}} </tr>
{% endfor %}

I end up then with a list of all attributes.

But if I add | selectattr('attributes.description', 'defined') or </tr> {{state.attributes.description}} </tr> that will break the code.

If the attribute’s ID is actually “Description” with a capital “D”, then you need to use that… If that doesn’t fix the issue, please post an example state object for one of the target entities so we don’t have to keep guessing at the elements and structure.

Be aware also that the Markdown card’s preview doesn’t always render updates properly when editing, so you may need to edit the code then save the card to see the changes.

<table>
{% for state in states.device_tracker
| selectattr('entity_id', 'match', 'device_tracker.amplifi.*')
| selectattr('attributes.Description', 'defined')
| selectattr('state', 'eq', 'home') %}
  <tr>
    <td>{{ state.name }}</td>
    <td>{{ state.attributes.Description }}</td>
  </tr>
{% endfor %}
</table>

Thank you! I got it working now.