🔹 Auto-entities - Automatically fill cards with entities

Those “style” things are for “card-mod”.
Try learning this example (without card-mod):

      - type: custom:auto-entities
        card:
          type: entities
        filter:
          include:
            - group: group.github_repos_in_use
              options:
                type: custom:template-entity-row
                state: >
                  {% if states(config.entity) is not none %}
                    {% if state_attr(config.entity,'latest_release_tag') %}
                    {{state_attr(config.entity,'latest_release_tag')}}
                    {% else %} {{states(config.entity)}}
                    {% endif %}
                  {% else %} Unknown
                  {% endif %}
                secondary: >
                  {% if states(config.entity) == 'unavailable' %} Unavailable
                  {% elif states(config.entity) is not none %}
                    {{state_attr(config.entity,'latest_commit_message')}}
                  {% else %} Unknown
                  {% endif %}
              sort:
                method: name

I will try learning it too since "template-entity-row" is a new thing for me too )))

basically what this does, is use the auto-entities card, set it to display entities in an entities card, which it should get from the entities in the group. (if you want, you can also use the other options of auto-entities, but the group is very easy)

It should do that, using the specified options. In this case I suggested the template-entity-row, with which you can set anything (state, icon, name etc etc, see the options there) with a template.

for that you use the config.entity (you dont hard code any entities, since this is created automatically) and the templates are for that entity. Depending on your naming, you should adjust the template.
Dont quote config.entity in those templates, since it is a system variable, and not a string.
What is your naming convention in the sensors?

Hai Marius,

Thanks for the clarification, I tried the stripped example form Ildar_Gabdullin, tried to modify it, bit no luck.
as said, Just scratching the surface here, the problem is that it is a huuuuge surface :slight_smile:

My naming convention is straight forward:
sensortype.TypeOfDevice_property_zone

example, in dutch :wink:
sensor.deur_batterijniveau_keuken (translate sensor.door_batterylevel_kitchen)

and another example of a temperature/humidity/pressure device

sensor.temphygrobaro_pressure_garden
sensor.temphygrobaro_humidity_garden
sensor.temphygrobaro_temperature_garden
sensor.temphygrobaro_temperature_batterylevel_garden

etc etc

In my auto-entities card I use sensor.temp*_batterijniveau*
to show the various temperature sensors.

Regards
Frank

ok, no problem :wink:

what you want to do here, is first make a regular template based on 1 of your real life entities in the template editor developer-tools/template

so, if all your sensors contain batterijniveau_ and you want the name to be the ‘zone’

you split at that string (and capitalize because thats a better name in the frontend)

{% set door = 'sensor.deur_batterijniveau_keuken' %}
{{door.split('batterijniveau_')[1]|capitalize}}

if that works out for you, you can use that on the config.entity in the template-entity-row

name: >
  {{config.entity.split('batterijniveau_')[1]|capitalize}}

unless of course you already had set the friendly_name of the sensor itself, and you could use that:

name: >
  {{config.entity.attributes.friendly_name}}

just give it a try

Thanks Marius and Ildar_Gabdullin

Will indeed give it a try, eager to learn, just love the possibilities.
But wont be able to try till Sunday, will let you know how I progress.

Regards,
Frank

Hi Marius,

Little later than Sunday, but here is my solution following your guidance.

type: 'custom:auto-entities'
card:
  type: entities
filter:
  include:
    - entity_id: sensor.temp*_batterijniveau*
      state: < 101
      options:
        type: 'custom:template-entity-row'
        state: |
          {{states(config.entity)}}{{' %'}}
        name: |
          {{config.entity.split('_')[-1]|capitalize}}
        secondary: >
          {{ as_timestamp(states[config.entity].last_changed)|
          timestamp_custom('%d %b %X') }}
      sort:
        method: state
        reverse: false
        numeric: true

As you can see I left out the split part batterijniveau_ I had another underscore following in 2 of my sensors namely Lcd_ So I came up with the split to use only the underscore and the [-1] part, show only the last split and it works. :wink: as a bonus I added the secondary info, although this was a little bit different in format as you can see than the regular config.entity.atrributes…

An here the result:

marius

Ofcourse the cutoff value has to be set about 20% or so, for this example it was set to 101% show all…
Regards and thanks.
Frank

1 Like

Hi,

Did someone now if you can set a fix height to the auto-entities card?
I have is a glance card that is sometimes empty (that’s good),
I have the “show_empty:” on true,
But when the card is empty, the height of the card is not the same height else when there are entities in it.

