🔹 Auto-entities - Automatically fill cards with entities

Here 3 cards:

  • auto-entities
  • entity card
  • entities card
    The last 2 are not displayed too.
  - title: zzzzzzzzz
    path: zzzzzzzzz
    badges: []
    cards:
      - type: 'custom:auto-entities'
        card:
          type: entities
          title: auto-entities
        entities:
          - entity: sun.sun
            secondary_info: last-changed
          - type: section
        filter:
          include:
            - domain: device_tracker
              options:
                secondary_info: last-changed
        unique: true
        sort:
          method: name
          reverse: false
          ignore_case: true
      - type: entity
        entity: sun.sun
      - type: entities
        entities:
          - sun.sun
          - sun.sun

This should be fixed in 1.8.3

1 Like

Thomas, thank you! Now it works, I do not see the problem.

fwiw, 🔹 Auto-entities - Automatically fill cards with entities is still happening.

Fwiw @Mariusthvdb this has been happening as long as I can remember with conditional cards in vertical stacks too.

conditional cards do tend to take spaces, even as separate cards…

my issue above however is new since this week, and I believe it to coincide with the many updates of auto-entities. I didnt notice it after updating Ha itself to either of the 2021.3 versions (but might be wrong there, just didnt notice it)

Nothing else in that card config changed. there’s an older post of mine here too show the gapless way it was before:

This problem still exist since 1.8.2 and did not resolve with 1.8.3

Can’t reproduce with 1.8.3. What does your browser console say?

Your issue sounds like what my issue was. For me 1.8.3 has fixed it. Make sure you clear caches and reload page a few times. Sometimes it can get stuck to older version in the browser, even after multiple reloads. Closing other browsers can help. Or uninstall card, delete from resources, reboot HA, install again and add as resource, restart HA again and then reload browser.

Make sure it says this in your browser console, keep trying till it does and then test it.
msedge_hYnfiwXbEi

Same was for me.
Only after clearing the browser’s cache the disappeared content displayed.

Indeed:

12:38:58.063 AUTO-ENTITIES 1.8.3 IS INSTALLED auto-entities.js:194:5516

Unfortunately no luck!

Deleted all cards using auto entities. Removed and reinstalled auto-entities. After start-up, following message was recorded: 12:38:58.063 AUTO-ENTITIES 1.8.3 IS INSTALLED auto-entities.js:194:5516. No errors found. Using auto-entities again without embedded custom:fold-entity-row, functioned properly. Including custom:fold-entity-row back again made lovelace card disappear and resulted in error message: 13:17:40.477 TypeError: r is undefined auto-entities.js:1:27664.
Using the auto-entities.js hyperlink as shown in console delivered the following highlighted pointer:
function t(t,e,i,n){var s,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if(“object”==typeof Reflect&&“function”==typeof …etc

Thank you. Try 1.8.4

Bingo! :wink: Thank you so much!

Need some help.
For this I gonna make a simple case.

There is a list of batteries.
The card contains:

But the batteries must be sorted by “charge level”.
This is an easy task if using “filter / include / …” method.
But here I gonna use a “filter / template” method:

type: 'custom:auto-entities'
card:
  type: entities
  title: Batteries
entities:
  - type: section
    label: Some title
unique: entity
show_empty: true
filter:
  template: |
    {% for state in states.sensor -%}
      {%- if state.entity_id | regex_match('sensor.battery_',ignorecase=False) -%}
        {{
          { 'entity': state.entity_id,
            'secondary_info': 'last-changed'
          } }},
      {%- endif -%} 
    {%- endfor %}
sort:
  method: state
  reverse: false
  ignore_case: false
  attribute: null
  first: 0
  count: 1000
  numeric: true

Now the question is - how to sort this list?
The code provided above gives this picture:


Note that the “section” row is sorted with other “battery” rows - and it comes to the bottom.
So how can I sort only “templated” rows?

Of course, there is a workaround "reverse: true" - but this is not a solution.

I am not sure what has happened. But, today my sensors are sorting in reverse order on my browser and the correct/normal order on my tablet. Using 1.8.4. Any ideas?

https://jinja.palletsprojects.com/en/2.11.x/templates/#sort

Thank you for the guidance!

Made this:

  template: |
    {% for state in states.sensor|sort(reverse=false,attribute="state") -%}
      {%- if state.entity_id | regex_match('sensor.battery_',ignorecase=False) -%}
        {{
          { 'entity': state.entity_id,
            'secondary_info': 'last-changed'
          } }},
      {%- endif -%} 
    {%- endfor %}

But:
Sort is made for “strings”, so the result is “100%, 14%, 20%, 90%”.
Is it possible to sort it is numbers?

P.S.
A bit simpler way (w/o "secondary_info") - filter by “device_class” (may not be 100% useful in some particular setup) - with "sort", and it does not sort properly too 'cause it sorts strings instead of numbers:

      template: |
        {{ states.sensor
           | selectattr('attributes.device_class','eq','battery')
           | sort(reverse=false,attribute='state')
           | map(attribute='entity_id')
           | list }}

of course ymmv, but, depending on the states and auto-entities cards you have, continuous evaluating of states in the states machine might be very costly. especially since these are done in the back-end and not in the browser?

suggestion: auto create a group at startup with the same template and have the auto-entities card use the group for filter?

automation:
  - alias: Create battery group
    trigger:
      platform: homeassistant
      event: start
    action:
      service: group.set
      data:
        object_id: battery_sensors
        entities: >-
          {%- for s in states.sensor
            if ('battery_level' in s.entity_id or
                'motion_sensor_battery' in s.entity_id)%}
            {{s.entity_id}}{% if not loop.last %}, {% endif %}
          {%- endfor %}
1 Like