thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.2k stars 111 forks source link

Display devices instead of entities #326

Closed mietzen closed 1 year ago

mietzen commented 1 year ago

Hi, I'm trying to list all unavailable devices in a auto-entities list.

This is my current workaround:

package_unavailable_devices.yaml:

template:
  - sensor:
      - name: "Unavailable Devices"
        unique_id: unavailable_devices
        icon: "{{ if(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 it what it looks like:

Untitled

Instead of 'attribute': 'unavailable' I only get a dash, it would also be nice to be able to click on one entry and be redirected to the device.

I know it is possible to list all unavailable entities, but then I get 4-6 entries for every device that is unavailable.

Is it possible to display a list of devices instead of entities with custom:auto-entities without the sensor workaround?

thomasloven commented 1 year ago

Listing devices is not in the scope of auto-entities.