Rejectattr in card template not working

I’m using the below template in a markdown card to display devices reporting as unavailable but | rejectattr('name', 'eq', 'HACS') is not working correctly…i.e. “HACS” still appears in the list of devices.

The rest of the template works as expected but what am I doing wrong with the rejectattr?

type: markdown
title: Devices Offline
content: |-
  {% set device_ids = states
    | selectattr('state', 'in', ['unavailable'])
    | rejectattr('name', 'eq', 'HACS')
    | map(attribute='entity_id')
    | map("device_id")
    | map("string")
    | unique
    | select("ne", "None")
    | list
  %}
  {% for device_id in device_ids %}
    {{ device_attr(device_id, "name_by_user") or device_attr(device_id, "name")}}
  {%- endfor %}

You’re outputting the device_attr name_by_user or device_attr name, which is not the same as the entity name. You’re filtering out the entity name.

1 Like

If you don’t understand what I said… this will do what you want.

  {% set device_ids = states
    | selectattr('state', 'in', ['unavailable'])
    | map(attribute='entity_id')
    | map("device_id")
    | reject('none')
    | reject('is_device_attr', 'name', 'HACS')
    | unique
    | list
  %}

edit: left out unique, added back

1 Like

I understand, thanks Petro.

I did try reject earlier but didn’t change the rest of it.

Thanks for your help.