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

Suppose you have a card which accepts a list of objects:

type: some-card
some_objects:
  - entity: sensor.XXXXXXX
    ....
  - entity: sensor.XXXXXXX
    ....

Examples - Entities card, Glance-card, history-graph, custom:mini-graph-card, custom:apexcharts-card, ā€¦
If you want to fill the some_objects list by auto-entities:

type: custom:auto-entities
card:
  type: some-card   ### your card
card_param: some_objects   ## by default = "entities"
filter:
  include:
    - ...
      options:
        .... options for a particular entity

As for your case - check if the custom:simple-thermostat accepts a list of objects.

If not - then your way is using that card inside a STACK:

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  include:
    - ...
      options:
        type: some-card   ### your card
        .... options for a particular card
1 Like

I noticed that this card currently includes entities that are hidden using the new 2022.4 functionality. Is there an easy filter to exclude those? As the card is intended for the UI I feel like these should not be included by default.

As far as I know, there is no ā€œhiddenā€ attribute among the state objects.
And we cannot use the ā€œhiddenā€ attribute inside a ā€œtemplateā€ option, for instance.

I hid this entity:

There is a ā€œhidden_byā€ attribute in core.entity_registry:
image

But I cannot check if it is hidden:

From my point of view, currently this ā€œhidden thingā€ works only for auto-generated dashboards (is anyone using them???)

I have one autogenerated dashbord to easily get at entities I did not care to include in my ā€œnormalā€ dashboards, which of course I maintain myself. But this card is the perfect balance between control of the dashboard and not having to maintain a lot of entity lists by hand. That is why I hope to find a way to hide unwanted entities.

For instance, when using the Switch as X feature, the original entities should not show up as well. The same goes for a lot of other template entities I use to enhance the original ones. I use template covers that block normal operation when it isnā€™t safe (wind, open window blocking a rollerblind). I hide the original unprotected ones now. It would be nice if I can take advantage of that with the auto-entities card.

I could list them as excludes, but that kind of defeats the purpose, as Iā€™d then be listing the other half.

1 Like

As I said, this ā€œhiding thingā€ is not available in ā€œstate objectsā€. But probably this ā€œhiding thingā€ is available for custom cards via some programming interface - I do not know.
You may start monitoring this issue:

1 Like

Is anyone able to configure filters through the GUI editor? Iā€™m running into this issue that I just reported but Iā€™m curious if others are seeing issues or if itā€™s just me: Cannot configure filters in visual editor Ā· Issue #282 Ā· thomasloven/lovelace-auto-entities Ā· GitHub

Sorry for the late reply @Ildar_Gabdullin and @Mariusthvdb ,

I will try templating. As this is relatively new to me, I will need to do this during the weekend.

But something else I ran into last night:
I would like to use auto-entities within cards like horizontal stack, grid and picture-elements. But of course, when I have a lot of entities, then the auto-entities creates one long list.

Is it possible to somehow break this list into sections or make it create columns?

One idea would be to only display entites 1-10, then 11-20 and so on. So a filter which is not based on the entity information but only on the amount of entities returned?

1 Like

Thank you! Sometimes I am sooooo stupid ^^

For some reason, when I looked at sort, I took as meaning the very first one within the filter and not that I can define the number for the first one.

Duuuuuhhhhh :smiley:

So am I, welcome to the club :laughing:

1 Like

This may sound like a weird idea, but would it be possible to use auto-entities based on e.g. dashboard name?

So
something along the lines of

  • entities: sensor.* + #code that looks for e.g. living_room in the dashboad name

By the way, does anybody know why it is not possible to start and entity with * ?
So, why does

  • entities: *living_room
    not work but
  • entities: sensor.*living_room
    does work?

I donā€™t have an answer to your first question, unfortunately.

But when it comes to the use of * there are examples in the docs that show that you should use quotes, so "*living_room" should work.

1 Like

OK group or @thomasloven ā€¦ I am a bit lost on this one and I am trying to figure out whether this can be done.

Background ā€“ because of the demise of Insteon, I have been doing some GUI work to make things easier. As part of this, I created a sensor that can give me entity_idā€™s for all insteon devices and then I put them into an option list. Selecting an option list I can get the currently selected entity. Now because the auto-entities card only takes templates in the ā€œtemplateā€ of filter, I pass in that via jinja.

