WTH: why can't I easily see which devices/sensors are not working?

Sometimes my Zigbee or WiFi is malfunctioning, batteries are low, USB stick got disconnected or an online service stops working (thank you lufdaten!) Why can’t HA profile ‘healthy’ sensors and determine their normal behaviour (gas usage reports every hour, temperature roughly every 5 minutes, etc.) and notify me on irregularities. Too often it takes me days or even weeks to notice some sensor is not working.

Something like this?

type: 'custom:auto-entities'
card:
  type: entities
  title: Last Seen
  show_header_toggle: false
filter:
  include:
    - name: /linkquality/
      options:
        secondary_info: last-changed
sort:
  method: last_updated
  reverse: true

type: 'custom:auto-entities'
card:
  type: entities
  title: Link Quality
  show_header_toggle: false
filter:
  include:
    - name: /linkquality/
      options:
        secondary_info: last-changed
sort:
  method: state
  numeric: true

type: 'custom:auto-entities'
card:
  type: entities
  title: Battery
  show_header_toggle: false
filter:
  include:
    - entity_id: '*battery'
      options:
        secondary_info: last-changed
      not:
        domain: automation
sort:
  method: state
  numeric: true

And an automation that notifies me:

- id: '1579893997207'
  alias: Zigbee Drop Notification
  description: ''
  trigger:
  - at: '18:00:30'
    platform: time
  - at: '6:58:24'
    platform: time
  condition:
  - condition: template
    value_template: "    {%- macro GetDroppedZigbee() -%}\n    {% for state in states.sensor\
      \ -%}\n      {%- if state.attributes.linkquality %}\n        {%- if \"Ikea\"\
      \ not in state.name and \"linkquality\" in state.name and (state.attributes.linkquality\
      \ < 15 or (as_timestamp(now()) - as_timestamp(state.last_updated) > (12 * 60\
      \ * 60) )) -%}\n         X \n        {%- endif -%}\n      {%- endif -%}\n  \
      \  {%- endfor %}\n    {%- endmacro -%}\n\n    {%- if GetDroppedZigbee()[0] ==\
      \ \"X\" -%}\n    true\n    {%- else -%}\n    false\n    {%- endif -%}"
  action:
  - data:
      message: "Some devices haven't been seen lately or have low lqi... {% for state\
        \ in states.sensor -%}\n  {%- if state.attributes.linkquality %}\n    {%-\
        \ if \"Ikea\" not in state.name and \"linkquality\" in state.name and (state.attributes.linkquality\
        \ < 15 or (as_timestamp(now()) - as_timestamp(state.last_updated) > (12 *\
        \ 60 * 60) )) %}\n      {{ relative_time(state.last_updated) }} ago for {{\
        \ state.name | lower }} ({{state.attributes.linkquality}} lqi)\n    {%- endif\
        \ -%}\n  {%- endif -%}\n{%- endfor %}\n"
    service: notify.mobile_app_phone
9 Likes

Very good! Didn’t know about the last-changed option.

You could also consider hiding the “good” entities and only showing the ones that need attention to clean things up a bit. E.g. for my battery sensors I have it filtering on lower than 5% remaining which cleans up the overview a lot.

- entity_id: '*_battery'
  state: < 5
1 Like

thank you for your example… this will certainly help. Doesn’t cover my frustration completely. Some integrations or sensors are allowed to only report daily, while others (e.g. electricity) are supposed to trigger every 10s. Now I have to visually inspect my sensors (and there are many) and assess if they are working correctly. That is not do-able.

In config -> entities, click on the status column to sort by status and it will highlight all entities that are either unavailable as reported by the integration or unavailable because they are not currently provided by any integration:

1 Like

That’s great! Thanks! However, are you sure the condition in the automation works properly?
I copied paste, by removing the ikea test and it also go through the condition even though the macro does not return anythin…

The condition I typed in:

    {%- macro GetDroppedZigbee() -%}
    {% for state in states.sensor -%}
      {%- if state.attributes.linkquality %}
        {%- if  "linkquality" in state.name and (state.attributes.linkquality < 15 or (as_timestamp(now()) - as_timestamp(state.last_updated) > (12 * 60 * 60) )) -%}
         X 
        {%- endif -%}
      {%- endif -%}
    {%- endfor %}
    {%- endmacro -%}

    {%- if GetDroppedZigbee()[0] == "X" -%}
    true
    {%- else -%}
    false
    {%- endif -%}

Have you tried it in the dev tools and see what the outcome is? Try testing it there
For me it works flawlessly.

@Skye Hey I was doing some reworking on my automations and cards due to changes in zigbee2mqtt and thought will affect your great atomation. Arent they ? and pottentially if @mgi has new setup {%- if “linkquality” in state.name -%}`
This will always return false…
Also I am not that skilled but from now on this shold check if entity has attribute linquality?

The auto-entities syntax of the original answer doesn’t seem to work anymore. This auto-entities filter shows the link quality of all entities which have a linkquality attribute, that is null or above 0:

        filter:
          include:
            - attributes:
                linkquality: null
              options:
                type: attribute
                attribute: linkquality
                secondary_info: last-updated
              sort:
                method: name
            - attributes:
                linkquality: '>= 0'
              options:
                type: attribute
                attribute: linkquality
                suffix: LQI
                secondary_info: last-updated
              sort:
                method: attribute
                attribute: linkquality
                numeric: true

Here is a whole card I use on HAOS to keep track of the system health. It integrates the filter above in a dropdown menu, so that the card is not showing all the entities by default and keeping things tidy:

type: vertical-stack
cards:
  - type: custom:battery-state-card
    title: Batteries
    secondary_info: last_updated
    sort_by_level: asc
    collapse: 3
    filter:
      include:
        - name: attributes.device_class
          value: battery
  - type: entities
    title: Updates
    entities:
      - entity: sensor.hacs
        name: HACS
      - type: custom:auto-entities
        card:
          type: custom:fold-entity-row
          head:
            type: section
            label: Supervisor Add-Ons
        filter:
          include:
            - domain: update
              sort:
                method: name
      - type: custom:auto-entities
        card:
          type: custom:fold-entity-row
          head:
            type: section
            label: Zigbee OTA Devices
        filter:
          include:
            - attributes:
                device_class: update
              sort:
                method: name
  - type: entities
    title: Zigbee Entities
    entities:
      - type: custom:auto-entities
        card:
          type: custom:fold-entity-row
          head:
            type: section
            label: Sort by Link Quality
        filter:
          include:
            - attributes:
                linkquality: null
              options:
                type: attribute
                attribute: linkquality
                secondary_info: last-updated
              sort:
                method: name
            - attributes:
                linkquality: '>= 0'
              options:
                type: attribute
                attribute: linkquality
                suffix: LQI
                secondary_info: last-updated
              sort:
                method: attribute
                attribute: linkquality
                numeric: true
      - type: custom:auto-entities
        card:
          type: custom:fold-entity-row
          head:
            type: section
            label: Sort by Last Seen
        filter:
          include:
            - attributes:
                linkquality: null
              options:
                type: attribute
                attribute: linkquality
                secondary_info: last-updated
            - attributes:
                linkquality: '> 0'
              options:
                type: attribute
                attribute: linkquality
                suffix: LQI
                secondary_info: last-updated
        sort:
          method: last_updated
          reverse: false
  - type: custom:auto-entities
    card:
      type: entities
      title: Unavailable Entities
    filter:
      include:
        - state: unavailable
          sort:
            method: name
    show_empty: false

For this to work you need to install these plugins from HACS:

  • auto-entities
  • fold-entity-row
  • battery-state-card
2 Likes