What entities are offline or unavailable? Solved

I want a display of all devices ( primarily for battery powered zigbee devices ) that have gone offline. The entity-filter card sounds like a reasonable approach, but I can’t figure out what state_filter and value to use.

Look on Developer Tools / States and see what state they’re in. Probably a combination of unknown and unavailable.

{{ states.sensor
| selectattr('state','in', ['unknown', 'unavailable'])
| map(attribute='entity_id')
| list }}
1 Like

Nice. This extension allows for multiple domains:

{{ states
| selectattr('domain','in',['binary_sensor','light','sensor','switch'])
| selectattr('state','in', ['unknown', 'unavailable'])
| map(attribute='entity_id')
| list }}
1 Like

mmmm
Looks like the entity-filter card don’t like templating. :frowning:

I will take a look in another cards, hold on.

There is:

type: custom:auto-entities
card:
  type: entities
  title: Offline entities
filter:
  include:
    - state: "unknown"
    - state: "unavailable"
  exclude:
    - domain: person

I have used this card:

1 Like

Markdown card with HA Alerts.

type: markdown
content: |
  {% for e in states|selectattr('domain','in',['binary_sensor','light','sensor','switch'])|selectattr('state','in', ['unknown', 'unavailable'])|map(attribute='name')|list %}
  <ha-alert alert-type="error">{{ e }}</ha-alert>
  {% endfor %}

image

2 Likes
1 Like

Same here, would add this:

  exclude:
    - hidden_by: /user|integration/
    - attributes:
        device_class: battery

Although what bothers me is that it creates items for each device entity. What i would love is something that would show only the Device that is offline, not that device.battery, device.rssi, device.update etc are available, since it is useless clutter.

First, I would like to thank everyone who helped me with this. After reading all of the responses, I realized that I didn’t do a good job of explaining my intent. What I wanted was a tool to help me anticipate when the batteries in zigbee devices would need replacements.
I eventually found the custom auto-entities card that does everything that I wanted. This solution did require that entity names have a uniform structure so that I could filter using ‘*_power’.

> type: custom:auto-entities
> filter:
>   include:
>     - domain: sensor
>       integration: zha
>       entity_id: '*_power'
>       state: <=40
>     - domain: sensor
>       integration: zha
>       entity_id: '*_power'
>       state: unknown
>     - domain: sensor
>       integration: zha
>       entity_id: '*_power'
>       state: unavailable
>   exclude: []
> sort:
>   method: state
> card:
>   type: entities
>   state_color: true
>   title: Low Battery Status

This is how is my card for battery level:

      - type: custom:battery-state-card
        title: Battery state
        sort_by_level: asc
        color_thresholds:
          - value: 15
            color: red
          - value: 25
            color: yellow
          - value: 35
            color: green
        filter:
          include:
            - name: attributes.device_class
              value: battery
          exclude:
            - name: state
              value: 35
              operator: '>'
            - name: state
              value: Unknown
            - name: entity_id
              value: binary_sensor.*
            - name: entity_id
              value: '*phone*'
            - name: entity_id
              value: '*tablet*'
            - name: entity_id
              value: '*laptop*'
            - name: entity_id
              value: '*abisko*'
            - name: entity_id
              value: '*sm_g981b*'
        tap_action:
          action: more-info

Note that I’m including all the batteries, independent of the integration, but then I have excluded a few devices (mobile phones, laptops, etc.).

Hello

Is it possible to apply the same code so I could see when my Qnap NAS was last offline as to opposed to online. Its not kept on around the clock and the entity unavailable that shows up looks like a big eye sore on the dashboard. Still fairly new to HA world so help would be appreciated

- platform: qnap
    host: 192.168.0.70 
    username: uname    
    password: pword
    monitored_conditions:
      - status
      - system_temp
      - cpu_temp
      - cpu_usage
      - memory_free
      - memory_used    

Could you please go to Developer Tools, select tab State and the search for the entity(ies) generated by this and share a screenshot with the attributes visible?
Please hide any private info.

My bad here for not further explaining in the case of qnap the code shown above was added to configuration.yaml file. When I went to developer tools I did not see the following entities, which appear when the Qnap is offline

image