🔹 Auto-entities - Automatically fill cards with entities

Hi, I like your auto-entities card a lot. Is there a way to get tap_action : toggle working? That would improve usability a lot imho.

So, I don’t think you are understanding auto-entities. Auto-entities is not actually a ‘card’.

Auto-entities is used to select a ‘group’ of entities to build cards. It is the actual cards that need the tap_action. Not auto-entities.

So, yes, auto-entities can build cards that have tap actions.

1 Like

Suggest you to describe your use case with that “tap-action” issue. Probably it is possible by a target card’s settings.

1 Like

I would echo this - please could you share the finalised code. Excellent usage of this card and exactly what I’m trying to achieve.

I have several cards filled with auto-entities. With some toggle did not work. I went through them again because with some it worked. Turns out that on a type: glance card I had to put
options:
tap_action:
action: toggle
In the include section to get it to work. On other cards it is put in the entity: section but since with auto-entities you do not specify entities I did not know how to get it working. Now it works.

List of area cards:

  - type: custom:auto-entities
    card:
      type: grid
      columns: 2
      square: false
    card_param: cards
    filter:
      template: |-
        {% for AREA in areas() -%}
          {{
            {
              'type': 'area',
              'area': AREA
            }
          }},
        {%- endfor %}


other examples

1 Like

I’m seeking some help … I have a fairly complex card. I am using a vertical stack card with a series of conditional cards after a selector card - the selector picks the room, the conditional card then populates all the scenes for that room. The room selection and conditionally picking the auto entity card works great but as soon as I try to use any custom card in place of the build-in ‘entities’ card it seems to fall apart.

Here’s the YAML I’ve got so far, with no chips card:

type: vertical-stack
cards:
  - type: conditional
    conditions:
      - condition: state
        entity: input_select.room_selector
        state: Living Room
    card:
      type: custom:auto-entities
      filter:
        include:
          - domain: scene
            area: Living Room
        exclude: []
      card:
        type: entities

On my phone, it looks something like this

Anybody been able to make a setup like this work with the auto-entities card putting stuff into a mushroom chips card?

Assume you need to show entities associated with some Area.
And this area is selected by “input_select”.
Should be:

  1. Vertical stack: Entities card with input_select + Entities card filled by auto-entities.
  2. Auto-entities with a “template” filter (not “include”, “exclude”) - learn docs & examples.
  3. This template filter takes a state of “input_select” and uses as an area.
1 Like

please have a look what I am not seeing… trying to add a card_mod to a template filter is always a bit tricky, but somehow I cant find the error, and the output in dev template seems ok too…

    filter:
      template: >
        [{% set threshold = states('input_number.power_threshold')|float(0) %}
        {% set ns = namespace(above_threshold=[]) %}
        {% for s in states.sensor
         |rejectattr('entity_id','search','solaredge')
         |rejectattr('entity_id','eq','sensor.alle_schakelaars_samen_actueel')
         |selectattr('entity_id','search','_actueel|_current_power')
         if s.state|float(0) > threshold %}
           {{
              {
                'entity': s.entity_id,
                'options':
                  {'card_mod': '!secret power_color'}
              }
            }},
          {%- endfor %}]

does create the correct list of filtered entities and shows those, but the card_mod option is not applied, meaning the icons aren’t colored as expected.

if I do a single entity like this:

  - entity: sensor.vijverpomp_links_actueel
    card_mod: !secret power_color

it does work properly ( icon is colored following state), and attaches the secret which I saved as

power_color:
  style: |
    :host {
      --paper-item-icon-color:
        {% set state = states(config.entity)|int(-5) %}
        {% if state > 2000 %} purple
        {% elif state > 1000 %} maroon
        {% elif state > 450 %} darkred
        {% elif state > 300 %} firebrick
        {% elif state > 250 %} crimson
        {% elif state > 150 %} darkorange
        {% elif state > 70 %} orange
        {% elif state > 10 %} lightsalmon
        {% elif state > 0 %} gold
        {% else %} var(--no-power-color)
        {% endif %}
    }

