Report of unavailable matter devices

Hi Community,

I’m not sure how to start with a requirement I gave me for my home assistant.
I’d like to have a report of all matter devices that are unavailable.
Currently I have a list of unavailable matter entity, but that list can get fairly long fast, as some devices have 10+ entities…
Is there a way for example with auto-entities to show only the devices?

In an ideal world I would like to have a list of tiles from matter devices that are currently unavailable.
That titles should have the name of the device as main text and the room as subtext. If the device is battery powered an additional Icon on the right side of the tile with the current battery level would be nice too :slight_smile:

This is my current code to get the list of all unavilable entities (Not devices)

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
show_empty: false
filter:
  template: |-
    {%- for state in states -%}
      {%-
        if state.entity_id in integration_entities('matter')
        and not has_value(state.entity_id)
        and not state.domain == 'button'
      -%}
        {{-
          {
            'type': 'tile',
            'entity': state.entity_id,
            'name': state.name,
            'hide_state': true,
            'tap_action': {
              'action': 'none'
            },
            'icon_tap_action': {
              'action': 'none'
            }
          }
        -}},
      {%- endif -%}
    {%- endfor -%}
sort:
  method: name

got a little bit further on the road…

But now the real questions are rising on the horizon:

How do I get the devices primary entity to get the icon?
How do I get the devices battery (if there is any) to add a badge_icon of the battery level?

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
show_empty: false
filter:
  template: |-
    {% set device_ids = states
      | selectattr('entity_id', 'in', integration_entities('matter'))
      | selectattr('state', 'eq', 'unavailable')
      | map(attribute='entity_id')
      | map("device_id")
      | unique
    %}
    {%- for device_id in device_ids -%}
        {{-
          {
            'type': 'custom:mushroom-template-card',
            'primary': device_attr(device_id, 'name_by_user'),
            'secondary': area_name(device_id),
            'tap_action': {
              'action': 'none'
            },
            'hold_action': {
              'action': 'none'
            },
            'double_tap_action': {
              'action': 'none'
            }
          }
        -}},
    {%- endfor -%}
sort:
  method: name