🔹 Auto-entities - Automatically fill cards with entities

hi there,
is there any way to get rid of the name of the sensor and only display the value:
So instead of “esp32035_name” below it would be only:

Code:

type: custom:auto-entities
show_empty: false
card:
  type: entities
  title: 'Last seen:'
filter:
  include:
    - domain: sensor
      entity_id: /name/
      options:
        secondary_info: last-changed
sort:
  method: last_updated
  numeric: true
  count: 3
  reverse: true

Hi. Is there a way to count how many entities there are in the result? For example if I set up som filter to warn me about low batteries etc it would be nice if I was able to print “You have xx warnings”

Same way as for a conventional Entities card.

You may calculate count of filtered entities inside a “template” option.

nice answer but it does not help me much - for normal entities I put name:… but here I am not sure how to
thx anway

@homonto
Consider this:

type: vertical-stack
cards:
  - type: entities
    entities:
      - type: section
        label: w/o secondary_info
      - entity: sun.sun
      - entity: sun.sun
        name: replaced
      - entity: sun.sun
        name: ' '
      - type: section
        label: with secondary_info
      - entity: sun.sun
        secondary_info: last-changed
      - entity: sun.sun
        name: replaced
        secondary_info: last-changed
      - entity: sun.sun
        name: ' '
        secondary_info: last-changed
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - entity_id: sun.sun
          options:
            secondary_info: last-changed
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - entity_id: sun.sun
          options:
            name: ' '
            secondary_info: last-changed

As I said - same way as for a conventional Entities card.

1 Like

that is what template-entity-row was made for :wink:

Oh yes.
Same output, different efforts:

Surely in some cases template-entity-row is the simplest solution, it depends.
Not to mention a fact that “last-changed” label is NOT periodically updated for template-entity-row (only when a state changes or a page refreshed) as it is for a conventional entity row (periodically).

tbh I always use the last-changed on states in the config.entity, so they are always correctly updated. you might be right for other situations, I confess I bever watched that. Should be an important aspect in choosing the right card.

See this rather complex composite of card_mod_theme, card_mod and template-entity-row. whish I could be simpler…
luckily, we can just completely throw it inside an anchor and repeat for the another entity::

type: entities
title: Luchtreinigers
card_mod:
 class: class-header-margin
entities:
  - type: custom:template-entity-row
# https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/2182
    entity: fan.luchtreiniger_hall
    <<: &fan
#       color: >
#         {{iif(states[config.entity].state == 'on','red','black')}}
      name: >
        {% if states[config.entity] is not none %}
          {{state_attr(config.entity,'friendly_name').split(' ')[1]}}:
          {% set id = states[config.entity].object_id %}
          Air quality:
          {% if states('sensor.' ~ id ~ '_air_quality') in ['unknown','unavailable'] %}
            {% if states[config.entity].state == 'on' %} Initializing
            {% else %} Off {# Device not ready #}
            {% endif %}
          {% else %} {{states('sensor.' ~ id ~ '_air_quality')}} µg/m³
          {% endif %}
        {% else %} Not yet set
        {% endif %}

      secondary: >
        {% if states[config.entity] is not none %}
          {% set id = states[config.entity].object_id %}
          {% if states[config.entity].state == 'on' %}
            On: {{states[config.entity].attributes.percentage}} -
          {% else %} Off since {{relative_time(states[config.entity].last_changed)}} -
          {% endif %}
        {% else %} Not yet set -
        {% endif %}
        Power: {{states('sensor.' + id + '_device_power')}} W

      card_mod:
        style:
          div#wrapper: |
            state-badge {
              {% if is_state(config.entity,'on') %}
                animation: rotation 2s linear infinite, colorize 5s linear forwards 1;
              {% endif %}
            }
            @keyframes rotation {
              0% {
                transform: rotate(0deg);
              }
              100% {
                transform: rotate(360deg);
              }
            }
            @keyframes colorize {
              0% {
                background: steelblue;
              }
              100% {
                background: aquamarine;
              }
            }
#      state: >
#        {{iif(is_state(config.entity,'on'),'Aan','Uit')}}

      icon: >
        {{is_state(config.entity,'on')|iif('mdi:fan','mdi:fan-off')}}
#      icon: >
#        {{'mdi:record-circle-outline' if is_state(config.entity,'on') else 'mdi:fan-off'}}

      toggle: true

  - type: custom:template-entity-row
    entity: fan.luchtreiniger_woonkamer
    <<: *fan

btw, that animated fan is still off-center…

This template only updates when the state is changed, or when the page is refreshed.

Sorry for an off-topic.

yes, I understood that, np.
btw, not so off topic, as its a very easy mod to use in the options for an auto-entities card. using that myself

Thanks, I thought it was possible with som sort of template. I just didn’t know i could use the filter when i created the template. I will have to look into that since i’m quite new to the coding part of HA (where you can do all the cool stuff)

Kind of:

    type: custom:auto-entities
    card:
      type: entities
    filter:
      template: |-
        {% set DEVICES = states.device_tracker |
                          selectattr("attributes.ip","defined") | list -%}
        {%- set COUNT = DEVICES | count -%}
        {{
            {
              'type': 'section',
              'label': 'Count: ' + COUNT|string
            }
        }},
        {%- for DEVICE in DEVICES  -%}
            {{
              {
                'entity': DEVICE.entity_id,
                'secondary_info': 'last-changed'
              }
            }},
        {%- endfor %}

image

3 Likes

Should show_empty work when using a filter template?

It’s working fine with include filters. But when using a template filte it’s not. Here is some example that doesn’t seem to work:

- type: custom:auto-entities # Offene Fenster und Türen
  show_empty: false
  card:
    type: entities
    title: Offene Fenster/Türen
  filter:
    template: |-
      {% set DEVICES = states.binary_sensor 
        |rejectattr('attributes.device_class', 'undefined')
        |selectattr('attributes.device_class', 'eq', 'door')
        |selectattr('state', 'eq', 'on')
        |list
        %}
        {% if DEVICES|length > 0 %}
          [
          {% for DEVICE in DEVICES  -%}
            {{{
                'entity': DEVICE.entity_id,
                'name': area_name(DEVICE.entity_id),
                'secondary_info': 'last-updated'
            }}},
          {% endfor %}
          ]
        {% endif %}

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

sorted graphs in an apexcharts donut 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