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

Wrong.
Cannot combine ā€œtemplateā€ with other variants.

Updated: I was wrong

that is not entirely true, although commonly accepted as such:

          filter:
            template: >
              {% set number = states('input_number.auto_entities_count')|int(default=0) %}
              {% set sort = is_state('input_boolean.auto_entities_sort_reverse','on') %}
              {{ (states.switch
                  |selectattr('state','eq', 'off')
                  |sort(reverse=sort,attribute='name')
                  |map(attribute='entity_id')
                  |list)[:number] }}
            include:
              - entity_id: '*firmware_update'
                state: 'off'
                options:
                  type: custom:template-entity-row
                  secondary: >
                    {{state_attr(config.entity,'installed_version')}}
            exclude:
              - attributes:
                  installed_version: '*rc*'
              - attributes:
                  installed_version: '*beta*'
              - attributes:
                  latest_stable_version: ''

works just fine

additional exclude:

            exclude:
              - attributes:
                  friendly_name: 'Amp*'

Yes, thatā€™s clear, but how to make all my includes, excludes, colors in ā€œtemplate:ā€ā€¦

Correct, I was wrong.

Nevermind, can be used together, I was wrong.

1 Like

No problem, I see, but still the question is it possible to filter (sensor.0x*_voltage) in template:

template: >- 
        {% set number = states('input_number.auto_entities_sort_count')|int(default=0) %}        
        {{ (states.sensor |
           selectattr('state','eq', 'off') |
           sort(reverse=true,attribute='name') |
           map(attribute='entity_id') | list)[:number] }}
type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_number.test_number
        name: count
      - entity: input_boolean.test_boolean_10
        name: reject fan_bathroom
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: >-
        {% set NUMBER = states('input_number.test_number')|int(default=0) -%}
        {%- set REJECT_FAN_BATHROOM = states('input_boolean.test_boolean_10')|bool(default=false) -%}
        {%- set SWITCHES = states.switch |
                           selectattr('state','eq','off') -%}
        {%- if REJECT_FAN_BATHROOM -%}
          {%- set SWITCHES = SWITCHES | rejectattr('entity_id','search','fan') -%}
        {%- endif -%}
        {{ (
             SWITCHES |
             sort(reverse=false,attribute='name') |
             map(attribute='entity_id') | list
           )[:NUMBER] }}

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

Can anyone tell me why I cannot template the ā€œtitleā€?

I tested the template and it works:

Because templates are only supported for the ā€œtemplateā€ option.

Hey guys Iā€™m new here, I saw someone using sections in his auto entities card and I canā€™t seem to find the documentation about it. Can anyone please point me to how can I add sections to my auto entities cards?

For instance:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: input_number.test_n*
      sort:
        count: 3
    - type: section
      fake_option: 1
    - entity_id: sun.sun
    - type: section
      fake_option: 2
    - domain: person
      sort:
        count: 2
unique: true

image

type: custom:auto-entities
card:
  type: entities
filter:
  template: |-
    {% for s in states.switch -%}
      {{
        {
          'entity': s.entity_id,
          'secondary_info': 'last-changed'
        }
      }},{%- if not loop.last -%}{{
        {
          'type': 'section'
        }
      }},
      {%- endif -%}
    {%- endfor %}

image

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.