But I would have expected the ā€œauto-entitiesā€ card to toggle auto-magiclly to the type selected or even by setting the type to ā€œslider-entity-rowā€ ā€¦ instead it seems to only use a switch with on/off.

To explain further, look at this illustration:

Clearly the device is a dimmable entity, yet it does not show a slider for the dim setting.
Yet if I simple have the same entity in a card:

Maybe I need to add domain light? or?

In other words, does a the template filter actually control entities or? It seems like no matter what I do, I only see on/off

long time issue, I never got around to ask/post:
whenever I use auto-entities and add an entity in the entities list like:

  - type: custom:auto-entities
    card:
      type: entities
      title: Update entities
      entities:
        - sensor.hacs
    show_empty: false
    filter:
      include:
        - domain: update
          state: 'on'

the filters are applied correctly, or at all I should say. I only see the entity sensor.hacs.
Itā€™s not until I do

  - type: custom:auto-entities
    card:
      type: entities
      title: Update entities
      card_mod:
        class: class-header-margin
#      entities:
#        - sensor.hacs
    show_empty: false
    filter:
      include:
        - domain: update
          state: 'on'

I get to see the on entities of the domain update.

But, I want to see both, so am forced to do:

  - type: entities
    title: Updates available
    entities:
      - sensor.hacs
      - type: custom:auto-entities
        card:
          type: entities
          card_mod:
            style: |
              ha-card {
                box-shadow: none;
                margin: -16px;
              }
        show_empty: false
        filter:
          include:
            - domain: update
              state: 'on'

to get:

anyone seeing an obvious mistake in my top config, or do I file an issue report on a bug discoveredā€¦

btw, using an unindented entities section like:

  - type: custom:auto-entities
    card:
      type: entities
      title: Update entities
      card_mod:
        class: class-header-margin
    entities:
      - sensor.hacs
    show_empty: false
    filter:
      include:
        - domain: update
          state: 'on'

shows the sensor.hacs, but as a last item the list:

thanks for having a look!

Your last version (with it unindented) looks the most correct to me, or at least it works for me.

But what happens if you add a sort by name method? Does it put the HACS sensor first in this case?

The reason I ask is that it maybe working for me because the entity Iā€™m including always alphabetically precedes the filtered entities, so I wonā€™t have noticed it not working. In that case, it does sound like a bug.

yeah, I reread the docs again, and the unindented is what is was supposed to be apparently. So that was officially a ā€˜user-errorā€™ :wink:

didnt use the sort option yet, which would rely on the coincidental fact sensor.hacs would always precede the update domain entities alphabetically ā€¦

lll try when new updates arrive! thx

edit

yes that works fine:

So this is my first time using this card, and the possibilities seem great. I just messed up somewhere, or at least the behavior is unexpected. It is actually a modification of another post of @Mariusthvdb.
I have the following configuration. However, it seems as if the sorting isnt working.

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.afvalwijzer_gft
      options:
        type: custom:template-entity-row
        secondary: >
          {% set count =
          state_attr('sensor.afvalwijzer_gft','days_until_collection_date')|int
          %}

          {% set unit = 'Dag' if count == 1 else 'Dagen' %}

          {% if count == 0 %} Vandaag

          {% else %} Over {{count}} {{unit}}

          {% endif %}
    - entity_id: sensor.afvalwijzer_pmd
      options:
        type: custom:template-entity-row
        secondary: >
          {% set count =
          state_attr('sensor.afvalwijzer_pmd','days_until_collection_date')|int
          %}

          {% set unit = 'Dag' if count == 1 else 'Dagen' %}

          {% if count == 0 %} Vandaag

          {% else %} Over {{count}} {{unit}}

          {% endif %}
    - entity_id: sensor.afvalwijzer_papier
      options:
        type: custom:template-entity-row
        secondary: >
          {% set count =
          state_attr('sensor.afvalwijzer_papier','days_until_collection_date')|int
          %}

          {% set unit = 'Dag' if count == 1 else 'Dagen' %}

          {% if count == 0 %} Vandaag

          {% else %} Over {{count}} {{unit}}

          {% endif %}
    - entity_id: sensor.afvalwijzer_restafval
      options:
        type: custom:template-entity-row
        secondary: >
          {% set count =
          state_attr('sensor.afvalwijzer_restafval','days_until_collection_date')|int
          %}

          {% set unit = 'Dag' if count == 1 else 'Dagen' %}

          {% if count == 0 %} Vandaag

          {% else %} Over {{count}} {{unit}}

          {% endif %}
    - entity_id: sensor.afvalwijzer_luiers
      options:
        type: custom:template-entity-row
        secondary: >
          {% set count =
          state_attr('sensor.afvalwijzer_luiers','days_until_collection_date')|int
          %}

          {% set unit = 'Dag' if count == 1 else 'Dagen' %}

          {% if count == 0 %} Vandaag

          {% else %} Over {{count}} {{unit}}

          {% endif %}
