List all ZHA devices that are offline

I was looking for a simple way to show all the devices that were disconnected from the Zigbee network, but I couldn’t find any solution that I liked.

Most of the solutions I found listed the disconnected entities, but not the disconnected devices. Since a device can have multiple entities, the generated listings contained many duplicates.

After many hours of testing, I got a working solution with the following code:

type: custom:auto-entities
card:
  type: entities
unique: false
filter:
  template: |
    {% set data = namespace(numbers=[]) %}
    {%- for da in expand(integration_entities('zha') ) |selectattr( 'state',
    'eq', 'unavailable') | list -%}
      {% set data.numbers = data.numbers + [device_entities(device_attr(da.entity_id, 'id')) | first] %}
    {%- endfor -%}
    [
    {%- for filt in data.numbers | unique -%}
      {{ {"name": device_attr(filt, 'name_by_user'), "secondary": device_attr(filt, 'name'), "state": "", "icon": "mdi:devices", "type": "custom:template-entity-row" } }} 
      ,
    {%- endfor -%}
    ]
else:
  type: markdown
  content: Ninguno

You will need to first install the cards “Auto Entities” and “Template Entity Row”.

This is how it looks:
Screenshot 2023-12-22 at 01-36-28 Resumen – Home Assistant

And the same thing in a dashboard:

I thought it would be a good idea to share the code in case anyone had the same problem. I hope it helps!

4 Likes

That’s brilliant! Thank you very much :slight_smile:
How do I get the entire table with the details of the Zigbee devices?

Hey
I’ve installed this custom card through HACS: GitHub - dmulcahey/zha-network-card: Custom Lovelace card that displays ZHA network and device information

And this is the code that I’m using:

clickable: true
columns:
  - attr: available
    id: available
    modify: >-
      if (x===true){"<span style='color:green;'>✓</span>"}else{"<span
      style='color:red;'>✕</span>"}
    name: ' '
    align: center
  - name: Nombre
    prop: name
  - attr: manufacturer
    name: Fabricante
  - attr: model
    name: Modelo
  - attr: ieee
    name: IEEE
  - name: NWK
    prop: nwk
    align: center
  - attr: lqi
    name: LQI (%)
    align: center
    modify: Math.round((x*100)/255) || ""
  - attr: last_seen
    name: Última vez
    modify: >-
      if (new Date(Date.parse(x)).getDate() == new Date().getDate()) {String(new
      Date(Date.parse(x)).getHours()).padStart(2, "0")+":"+String(new
      Date(Date.parse(x)).getMinutes()).padStart(2, "0") }else{String(new
      Date(Date.parse(x)).getDate()).padStart(2, "0")+"/"+String(new
      Date(Date.parse(x)).getMonth()+1).padStart(2, "0")+" "+String(new
      Date(Date.parse(x)).getHours()).padStart(2, "0")+":"+String(new
      Date(Date.parse(x)).getMinutes()).padStart(2, "0")}
    align: center
  - attr: power_source
    name: A
    modify: if (x=='Mains'){"🔌"}else{"🔋"}
    align: center
  - attr: quirk_class
    name: Quirk
    modify: x.replace(/^(zhaquirks.)/,"");
sort_by: available-
type: custom:zha-network-card
view_layout:
  position: main
2 Likes

Hey thank you very much! I’ll test the card right away ;)’

I use the auto-entities vard for this. Copied the setup from some other post here on the formum and edited it for my need. So I do not take any credit for the code.

type: custom:auto-entities
card:
  type: custom:bar-card
  positions:
    name: inside
    value: inside
    indicator: 'off'
    icon: 'off'
  unit_of_measurement: '%'
  max: 100
  severity:
    - color: '#ff4d00'
      from: 0
      to: 10
    - color: '#ff8100'
      from: 11
      to: 20
    - color: LimeGreen
      from: 21
      to: 100
  height: 30px
  style: "\n#states { padding: 0 } \nbar-card-name,\nbar-card-value {\n  \n  color: #ffffff;\n  }\nbar-card-value\t{\n  font-weight: bold;\n}\nbar-card-indicator {\n transform: scaleY(-1);\n}\n"
  stack: vertical
  direction: right
  decimals: 2
entities: []
sort:
  method: state
  numeric: true
  reverse: false
filter:
  include:
    - state: unavailable
  exclude:
    - state: '> 40'
    - entity_id: sensor.*_*state*
    - entity_id: sensor.*phone*