šŸ”¹ Auto-entities - Automatically fill cards with entities

I would like to use this card with template with the custom button-card. but really don’t know how to do it (i saw several examples about it in this thread, but without success).
Can somebody helps me?

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: |-
    {{ states.light | selectattr('state', 'eq', 'on') |
        map(attribute='entity_id') | list 
    }}
else:
  type: markdown
  content: all lights off

this is the basic format of doing something like that, you need to set the card_param

    - type: custom:auto-entities
      card:
        type: grid
        title: Threshold buttons battery template
        columns: 4
      card_param: cards
      filter:
        template: >-
          [{% set threshold = states('input_number.battery_alert_level')|float(0) -%} {%-
          for s in states.sensor|selectattr('entity_id','search','battery_level')
             if s.state|float(0) > threshold -%}
            {{
              {
                'type': 'custom:button-card',
                'entity': s.entity_id
              }
            }},
          {%- endfor %}]
      sort:
        method: state
        numeric: true

bottom line: you need to add the card_type settings inside the template

of course, always check the documentation Template filters Ā· thomasloven/lovelace-auto-entities Wiki Ā· GitHub which has a nice example too

1 Like

I used the same code, but recently it stopped working, the background color and font color do not change, is it the same for you?

It’s still working fine for me.

Is there a way to use auto-entities with the new badges? I doubt it but just asking in case anyone found out a way.

—-No way ——

1 Like

I would like to have a list of unavailable entities with a heading. Then hide the whole card, including heading, when empty. I can’t seem to get it quite right.
This shows and hides the heading correctly (tested with filters I know are empty), but for some reason no entities appear when there should be results:

type: custom:auto-entities
card:
  type: vertical-stack
  cards:
    - type: heading
      heading: test
      icon: mdi:fridge
      heading_style: title
filter:
  include:
    - attributes:
        device_class: battery
      state: unavailable
      options:
        type: tile
card_param: cards
show_empty: false

This shows the entities and the heading correctly, but when empty still shows the heading:

type: custom:auto-entities
card:
  type: vertical-stack
filter:
  include:
    - type: heading
      heading: test
      icon: mdi:fridge
      heading_style: title
    - attributes:
        device_class: battery
      state: unavailable
      options:
        type: tile
card_param: cards
show_empty: false

Anyone have any ideas?

The code is wrong, you cannot merge 2 lists:

  • a list of cards containing only the ā€œHeading cardā€;
  • a list of ā€œTileā€ cards.

If you need to create a list of cards containing a FIXED card + DYNAMIC cards - you need to add that fixed card inside the ā€œfilterā€ like here:

type: custom:auto-entities
card:
  type: vertical-stack
filter:
  include:
    - domain: sun
      options:
        type: heading
        heading: test
        icon: mdi:fridge
        heading_style: title
    - attributes:
        device_class: battery
      state: unavailable
      options:
        type: tile
card_param: cards
show_empty: false

image

Thanks for the speedy reply.
I still have the heading when the filter is empty. Is there anyway to hide the heading card when my filter returns no results?

What do I need to add to make the card show entities from the group that ā€˜last changed’ within the last 3 minutes? … and show the last change time?

type: custom:auto-entities
card:
  type: entities
  title: All Indoor Motion Sensors
filter:
  template: >
    {{ expand('binary_sensor.motion_all_inside')| map(attribute='entity_id')|
    list }}

thx!

For this you will have to use a ā€œtemplateā€ option and compose a list of cards MANUALLY dependently on a presence of required entities.

1 Like

Might be helpful

I mostly follow, I think… Using your example I changed Entity to ā€˜binary_sensor.motion_all_inside’ and adding a line to pull in ā€˜state.last_changed’ attribute.

but it doesnt work… is this pulling all entities out of the Group? (like Expand does?)

When I put in the code in the card it says it saves but it doesnt - its empty. Asks me for a new selection when I edit it again.

I tried your exact template, just changed the Entity to the group entity I’m using…

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: >-
    {% set ns = namespace(entity_and_area=[]) -%}
    {%- for entity in binary_sensor.motion_all_inside -%}
      {%- set entity_id = entity.entity_id -%}
      {%- set area = area_name(entity.entity_id) -%}
      {%- set entity_and_area = ({'entity_id':entity_id,'area':area}) -%}
      {%- set ns.entity_and_area = ns.entity_and_area + [entity_and_area] -%}
      {%- set last_changed = state.last_changed(entity.entity_id) -%}
    {%- endfor -%}
    {%- set sorted_list = (ns.entity_and_area) | rejectattr('area','eq',none) | sort(attribute='area') -%}
    {{ sorted_list | map(attribute='entity_id') | list }}

Is it possible to hide the auto-entities card when there are no visible entities (they are excluded)?

1 Like

show_empty:

Default is true.

2 Likes

Has anybody got some examples to get me on my way with filling a auto-entities with data from a ToDo List (To-do list - Home Assistant)

I have no experience in using the template function with a action call to import the data into the auto entities. Is it even possible?

I’ve just spent some time creating a list of the firmware versions of all my Shelly devices. So I thought it was worth sharing.

The key thing is the line 9ff (ā€œoptionsā€).
See šŸ”¹ Auto-entities - Automatically fill cards with entities - #164 by thomasloven

type: custom:auto-entities
card:
  title: Shelly Firmware Versions
  type: entities
filter:
  include:
    - integration: shelly
      entity_id: "*firmware*"
      options:
        type: attribute
        attribute: installed_version
  exclude:
    - entity_id: "*beta*"
sort:
  method: attribute
  attribute: installed_version
1 Like

I have my list displaying the correct entity ids as the heading using this.entity_id but am trying to figure out how to instead display the device name (in lieu of the entity id) in the following code. Any ideas?

      - type: custom:auto-entities
        card:
          type: grid
          columns: 1
          square: false
        card_param: cards
        filter:
          include:
            - area: Attic
              entity_id: sensor.*temperature_measurement*
              options:
                type: heading
                heading_style: subtitle
                heading: this.entity_id   

You may get a device name from some entity_id only by using jinja.

How to make this card collapsible?

I’d like to have the collapse/expand arrow in the Title section…