sort:
  attribute: days_until_collection_date
  method: state
  numeric: true
  reverse: true
  ignore_case: true
show_empty: true
card:
  type: entities

result

as you can see the sorting doesnā€™t work as I expect. I would expect the PMD entry would be sorted between the once that take 2 days and 18 days. But somehow it doesnā€™t do that. Note that in displaying the attribute is correctly interpreted, but in sorting somehow this is not the case.

did you try:

        sort:
          method: attribute
          attribute: days_until_collection_date
          numeric: true

btw, you are not using the powers of auto-entities hereā€¦ you are simply listing the entities.

check:

          include:
            - entity_id: sensor.afvalwijzer_*
              options:
                type: custom:template-entity-row
                state: >
                  {% set trash = config.entity %}
                  {% set today = state_attr(trash,'is_collection_date_today') %}
                  {% set future = state_attr(trash,'days_until_collection_date') %}
                  {% if future is none or
                     (is_state(trash,'Geen') and future == 0) %} Tba
                  {% else %}
                  {{as_timestamp(strptime(states(trash),'%d-%m-%Y'))
                                  |timestamp_custom('%-d %b')}}
                  {% endif %}
                secondary: >
                  {% set trash = config.entity %}
                  {% set today = state_attr(trash,'is_collection_date_today') %}
                  {% set future = state_attr(trash,'days_until_collection_date') %}
                  {% if future is none or
                     (is_state(trash,'Geen') and future == 0) %} Nog niet gepubliceerd
                  {% else %}
                    {% set count = state_attr(trash,'days_until_collection_date')|int(default=0) %}
                    {% set day = as_timestamp(strptime(states(trash),'%d-%m-%Y'))
                       |timestamp_custom('%A') %}
                    {% set dagen =
                      {'Monday': 'Maandag',
                      'Tuesday': 'Dinsdag',
                      'Wednesday': 'Woensdag',
                      'Thursday': 'Donderdag',
                      'Friday': 'Vrijdag',
                      'Saturday': 'Zaterdag',
                      'Sunday': 'Zondag'} %}
                    {% set dag = dagen[day] if day in dagen else day %}
                    {% set unit = 'dag' if count == 1 else 'dagen' %}

                    {% if count >= 28 %} {% set phrase = dag + ' over 4 weken' %}
                    {% elif count >= 21 %} {% set phrase = dag + ' over 3 weken' %}
                    {% elif count >= 14 %} {% set phrase = dag + ' over 2 weken' %}
                    {% elif count >= 7 %} {% set phrase = 'Volgende week ' + dag %}
                    {% elif count >= 3 %} {% set phrase = 'komende ' + dag %}
                    {% elif count == 2 %} {% set phrase = dag + ', overmorgen' %}
                    {% elif count == 1 %} {% set phrase = 'morgen, ' + dag %}
                    {% else %} {% set phrase = 'Vandaag, ' + dag %}
                    {% endif %}
                    {{phrase}} {% if count != 0 %} ({{count}} {{unit}}) {% endif %}
                  {% endif %}
        sort:
          method: attribute
          attribute: days_until_collection_date
          numeric: true

Hi @Mariusthvdb,

thanks! that fixed it! I was aware that auto-entities was capable of automatically listing entities that satisfied a certain criteria. However, I wasnā€™t sure on how to access the attribute of that entity to get the ā€˜daysā€™ until. I guess that config.entity refers to all the entities that are selected by the sensor.afvalwijzer_* ā€˜filterā€™? Sorry if Iā€™m not using the right terminology, Iā€™m still fairly new to this.

Is there something similar to ā€œthis.entity_idā€ that only returns the entity_id without the domain?