Hi,
I’m trying to list all unavailable devices in a auto-entities
list. This is what I got so far:
package_unavailable_devices.yaml:
template:
- sensor:
- name: "Unavailable Devices"
unique_id: unavailable_devices
icon: "{{ iif(states(this.entity_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}"
unit_of_measurement: entities
state: >
{%- set devices = namespace(entities=[]) -%}
{%- set entities = states | selectattr('state', 'in', ['unavailable', 'none']) | map(attribute='entity_id') | lis>
{%- for entity in entities -%}
{%- set devices.entities = devices.entities + [device_attr(entity, "name_by_user")] -%}
{%- endfor %}
{{ devices.entities | unique | list | length}}
attributes:
devices: >
{%- set devices = namespace(entities=[]) -%}
{%- set entities = states | selectattr('state', 'in', ['unavailable', 'none']) | map(attribute='entity_id') | l>
{%- for entity in entities -%}
{%- if device_attr(entity, "name_by_user") -%}
{%- set devices.entities = devices.entities + [device_attr(entity, "name_by_user")] -%}
{%- else -%}
{%- set devices.entities = devices.entities + [device_attr(entity, "name")] -%}
{%- endif -%}
{%- endfor %}
{{ devices.entities | unique | list }}
Card Configuration:
type: custom:auto-entities
card:
type: entities
title: 'Unavailable Devices: '
filter:
template: |-
{% set SENSOR = 'sensor.unavailable_devices' -%}
{%- for attr in states[SENSOR].attributes['devices'] -%}
{{
{
'type': 'attribute',
'entity': SENSOR,
'attribute': 'unavailable',
'name': attr
}
}},
{%- endfor %}
This works but has a “cosmetic” issue:
Instead of 'attribute': 'unavailable'
I only get a dash.
Is there something I could do about that?