stuck really, editing an older card of mine, which wont show the geo_location entities anymore…

    filter:
      template: |
        {% set km = states('input_number.quakes_near')|float %}
        {% set location = states('input_select.quakes_near') %}
        {% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed') %}
        {% if distance(s.entity_id,location) < km %}
          {{- s.entity_id -}}
        {% endif %}
        {% endfor %}

gives me the error:

 Either entities or geo_location_sources must be specified

the geo_location entity is live, and the the template is correct:

so where is the error here…

odd thing is, it does show sometimes…:

please have a close look with me,
thanks!

Cannot reproduce it with geo_location, but it works with device_tracker.life360*.

yeah, Petro helped me out, it should be done with a namespace template:

          template: >
            {%- set ns = namespace(quakes_near=[]) %}
            {% set km = states('input_number.quakes_near')|float %}
            {% set location = states('input_select.quakes_near') %}
            {% for s in states.geo_location|selectattr('attributes.source','eq','usgs_earthquakes_feed')
                 if distance(s.entity_id,location) < km %}
                  {% set ns.quakes_near = ns.quakes_near + s.entity_id %}
            {% endfor %}
            {{ns.quakes_near}}

though I believed the other template to also create a true list because the empty list showed as [] in the editor, it probably doesn’t… this should be correct., only thing is I can not really test it, because there’s no quakes near at the moment :wink:

I am trying to populate the entities with filter: template: but I would like to change the display name of each entity based on their entity_id. It seems like something using options: as in this solution. It just seems like options: won’t work with filter: template:. I am open to any approach to solve this problem.

Basically I am trying to display all the settings I have configured by room, or by behavior (motion light activation, circadian/adaptive lighting, etc.) but I have to display the input_boolean/input_select/input_switch with a different name for each of these configuration methods. When showing settings by room, I need to display the behavior as the display name of the settings entity. When showing settings by behavior, I need to display the room as the display name of the settings entity.

I created this template which gathers the data I need into lists, but I’m not sure what the best way to turn this into the display I am aiming for.

{% if states('input_select.settings_behavior') == "Motion Activation" %}
  {% set behavior_entity_type = 'input_boolean' %}
  {% set behavior_regex = '\'input_boolean\.((?!motion_lights)[^\'])+\',?' %}
{% elif states('input_select.settings_behavior') == "Natural Lighting" %}
  {% set behavior_entity_type = 'switch' %}
  {% set behavior_regex = '\'switch\.((?!adaptive_lighting_(?!adapt|sleep))[^\'])+\',?' %}
{% endif %}
{% set entity_list = (states[behavior_entity_type] | map(attribute='entity_id') | list | regex_replace(behavior_regex)) %}
{% set area_list = (entity_list | regex_replace('input_boolean.motion_lights_')) %}
{{ [entity_list, area_list] | regex_replace('"\[','[') | regex_replace('\]"',']') }}

I also tried using config-template-card to create do the switching, but I’m having trouble getting this working.

      - type: entities
        entities:
          - input_select.settings_behavior
      - type: custom:config-template-card
        entities:
          - input_select.settings_behavior
        variables:
          behavior_prefix: |
            if (states[ 'input_select.settings_behavior' ].state === "Motion Activation") {
              return 'input_boolean.motion_lights_';
            } else if (states[ 'input_select.settings_behavior' ] === "Natural Lighting") {
              return 'switch.adaptive_lighting_';
            }   
          behavior_regex: |
            if (states[ 'input_select.settings_behavior' ].state === "Motion Activation") {
              return 'input_boolean.motion_lights*';
            } else if (states[ 'input_select.settings_behavior' ] === "Natural Lighting") {
              return '/switch\.adaptive_lighting_(?!adapt|sleep)/';
            }   
        card:
          type: custom:auto-entities
          card:
            type: custom:auto-entities
            card:
              type: entities
              title: 'Areas'
            filter:
              include:
                - entity_id: ${behavior_regex}
                  options:
                    type: 'custom:template-entity-row'
                    name: |
                      {{ config.entity.split(${behavior_prefix})[-1] | regex_replace('_', ' ') | capitalize }}

The only other way I can think to do it is with a very big custom:state-switch card containing a bunch of auto-entities cards. Which seems like a headache to come back to if I need to add more settings.

First of all, a huge thank you to @thomasloven for this fabulous card.
I confess to not having read all the posts, so please bear with me if my question has already been answered.
I would love to be able to sort by the most recent entry. Is that already possible?

Do you mean "last-changed"?

No, I mean last added to HA.

I do not know any exposed property expressing a “creation time” for entity.
If it is not present - then it is not possible to sort by it.
So, first find out about this property.

Could someone help me I can NOT figure out how to make the background transparent on this card. With my code as is the background is transparent when in the editor. soon as I save it does not show as transparent.

type: 'custom:auto-entities'
show_empty: false
style: |
  ha-card {
   background-color: transparent;
  }
card:
  type: entities
  title: Currently On / Running
  show_header_toggle: false
  style: |
    ha-card {
     background-color: transparent;
    }
filter:
  include:
    - domain: light
    - domain: switch
  exclude:
    - state: 'off'
    - state: unavailable
    - entity_id: light.desk_wall_right_light
    - entity_id: light.desk_wall_left_light
    - entity_id: light.wood_stove_l_e_ds
    - entity_id: light.fam_tv_l_e_ds
    - entity_id: light.family_room_wall_l_e_ds
    - entity_id: switch.g3syn_home_mode
    - entity_id: light.his_bed_l_e_ds
    - entity_id: light.his_room_access_point
    - entity_id: light.my_lights
    - entity_id: light.google_wifi_ap_a
    - entity_id: light.google_wifi_ap_b
    - entity_id: light.family_room_bulb_1
    - entity_id: light.family_room_bulb_2
    - entity_id: light.family_room_bulb_3
    - entity_id: light.family_room_bulb_4
    - entity_id: light.fire_side_bulb_1
    - entity_id: light.fire_side_bulb_2
    - entity_id: light.fire_side_bulb_3
    - entity_id: light.boiler_room_bulb_1
    - entity_id: light.boiler_room_bulb_2
    - entity_id: light.basment_bulbs
    - entity_id: light.fire_side_bulbs
    - entity_id: light.family_room_bulbs

The 1st style will not work.
The 2nd style works:

But does it still work after you save and return to the dashboard? Soon as I do it reverts to the default theme even with red. This is really messing with me as even when i go back to “edit” it will blink red and go back to the dark mode default. I have MANY cards on my setup and this one is the ONLY 1 that wont go transparent.

I do not see any flickering.
I tested this case with a card which is not placed inside some other card.
Could you provide a whole code for your card?
Also, I am using a default Lovelace theme.

OMG, you were 100% right! I moved it to a stand-alone card and BOOM it worked! HTF I did not try that months ago I don’t know… Thank you so much go’s to show some times you just need a kick in the but. haha