🔹 Auto-entities - Automatically fill cards with entities

Using your config:
Note:

  1. Corrected "sort" options.
  2. Replaced “ip” custom_field with a “nothing” string.
  3. Left your layout-card definition as is.
type: 'custom:auto-entities'
card:
  type: 'custom:layout-card'
  layout: horizontal
  column_num: 7
  view_layout: horizontal
filter:
  include:
    - domain: device_tracker
      options:
        type: 'custom:button-card'
        size: 65%
        show_entity_picture: true
        style: |
          ha-card {
            background: none;
            box-shadow: none;
          }
        styles:
          grid:
            - grid-template-areas: '"i" "n" "ip"'
          card:
            - height: 130px
            - width: 130px
          name:
            - font-size: 13px
          custom_fields:
            ip:
              - align-self: center
              - justify-self: center
              - font-size: 12px
              - color: red
        custom_fields:
          ip: '[[[ return ''nothing'' ]]]'
  exclude:
    - entity_id: device_tracker.life360*
    - entity_id: device_tracker.*ping*
    - entity_id: device_tracker.*_*_*
sort:
  method: friendly_name
  ignore_case: true
  numeric: false

Using CORRECTED layout-card definition:

type: 'custom:auto-entities'
card:
  type: 'custom:layout-card'
  layout_type: 'custom:horizontal-layout'
  layout:
    max_width: 250
    max_cols: 7
filter:
  include:
    - domain: device_tracker
      options:
        type: 'custom:button-card'
        size: 65%
        show_entity_picture: true
        style: |
          ha-card {
            background: none;
            box-shadow: none;
          }
        styles:
          grid:
            - grid-template-areas: '"i" "n" "ip"'
          card:
            - height: 130px
            - width: 130px
          name:
            - font-size: 13px
          custom_fields:
            ip:
              - align-self: center
              - justify-self: center
              - font-size: 12px
              - color: red
        custom_fields:
          ip: '[[[ return ''nothing'' ]]]'
  exclude:
    - entity_id: device_tracker.life360*
    - entity_id: device_tracker.*ping*
    - entity_id: device_tracker.*_*_*
sort:
  method: friendly_name
  ignore_case: true
  numeric: false

Using Grid card:

type: 'custom:auto-entities'
card:
  type: grid
  columns: 7
card_param: cards
filter:
  include:
    - domain: device_tracker
      options:
        type: 'custom:button-card'
        size: 65%
        show_entity_picture: true
        style: |
          ha-card {
            background: none;
            box-shadow: none;
          }
        styles:
          grid:
            - grid-template-areas: '"i" "n" "ip"'
          card:
            - height: 130px
            - width: 130px
          name:
            - font-size: 13px
          custom_fields:
            ip:
              - align-self: center
              - justify-self: center
              - font-size: 12px
              - color: red
        custom_fields:
          ip: '[[[ return ''nothing'' ]]]'
  exclude:
    - entity_id: device_tracker.life360*
    - entity_id: device_tracker.*ping*
    - entity_id: device_tracker.*_*_*
sort:
  method: friendly_name
  ignore_case: true
  numeric: false

That works like a charm! Thank you very much! I just couldn’t see it anymore after al there hours of staring :laughing:

Hello,

with the auto-entities card i like a list of temperature devices whose battery_level is below 60%
this works, but my friendly names are composed like temperatuur batterijniveau tuin (translate temperature battery_level garden). I want to strip the temperatuur batterijniveau part, its in all of the names, so a bit redundant.

I tried several options with the options setting but so far no luck, all i tried to put in is taken literally and displayed as name so no name regex replace possibility so far as I can see. anybody out here with a solution?

type: 'custom:auto-entities'
card:
  type: entities
  state_color: true
  title: Batterij laag temperatuursensoren
filter:
  include:
    - entity_id: sensor.*temp*_batterijniveau*
      state: < 60
      options:
         name: ??????????????????????????????????????
  exclude:
    - entity_id: sensor.beweginglichtsterktetemp*
sort:
  method: state
  reverse: true
show_empty: true

temperatuurlaag

you cant directly in auto-entities, but you could have a go at template-entity-row in the options

Kind of this:

filter:
  template: |
    {% set batteries = expand('group.batteries') -%}
    {%- for battery in batteries -%}
      {%- set NAME = battery.entity_id -%}
      {%- set NAME_SHORT =  NAME.split('sensor.battery_')[1] -%}
      {{
        { 'entity': battery.entity_id,
          'name': NAME_SHORT,
          'secondary_info': 'last-changed'
        } }},
    {%- endfor -%}

O yes, I forgot about the template option, not sure if it will go all the way though, fulfilling all necessary requirement here. At least should add:

if battery.state|int < 20

to make it

{%- for battery in batteries if battery.state|int < 60 -%}

using the template entity row is way more flexible though:

      - type: custom:auto-entities
        card:
          type: entities
          style: |
            ha-card {
              box-shadow: none;
              margin: 0px 0px 0px -36px;
            }
        filter:
          include:
            - group: group.github_repos_in_use
              options: &github_options
                tap_action:
                  action: more-info
                hold_action:
                  action: navigate #url
                  navigation_path: /ui-settings/weblinks
                  #url_path: >
                  #  {{state_attr('this.entity_id','latest_release_url')}}
                type: custom:template-entity-row
                style: |
                  :host {
                    --paper-item-icon-color:
                      {% set id = config.entity.split('.')[1] %}
                      {% set repo = 'input_boolean.' + id %}
                      {{'gold' if is_state(repo,'on') else 'green'}}
                      ;
                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

You are right!
This was a good educational example.

Hi guys,

Thanks for the hint, will try the template and template-entity-row option, and Marius sorry to say but your educational example way to complicated, way to steep for a beginner to even get a glance of whats its doing in relation to my question, thanks for letting me know what the possibilities are but in no way Iam at your level, just scratching the surface here :wink:

regards Frank

These examples are very useful for learning ))) and they are not too complicated, just get rid of unimportant things.

You are absolutely right, but I see it as, I asked to teach me how to ride a bike, and the example put me in a space shuttle, overwhelmed, and going stripping till I get the results I want not gonne cut it starting with the whole

style: |
:host {

thing, no mention of it in the custom:template-entity-row documentation, even google has no answer on the search home assistant :host

So, good example yes, but not for beginners, sorry…

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: