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

Yes I know, but I need to change the sort: section and it hasnā€™t ā€œtempleteā€ option :confused:
So, no options?

You should define a sorted list by using the ā€œtemplateā€ option.
Something like this:

      template: >-
        {{ states.switch |
           selectattr('state','eq', 'off') |
           sort(reverse=true,attribute='name') |
           map(attribute='entity_id') | list }}

Sorry, not quite clear, this is not working :confused:

    filter:
      template: >- 
        {%   if states('input_number.auto_entities_sort_count')|int == 4 %}
          sort(count='4')
        {% elif states('input_number.auto_entities_sort_count')|int == 8 %}
          sort(count='8')
        {% elif states('input_number.auto_entities_sort_count')|int == 10 %}
          sort(count='10')
        {% endif %}

check this post, and see how sort is Not contained in the filter template. It can be done.

probably the only way to template the config option for sort, would be by using custom:config-template-card

you then embrace your working auto-entities card, make a variable for the count, and have that set by the config-template-card.

I fear though that is going to be a very demanding card for the Frontend, as it constantly evaluates both the auto-entities, and the new count optionā€¦

what Ildar is saying is you can use the jinja template to create a list, but then need to do all manipulation inside that template.

you can add a selector to that template and show only 4:

        {{ (states.switch |
           selectattr('state','eq', 'off') |
           sort(reverse=true,attribute='name') |
           map(attribute='entity_id') | list)[:4] }}

ofc, you can then replace the 4 with a templated state of your input_number.auto_entities_sort_count

like:

{% set number = states('input_number.auto_entities_sort_count')|int(default=0) %}        
{{ (states.switch |
     selectattr('state','eq', 'off') |
     sort(reverse=true,attribute='name') |
    map(attribute='entity_id') | list)[:number] }}
1 Like

You may only use jinjia inside templates.
This ā€œsort(count=ā€˜4ā€™)ā€ is not smth supported.
https://jinja.palletsprojects.com/en/2.11.x/templates/#sort

As example:

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_boolean.test_boolean
        name: reverse sort
  - type: custom:auto-entities
    card:
      type: entities
    unique: true
    show_empty: true
    filter:
      template: >-
        {% if is_state('input_boolean.test_boolean','on') -%}
        {%- set SORT_REVERSE = true -%}
        {%- else -%}
        {%- set SORT_REVERSE = false -%}
        {%- endif -%}
        {{
          states.switch |
          selectattr('state','eq', 'off') |
          sort(reverse=SORT_REVERSE,attribute='name') |
          map(attribute='entity_id') | list }}

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

quickly scribbled this together

    - type: custom:auto-entities
      card:
        type: entities
      entities:
        - input_number.auto_entities_count
      filter:
         template: >
           {% set number = states('input_number.auto_entities_count')|int(default=0) %}
           {{ (states.switch |
           selectattr('state','eq', 'off') |
           sort(reverse=true,attribute='name') |
           map(attribute='entity_id') | list)[:number] }}

ofc you can also template the state of the order directly,

    - type: custom:auto-entities
      card:
        type: entities
      entities:
        - input_number.auto_entities_count
        - input_boolean.auto_entities_sort_reverse
        - type: divider
      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] }}

what ever you want really. As long as it is inside the template and follows jinja rules on list manipulation

Generally works, but not entirely accurate :wink:
I donā€™t think it was the best idea and no way to make it goodly.

sad, that easy count: {{ states(ā€˜input_number.auto_entities_sort_countā€™)|int }} canā€™t be used

  - type: custom:auto-entities
    card:
      type: entities
      title: Voltage
      show_header_toggle: false
    filter:
      include:
        - entity_id: 'sensor.0x*_voltage'
          options:
            style: |
              :host {
                --paper-item-icon-color:
                 {% if states(config.entity)|int < 218 %} #4285F4;
                 {% elif states(config.entity)|int < 222 %} #0F9D58;
                 {% elif states(config.entity)|int < 226 %} #F4B400;
                 {% else %} #DB4437;
                 {% endif %} }
      exclude:
        - state: "= 0"
        - state: "unavailable"
        - state: "None"
      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] }}
    show_empty: false
    sort:
      method: state
      reverse: true
      numeric: true

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.