🔹 Auto-entities - Automatically fill cards with entities

Seems to work:

seems to have been some caching issue or so. Didn’t change anything. Works now. Sorry for the confusion. Thanks for investigating.

thank you @Ildar_Gabdullin

Anyone know how to filter out entities/devices not assigned to an area? I know how to filter by devices assigned to an area but am looking for the opposite. Overall, I am trying to only show a list of switches assigned to an area ie if a switch has not been assigned an area it won’t show in the auto entities list.
I know a work around could be to include switch domain and include every area but this just feels like a lot of work when there should be exclude: null

Have two lists? One with all entities and one with those in areas … and remove the items from the later list from the former list.

type: custom:auto-entities
show_empty: false
card:
  type: entities
filter:
  template: >-
    {% set ns = namespace(entity_and_area=[]) -%}
    {%- for entity in states.device_tracker -%}
      {%- 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] -%}
    {%- endfor -%}
    {%- set sorted_list = (ns.entity_and_area) | rejectattr('area','eq',none) | sort(attribute='area') -%}
    {{ sorted_list | map(attribute='entity_id') | list }}

Here we have a list of “device_tracker” entities (except not assigned to any area) sorted by area.




Will post a list of useful posts (just in case):

list an entity’s attributes

passing options into a conventional entity row:
hide a name
show an attribute

how to manage a sorting

mass-rename entities

list of batteries

select entities dependently on their attributes

using AND, OR, NOT

card-mod:
general schema
conditional card_mod
glance + card_mod
– card-mod in a template: one, two, three

button-card in a grid

graphs in a stack:
history-graph
mini-graph-card
mini-graph-card + template

many graphs in one card

multiple-entity-row

dividers between lists

rows separated by dividers

defining a number of found elements

how to list entities in 2 columns

how to define Markdown cards in auto-entities

areas:
sort entities by area
a card with entities filtered by some area
list of “area” cards
show an Area card for one area_name
list of entities except ones not assigned to any area

templated Gauge card

a possible way to easily define templates for cards

how auto-entities work

how to show an alternative card if a filter gives an empty list

4 Likes

@Ildar_Gabdullin thank you, I will give that a go, and thank you for the other links. Interesting reading :grinning:

1 Like

is it somehow possible to output an attribute as the value instead of the state?

type: custom:auto-entities
show_empty: false
card:
  type: entities
  state_color: true
  show_header_toggle: false

Read 2 posts above.

uups, sorry! But is it also possible to use an attribute instead of friendly_name on the left side? Or alternatively, to create a sensor whose friendly_name is created via a template?

Probably possible by using a “template” option based on examples in the thread.

Where could a template be inserted? Under options? I mean:

options:
  name:
    ...

OK, I modified the sensor - it’s possible to template the friendly_name:

friendly_name: "Test {{ states('sensor.klimasensor_1_humidity') | float(default=0) }}"

Hi, I had this code working before and I liked how it looked in the UI:

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  include:
    - entity_id: light.*
      state: 'on'
      options:
        type: custom:mushroom-update-card
        entities:
          - this.entity_id
        tap_action:
          action: call-service
          service: homeassistant.turn_off
          service_data:
            entity_id: this.entity_id

Now I have a template that obtain all the lights and switches that I want to display. But I have lost the ability to display these “lights” with a mushroom card.

type: custom:auto-entities
card:
  type: entities
filter:
  template: >-
    {{ expand('group.Lights_House') | selectattr('state','eq','on') |
    map(attribute='entity_id') | list }}

Any ideas on how to make it look better (maybe like before) using the template in filter?


type: custom:auto-entities
card:
  type: grid
  title: Group
card_param: cards
filter:
  include:
    - group: group.Lights_House
      state: 'on'
      options:
        type: custom:mushroom-entity-card
        primary_info: state
        secondary_info: name
        layout: vertical

Thank you for your answer. That does not work for me. I assume is because of group.Lights_House is a group that contains other groups

In this case use a for loop:

type: custom:auto-entities
card:
  type: grid
  columns: 5
  square: false
  title: Template
card_param: cards
filter:
  template: |-
    {% for x in expand('group.Lights_House') | selectattr('state','eq','on') %}
    {{- {
    'type': 'custom:mushroom-entity-card', 
    'entity': x.entity_id,
    'primary_info': 'state',
    'secondary_info': 'name',
    'vertical': true }
    -}},{%- endfor -%}

Great, they are now visible. But is there any way to keep the tap_action ?

Sure:

type: custom:auto-entities
card:
  type: grid
  columns: 3
  square: false
  title: Template
card_param: cards
filter:
  template: |-
    {% for x in expand('group.Lights_House') | selectattr('state','eq','on') %}
    {{- 
    {
      'type': 'custom:mushroom-entity-card', 
      'entity': x.entity_id,
      'primary_info': 'state',
      'secondary_info': 'name',
      'vertical': true,
      'tap_action': {
        'action': 'call-service',
        'service': 'homeassistant.turn_off',
        'target': { 'entity_id': x.entity_id }
       }
    }
    -}},{%- endfor -%}

It worked great! I don’t know how you can do all this! I understand the script, but man … you are a genius!