not sure what to check next. is it a dom path that changed because of the auto-entities, and should I change the mod itself? (Inspector seems to show the identical path…)

or, is it a syntax problem after all, and should I change the template filter.

the result is a list alright, as seen here:

and the output is like this:

[
  {
    "entity": "sensor.patchboard_zolder_actueel",
    "options": {
      "card_mod": "!secret power_color"
    }
  },
  {
    "entity": "sensor.vijverpomp_links_actueel",
    "options": {
      "card_mod": "!secret power_color"
    }
  }
]

tried it like this too:

        filter:
          include:
            - entity_id: sensor.*_actueel
               options:
                 card_mod: !secret power_color

which also works correctly showing all nicely colored icons.
So, my first bet would be the template filter has a syntax issue…

would appreciate a look, thanks

btw nevermind the namespace, it is a remnant of my other template, and does nothing in this config.

update

some progress… I should not use the option: in the template filter…

I can. are things happen when spelling the mod out verbosely (and not inserting the secret)

      template: >
        [{% set threshold = states('input_number.power_threshold')|float(0) %}
        {% for s in states.sensor
         |rejectattr('entity_id','search','solaredge')
         |rejectattr('entity_id','eq','sensor.alle_schakelaars_samen_actueel')
         |selectattr('entity_id','search','_actueel|_current_power')
         if s.state|float(0) > threshold %}
           {{
              {
                'entity': s.entity_id,
                'card_mod':
                  {'style':
                      ':host {
                        --paper-item-icon-color:
                          {% set state = states(config.entity)|int(-5) %}
                          {% if state > 2000 %} purple
                          {% elif state > 1000 %} maroon
                          {% elif state > 450 %} darkred
                          {% elif state > 300 %} firebrick
                          {% elif state > 250 %} crimson
                          {% elif state > 150 %} darkorange
                          {% elif state > 70 %} orange
                          {% elif state > 10 %} lightsalmon
                          {% elif state > 0 %} gold
                          {% else %} var(--no-power-color)
                          {% endif %}
                      }'
                  }
              }
           }},
          {%- endfor %}]

dont think we an import the !secret inside the template filter here…

So, this has been burning my ass. Because this should be doable.

This can actually be done in a markdown card without using a sensor.

views:
  - title: Test Unavailable
    path: test_unavailable
    subview: false
    badges: []
    cards:
      - type: markdown
        content: >
          |Device

          |-

          {%- set ns = namespace(devices=[]) -%}

          {%- set entities = states | selectattr('state', 'in', ['unavailable', 'none']) | map(attribute='entity_id') | list -%}

          {%- for entity in entities -%}
            {%- set ns.devices = ns.devices + [{"device_id": device_attr(entity, 'id')}] -%}
          {%- endfor -%}

          {%- for device in ns.devices | unique(attribute="device_id") %}
            | {{ device_attr(device.device_id, 'name_by_user') if device_attr(device.device_id, 'name_by_user') else device_attr(device.device_id, 'name') }}
          {%- endfor -%}

But, that shows devices that have any entity that is unavailable. And, that doesn’t really fit the question. My phone shows unavailable because Android Auto has an entity (car_ev_connector_type) that is unavailable since my truck is not an EV.

You can exclude certain devices. But, what if they really go unavailable? You can exclude certain entities though if you want.

This one will show a list of devices and the entities that are not available.

views:
  - title: Test Unavailable
    path: test_unavailable
    subview: false
    badges: []
    cards:
      - type: markdown
        content: >
          |Device|Entity

          |-|-

          {%- set ns = namespace(devices=[]) -%}

          {%- set entities = states | selectattr('state', 'in', ['unavailable', 'none']) | map(attribute='entity_id') | list -%}

          {%- for entity in entities -%}
            {%- set ns.devices = ns.devices + [{"unique_id": device_attr(entity, 'id') ~ entity, "device_id": device_attr(entity, 'id'), "entity_id": entity}] -%}
          {%- endfor -%}

          {%- for device in ns.devices | unique(attribute="unique_id") %}
            {%- set device_name = device_attr(device.device_id, 'name_by_user') if device_attr(device.device_id, 'name_by_user') else device_attr(device.device_id, 'name') -%}
            {%- if not loop.first -%}
              {%- if loop.previtem.device_id == device.device_id -%}
                {%- set device_name = '' -%}
              {%- endif -%}
            {%- endif %}
            | {{ device_name }} | {{ device.entity_id }}
          {%- endfor -%}

