🔹 Auto-entities - Automatically fill cards with entities

I have started making a new dashboard for my Home Assistant. It will have a view for each area in the house, a summary view and some views for special cases - so much like that produced by Dwain’s Dashboard or Mushroom dashboard, but as I wish it.
Firstly I made a series of summary binary_sensors, one for each area, using the ideas in this thread These sensors have counts of lights, lights_on, lights_off etc for various domains and a list of ids of the entities. So for the area named Annex we have binary_sensor.annex_summary, which looks like this:


I want to use this sensor to generate a grid of tile cards using the list of entities in the attribute lights_id, but I can’t get it right.
Firstly I tried an entities card, like this

type: custom:state-switch
entity: template
template: |-
  {{
    state_attr('binary_sensor.annex_summary', 'lights_count') | int > 0
  }}
states:
  'true':
    type: vertical-stack
    cards:
      - type: markdown
        content: '### Annex lights'
      - type: custom:auto-entities
        show_empty: true
        unique: true
        filter:
          template: '{{ state_attr(''binary_sensor.annex_summary'',''lights_id'') }}'
        card:
          type: entities
        state_color: true
        show_header_toggle: false
        entities: null

which works fine and produces an entities card, like so:


However I want to produce a grid of tile cards (or mushroom cards), but my inability to think and speak yaml and jinja prevents that. I have tried several different possibilities gleaned from the posts of others, but can’t crack it. Any and all help would be greatly appreciated.
The two approaches I have tried are:

- type: custom:auto-entities
show_empty: true
card:
  type: grid
  square: false
  columns: 2
card_param: cards
filter:
  template: |-
    {%- for element in
      expand(state_attr('binary_sensor.annex_summary','lights_id'))|
      map(attribute='name')|list -%}
      {{
        {
          'type': 'tile',
          'entity': [element.entity_id,]
          'name': state_attr(element.entity_id, 'friendly_name'),
          'tap_action': '',
            {'action':'more-info'}
        }
      }},
    {%- endfor -%}
sort:
  method: friendly_name

and this one

- type: custom:auto-entities
  show_empty: true
  unique: true
  card:
    type: grid
    square: false
    columns: 2
  card_param: cards
  filter:
    template: |-
      {% for element in
        state_attr('binary_sensor.annex_summary','lights_id') -%}
        {{
          {
            'type': 'tile',
            'entity': element.entity_id,
            'name': state_attr(element.entity_id, 'friendly_name'),
            'tap_action': '',
              {'action':'more-info'}
          }
        }},
      {%- endfor %}
  sort:
    method: friendly_name

Both result in nothing being shown. Substituting a markdown card that prints the loop counter in place of the tile card definition also produces nothing, so there is something wrong with the formatting of the loop, but I don’t know what.

Were you able to get the simple entity type to work? Anyone else out there that can help me? I tried “- type: simple-entity” but it’s not working for me.

Well, after two days of struggle I have it. But don’t ask me to reproduce it other than by copy & paste. There was nothing wrong with the loop, or the attribute containing the list of entity names. It was to do with presence or absence of dashes in the for loop.

type: custom:state-switch
entity: template
template: |-
  {{
    state_attr('binary_sensor.annex_summary', 'lights_count') | int > 0
  }}
states:
  'true':
    type: vertical-stack
    cards:
      - type: markdown
        content: '### Annex lights'
      - type: markdown
        content: |-
          **Lights_id Members:**
          {{ state_attr('binary_sensor.annex_summary','lights_id') }}
      - type: custom:auto-entities
        show_empty: true
        card:
          type: grid
          square: false
          columns: 2
        card_param: cards
        filter:
          template: |
            {%- for element in
              state_attr('binary_sensor.annex_summary','lights_id') -%}
            {{
               { 
                 'type' : 'tile',
                 'entity': element
               }
            }},
            {%- endfor %}
        sort:
          method: friendly_name
      - type: custom:auto-entities
        show_empty: true
        unique: true
        card:
          type: grid
          columns: 2
          square: false
        card_param: cards
        filter:
          template: |
            {%- for element in
              state_attr('binary_sensor.annex_summary','lights_id') -%}
            {{
               { 
                 'type' : 'tile',
                 'entity': element
               }
            }},
            {%- endfor %}
        sort:
          method: friendly_name

