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

Ok, I have a soultion now:

Description

Shows a list of unavailable Matter devices.
This is most likely due to connection issues or an empty battery.
Shows battery powered devices with an explicit badge icon.

Required customizations

  • Primary Device Type Dictionary

As it seems not possible to get the “primary” entity of a device in home assistant a dictionary of devices has to be maintained in order for the report to show correct icons.
An example with devices I own is already added in the UI code.
As you can see on Eve Systems 77 a device could have multiple device classes based on what is configured on the device.

set manufacturerDeviceClasses =
 {
    'Eve Systems': {
      '77': ['door', 'window'],
      '79': ['temperature'],
      '80': ['outlet'],
      '87': ['temperature'],
      '89': ['motion']
    },
    'Nanoleaf': {
      '67': ['light'],
      '68': ['light'],
      '71': ['light']
    },
    'Sunricher': {
      '257': ['light']
    }
  }

Code 1: Dictionary of device model IDs primary device types per manufacturer.

  • Icon per device type

As it seems not possible to get an entities current icon in home assistant a dictionary of deviceClasses with the desired icon has to be maintained in order for the report to show correct icons.
An example with device types I own is already added in the UI code.

set icon = {
  'temperature': 'mdi:thermostat',
  'motion': 'mdi:motion-sensor',
  'door': 'mdi:door',
  'window': 'mdi:window-closed',
  'light': 'mdi:lightbulb',
  'outlet': 'mdi:power-socket-de'
}

Code 2: Dictionary of device types designated icon.

Requirements

  • HACS
    Open your Home Assistant instance and show the dashboard of an add-on.
  • Auto Entities (For creating a list of entities by code)
    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.
  • Mushroom (For populating a tile for each matter device)
    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.
  • Easy Time (For showing a meaningful value in last updated)
    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.
  • Custom Brand Icons (For having a matter icon)
    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.
  • Input Helper (For selecting if additional information is shown)
    Open your Home Assistant instance and start setting up a new integration.
    Name: show_matter_debug_information

UI Code

type: grid
cards:
  - type: heading
    heading: Matter Devices
    heading_style: subtitle
    icon: phu:matter
  - type: tile
    entity: input_boolean.show_matter_debug_information
    features_position: bottom
    vertical: false
    grid_options:
      columns: full
    tap_action:
      action: toggle
    icon_tap_action:
      action: toggle
    hide_state: true
  - type: custom:auto-entities
    card:
      type: vertical-stack
    card_param: cards
    show_empty: false
    filter:
      template: |-
        {%- from 'easy_time.jinja' import big_relative_time -%}
        {#-
          {
            'Eve Systems': {
              '77': 'Eve Door 20EBN9901'
              '79': 'Eve Thermo 20EBP1701'
              '80': 'Eve Energy 20EBO8301'
              '87': 'Eve Weather 20EBS9901'
              '89': 'Eve Motion 20EBY9901'
            },
            Nanoleaf: {
              '67': 'Essentials A19/A60'
              '68': 'Essentials Lightstrip'
              '71': 'Essentials Holiday String Lights'
            },
            Sunricher: {
              '257': 'MT-RGBCCT'
            }
          }
        -#}
        {%-
          set manufacturerDeviceClasses =
           {
              'Eve Systems': {
                '77': ['door', 'window'],
                '79': ['temperature'],
                '80': ['outlet'],
                '87': ['temperature'],
                '89': ['motion']
              },
              'Nanoleaf': {
                '67': ['light'],
                '68': ['light'],
                '71': ['light']
              },
              'Sunricher': {
                '257': ['light']
              }
            }
        -%}
        {%-
          set icon = {
            'temperature': 'mdi:thermostat',
            'motion': 'mdi:motion-sensor',
            'door': 'mdi:door',
            'window': 'mdi:window-closed',
            'light': 'mdi:lightbulb',
            'outlet': 'mdi:power-socket-de'
          }
        -%}
        {%-
          set device_ids = states
          | selectattr('entity_id', 'in', integration_entities('matter'))
          | selectattr('attributes.device_class', 'ne', 'firmware')
          | selectattr('state', 'eq', 'unavailable')
          | map(attribute='entity_id')
          | map('device_id')
          | unique
        -%}
        {%- for device_id in device_ids -%}
          {%- set deviceEntities = expand(device_entities(device_id)) -%}
          {%- set deviceClasses = manufacturerDeviceClasses.get(device_attr(device_id, 'manufacturer'), {'default': ''}).get(device_attr(device_id, 'model_id'), ['']) -%}
          {%-
            set batteryEntity = deviceEntities
            | selectattr('attributes.device_class', 'eq', 'battery')
            | map(attribute='entity_id')
            | first
          -%}
          {%-
            set primaryEntity = deviceEntities
            | selectattr('attributes.device_class', 'in', deviceClasses)
            | map(attribute='entity_id')
            | first
            | default('zone.home')
          -%}
          {%- if 'temperature' in deviceClasses -%}
            {%-
              set primaryEntity = deviceEntities
              | selectattr('attributes.device_class', 'in', deviceClasses)
              | selectattr('attributes.state_class', 'in', 'measurement')
              | map(attribute='entity_id')
              | first
              | default('zone.home')
            -%}
          {%- endif -%}
          {%- if 'light' in deviceClasses -%}
            {%-
              set primaryEntity = deviceEntities
              | selectattr('domain', 'in', deviceClasses)
              | map(attribute='entity_id')
              | first
              | default('zone.home')
            -%}
            {%- set primaryDeviceClass = 'light' | string -%}
          {%- else -%}
            {%- set primaryDeviceClass = state_attr(primaryEntity, 'device_class') | string -%}
          {%- endif -%}
          {%- set details = '' -%}
          {%- set lastChanged = big_relative_time(states[primaryEntity]['last_updated'], language='en') | trim -%}
          {%- set badgeIcon = 'mdi:alert' -%}
          {%- set badgeColor = 'yellow' -%}
          {%- if batteryEntity is defined -%}
            {%- set badgeIcon = 'mdi:battery-alert' -%}
            {%- set badgeColor = 'red' -%}
          {%- endif -%}
          {%- if is_state('input_boolean.show_matter_debug_information', 'on') -%}
            {%-
              set details = '\nHersteller: ' + device_attr(device_id, 'manufacturer')
                + '\nModel-ID: ' + device_attr(device_id, 'model_id')
                + '\nDevice Class: ' + primaryDeviceClass
                + '\nPrimary Sensor: ' + primaryEntity
            -%}
          {%- endif %}
          {{-
            {
              'type': 'custom:mushroom-template-card',
              'primary':  device_attr(device_id, 'name_by_user'),
              'secondary': 'Room: ' + area_name(device_id)
                           + '\nLast Update: ' + lastChanged
                           + details,
              'entity':  primaryEntity,    
              'icon': icon.get(primaryDeviceClass, 'mdi:alert'),
              'badge_icon': badgeIcon,
              'badge_color': badgeColor,
              'multiline_secondary': true,
              'tap_action': {
                'action': 'none'
              },
              'hold_action': {
                'action': 'none'
              },
              'double_tap_action': {
                'action': 'none'
              }
            }
          -}},
        {%- endfor -%}
    sort:
      method: name
visibility:
  - condition: state
    entity: binary_sensor.matter_unavailable_warning_exists
    state: "on"

Code 3: Code of the unavailable matter device report as grid.

What it looks like (German Version)


Image 1: Report without additional information.


Image 2: Report with additional information.