If you want something other than a table in a markdown card, you could certainly use auto-entities, build a list of cards in the template filling in the data wanted, and use:

card_param: cards

I’d be very much interested in your solution, but unfortunately both your examples cause the following error for me: “TemplateError: Must provide a device or entity ID” – and when gradually removing code to see when this error disappears, the following lines seem to be the culprit:

…in the first example:

| {{ device_attr(device.device_id, 'name_by_user') if device_attr(device.device_id, 'name_by_user') else device_attr(device.device_id, 'name') }}

…in the second example:

{%- set device_name = device_attr(device.device_id, 'name_by_user') if device_attr(device.device_id, 'name_by_user') else device_attr(device.device_id, 'name') -%}

Do you happen to have any ideas why it’s not working for me? (And, many, many thanks for your attempt to find a solution for a simple alert which items are unavailable (or have been offline for a while).

That is really odd because I pulled it and pasted right from the test dashboard that I was using that was working. No longer in a test dashboard. I have it in my security dashboard.

I just checked it again. Here it is working:

Are the sort methods device and area still supported? I’ve tried both:

type: custom:auto-entities
filter:
  include:
    - entity_id: '*atom*button'
    - entity_id: '*atom*uptime*'
    - entity_id: '*atom*signal'
  exclude: []
sort:
  method: device
show_empty: true
card:
  type: entities

and

sort:
  method: area

and the result comes back as an empty card. If I replace the method with domain or entity_id, the card works nicely.

Are these methods still supported, or do they come with some additional options or restrictions that are missing above?

(Yes, I have areas defined for all of the devices involved.)

issue
You have to use “template” if you need to sort by “area”.

Okay, so it looks like area (and device?) sorting doesn’t work, correct?

That is to say, you have to sort manually in a template, rather than sort->method.

correct, until the issue is fixed

Interestingly it now also works for me – I retried your code once I knew a device was offline. Maybe there’s an issue when not a single entity is unavailable. I’ll keep an eye on it – and also search for a way to wrap this into a conditional card so I can hide it when empty.

So, that is actually odd. If none matched the states of unavailable or none, it never should have gotten into the loop where you got the error.

Examples with AND, OR, NOT

AND:

type: custom:auto-entities
card:
  type: entities
  title: AND
filter:
  include:
    - domain: input_number
      and:
        - state: '> 10'
        - state: '< 20'

And note this description in the Docs about “not necessary”:
изображение


OR:

type: custom:auto-entities
card:
  type: entities
  title: OR
filter:
  include:
    - domain: sensor
      entity_id: '*xiaomi*'
      or:
        - attributes:
            device_class: battery
        - attributes:
            device_class: temperature

изображение


NOT:

type: custom:auto-entities
card:
  type: entities
  title: NOT
filter:
  include:
    - domain: input_number
      not:
        state: '>=0'
      sort:
        count: 5

изображение

A simple way to show an alternative card if a filter gives an empty list:

type: custom:auto-entities
card:
  type: entities
filter:
  template: >-
    {% set lights =
    states.light|selectattr('state','==','on')|map(attribute='entity_id')|list -%}
    {%- if lights|length != 0 -%}
      {%- for LIGHT in lights -%}
        {{
          {
            'entity': LIGHT,
            'secondary_info': 'last-updated'
          }
        }},
      {%- endfor -%}
    {%- else -%}
      {{
        [
          {
            'type': 'custom:hui-element',
            'card_type': 'markdown',
            'content': 'all lights off',
            'card_mod':
            {
              'style': 'ha-card {border: none;}'
            }
          }
        ]
      }}
    {%- endif %}

изображение

изображение

OR - in most cases you may just use a native “else” option:

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: >-
       ....
    else:
      type: markdown
      content: all lights off

some more examples

2 Likes