The result is as I wanted.

Oh man, I’ve been trying to figure out how to do this for ages for my google play speakers! They don’t have a group_member attribute so I was trying to figure out another way to determine if they’re part of a group. I was thinking of just specifying the group player but where’s the fun in that lol

I,m starting with YAML, sorry for the rocky question, I´m trying to control the auto-entities filter for my battery warning card with one input_number helper, and can’t find my code error, the card is entirely ignoring the template filter that I set following (for sure badly) the card documentation…

type: custom:auto-entities
card:
  show_header_toggle: false
  title: Battery Warning
  type: entities
  state_color: true
filter:
  template: |
    {% for state in states.sensor %}
     {% if sensor.state <= "{{ states('input_number.battery_level') | int(0) }}" %}
      {{ sensor.entity_id}},
     {% endif %}
    {% endfor %}  
  include:
    - attributes:
        device_class: battery
  exclude:
    - name: /[Ll]ow/
    - name: /[Ss]tate/
sort:
  method: state
  numeric: true

Cannot use templates in templates.
Besides, states are strings & need to be converted to numbers.
Try

{% if sensor.state| int(0) <= states('input_number.battery_level') | int(0) %}

And you will have issues anyway since your template is multiline yaml and you are using “{%%}” instead of “{%–%}” in proper places.
And you need to generate a list - but you will get a string of ids separated by “,”.
Suggest to test the whole template in “Dev tools → templates”.

Big shoutout for your awesome plugin! It’s been a game-changer for my Home Assistant setup. Quick question - any tips on setting up a card to filter and display attribute values instead of just entity states? Thanks in advance!

Read the documentation, for the auto-entities-card ( Even the examples ) “Include”, and what the included cards/entities shows, is depended upon the “card-type” and maybe you need card-mod. , template-entity-row, or mushroom-template is flexible as card-option for the included entities

I have added a bit to my auto-entities card that shows the electricity consumption of a smart plug, so it’ll show up if power is going through the smart plug. The default tap action for this is just showing more info, but when it shows up in the card I want to be able to tap it and have it power off the smart plug. So I added a tap_action to call service switch.turn_off and set the entity_id to the plug. However now whenever this plug is getting power the item shows up twice on the card, tapping the top one gets me more info and tapping the bottom one turns off the plug. Why is it showing up twice? I can’t tell what I’ve done wrong.

square: false
type: grid
cards:
  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
    entities:
      - sensor.kid_room_plug_electric_consumption_a
    filter:
      include:
        - entity_id: sensor.kid_room_plug_electric_consumption_a
          state: '> 0.01'
          option:
            tap_action:
              action: call-service
              service: switch.turn_off
              service_data:
              entity_id: switch.kid_room_plug
      exclude:
        - state: < 0.02
columns: 1
title: Active Lights

image

The one that always shows, is the first , as you specific put it under the “root” entities
24.03.2024_20.09.39_REC

The second, is the one which shows up when “state > 0.01”

24.03.2024_20.09.57_REC

Meaning every entities you specify in first will always be there
The ones you specify under filter_include, turns up upon the specified “filter / requirements”

PS: Your exclude will/should “remove” the second entity, when the state is less than 0.02 which is kind of “conflicting” as your include is state > 0.01 ( which is less than 0.02 )

If You only want it to show up when using power, remove the exclude
If you want “more infor” on the card that shows up, add " hold_action / action: more_info

Thank you very much! This did get it to work.

And I agree the logic of it all seemed really wonky, but clearly it’s because I was doing one thing wrong that I didn’t realize, then to fix it did something else slightly wrong which seemed to make it work.

But with your tips I got all 25 of my entries into one statement now and I can go back and fix my overlapping logic.

1 Like

Hello all! I am having a strange problem with my auto-entities cards not populating upon initially opening a view on my dashboard…For example my “Lights” view is set up to show a mushroom card of all lights currently on in the house. When I first open the app and go to this view the screen will be blank. However, if I go to another view (say a bedroom) and then back to the Lights view the cards will populate like normal. This is happening with any auto entities cards I use. Here is an example of my Lights view code:

title: Lights
icon: mdi:lightbulb
path: lights
type: custom:vertical-layout
subview: false
cards:
  - type: custom:mushroom-title-card
    title: Lights On

# Lights On #
  - type: grid
    square: false
    columns: 1
    cards:
      - type: custom:auto-entities
        card:
          type: grid
          square: false
          columns: 2
        card_param: cards
        filter:
          include:
            - domain: light
              state: 'on'
              options:
                type: custom:decluttering-card
                template: light_card_horizontal
                variables: 
                  - entity: this.entity_id
        sort:
          method: area

Thanks for any tips you can provide!

Hey, thank you for the nice card. Is it possible to define a state color for my humidity sensors? But it doesn’t work with this code

card:
  type: entities  
  card_mod:
    style: |
      :host {
        color:
          {% if states(config.entity) | float <= 55 %} 
            default
          {% elif states(config.entity) | float >= 65 %}
            red
          {% endif %}
          ;
      }
  cards:
    type: entities
filter:
  include:
    - entity_id: '*humidity'
  exclude: []
sort:
  method: state
  numeric: true
  reverse: true

You should ask such question Or Search for same in the Big Card-Mod Thread !
Beside show your whole code, because this is definitely not the right way to do it ( regardless of card-mod, which btw should be moved below in the include

Before playing with auto-entities , try to reproduce same with a stock entity’s card.
And there is no such a value - “default”.

I did, no problems there

Here in your example the cardmod code is on the entity row level.
In your auto-entities card you placed cardmod code on a card level.
To style all rows in Entities card you may place cardmod on a card level - it will affect all rows. But you cannot use config.entity variable on this level.
And repeat, there is no such value as “default”. It causes an error in Code inspector. You better revise the whole syntax - do not use

color: {% if … %} default {% else } red {% endif %};

Use

{% if … %} color: red; {% endif %}

To place cardmod on a row - use “options” option of auto-entities.

can you give me an example of “options” please?

Please ?, it would be polite enough if you read the Github Documentation for the Card you are playing with, then you will get a better chance of getting it all in right place !

Wow just discovered this card. Great card!
I have just 1 question. I got it all working nicely. only in my previous setup i used card mod on the cards to make the borders and so on invisible:
card_mod:
style: |
ha-card
{background: transparent;
border-style: none;
I cannot seem to place this anywhere in my yaml to get it to work.
Where would i place this, and can it even work?

type: horizontal-stack
cards:
  - type: custom:auto-entities
    card:
      type: grid
      columns: 4
    card_param: cards
    filter:
      include:
        - entity_id: sensor.mijnafvalwijzer_gft
          options:
            type: picture-entity
            show_name: false
            image: /local/afbeeldingen/GFT1.png
        - entity_id: sensor.mijnafvalwijzer_papier
          options:
            type: picture-entity
            show_name: false
            image: /local/afbeeldingen/PAPIER1.png
        - entity_id: sensor.mijnafvalwijzer_pmd
          options:
            type: picture-entity
            show_name: false
            image: /local/afbeeldingen/PLASTIC1.png
        - entity_id: sensor.mijnafvalwijzer_restafval
          options:
            type: picture-entity
            show_name: false
            image: /local/afbeeldingen/REST1.png
      exclude: []
    sort:
      method: state
      numeric: true

EDIT: i see that i can give the full card itself a card mod. but the entities will still show borders, i hope i will be able to remove these borders