🔹 Auto-entities - Automatically fill cards with entities

Not Away, not away - must be not _home.

3 Likes

bingo! rock on dude, thank you

Here is what I use to display the friendly name in the primary field of my mushroom template card:

primary: '{{ state_attr(entity, "friendly_name") }}'

Thank you! That advice got me on the right track, and I was able to accomplish everything and more. Here is the fix:

image

type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 1
filter:
  include:
    - name: /Climate Sensor Temperature/
      options:
        type: custom:mushroom-template-card
        icon: mdi:thermometer
        primary: >
          {{state_attr(entity,'friendly_name') | replace('Climate Sensor
          Temperature','') }}
        secondary: |
          {{states(entity)+" °F"}}
        icon_color: |-
          {% set state=states('this.entity_id') %}
          {% if state > '70' %}
            red
          {% elif state > '69' %}
            orange
          {% else %}
            yellow
          {% endif %}
  exclude:
    - state: unavailable
sort:
  method: state
  reverse: true
  numeric: true
show_empty: false
card_param: cards

And if anyone else is going down a similar rabbit hole, here is my finished code which includes more intricate color-coding:
image

type: custom:auto-entities
card:
  square: false
  type: grid
  columns: 2
filter:
  include:
    - name: /Temperature/
      options:
        type: custom:mushroom-template-card
        icon: mdi:thermometer
        primary: >
          {{state_attr(entity,'friendly_name') | replace('Climate Sensor
          Temperature','') | replace('Temperature','') }}
        secondary: |
          {{states(entity)+" °F"}}
        icon_color: |-
          {% set state=states('this.entity_id') %}
          {% if state >= '-80' and state < '-20' %}
            #cbdbf4
          {% elif state >= '-20' and state < '-10' %}
            #7591b9
          {% elif state >= '-10' and state < '0' %}
            #7591b9
          {% elif state >= '0' and state < '10' %}
            #7591b9
          {% elif state >= '10' and state < '20' %}
            #4d6591
          {% elif state >= '20' and state < '30' %}
            #39517f
          {% elif state >= '30' and state < '32' %}
            #2f4775
          {% elif state >= '32' and state < '35' %}
            #275b80
          {% elif state >= '35' and state < '40' %}
            #275b80
          {% elif state >= '40' and state < '45' %}
            #275b80
          {% elif state >= '45' and state < '50' %}
            #256789
          {% elif state >= '50' and state < '55' %}
            #287593
          {% elif state >= '55' and state < '60' %}
            #438190
          {% elif state >= '60' and state < '65' %}
            #648d89
          {% elif state >= '65' and state < '70' %}
            #879a84
          {% elif state >= '70' and state < '75' %}
            #aba87d
          {% elif state >= '75' and state < '80' %}
            #c0a978
          {% elif state >= '80' and state < '85' %}
            #c19d61
          {% elif state >= '85' and state < '90' %}
            #c38a53
          {% elif state >= '90' and state < '95' %}
            #be704c
          {% elif state >= '95' and state < '100' %}
            #af4b4e
          {% elif state >= '100' and state < '105' %}
            #9e294c
          {% elif state >= '105' and state < '110' %}
            #87203e
          {% elif state >= '110' and state < '115' %}
            #6e1531
          {% elif state >= '115' and state < '120' %}
            #560c25
          {% elif state >= '120' and state < '150' %}
            #3d0216
          {% else %}
            black
          {% endif %}
  exclude:
    - state: unavailable
    - state: unknown
    - name: PirateWeather*
    - name: OpenWeatherMap*
sort:
  method: state
  reverse: true
  numeric: true
show_empty: false
card_param: cards

Hi. I wonder if I could filter by one entity but show another entity by replacing chars in the filtered entity name, like the following (note: I don’t fully understand the syntax of the auto-entities card so I have most probably errors in the code below). Aim: to filter mobile devices to only those which are actually charging (sensor.XXX_battery_state = ‘charging’) but then display their battery levels instead (sensor.XXX_battery_state >> replacing ‘_state’ for ‘_level’ >> sensor.XXX_battery_level). Thanks.

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - entity_id: sensor.*battery_state
      state: charging
      options:
        entity: |
          {{ this.entity_id | replace('_state', '_level') }}
sort:
  method: state
  numeric: false
show_empty: false

Hi

Today I learned the purpose of <card_param>
An option I did overlook for a long time.
The <card_param> option allows to generate the entries into another card object then the default entities:. As several cards list there entries under different objects then entities, this allow to still populate them with auto entities.

I want to share a short more challenging example. Auto populate a ‘history-explorer’ card. This particular card is a little more complex as the entities are declared in sub keys of a list of graph types. So not a simple rename using <card_param>. Using a template filter makes that possible:

This is a simple history-explorer card, configured in the standard way:

type: custom:history-explorer-card
graphs:
  - type: line
    entities:
      - entity: sensor.temperatures_bedroom
      - entity: sensor.temperatures_living
 ...

This is the same card, but populated with auto-entities:

type: custom:auto-entities
card_param: graphs
filter:
  template: >
    {%- set entities = state_attr('sensor.temperatures_binnen','entity_id') or
    [] -%}
    {%- set ns = namespace(lines=[]) -%}
    {%- for entity in entities -%}
      {%- set ns.lines = ns.lines + [{'entity': entity }] -%}
    {%- endfor -%}
    {%- set graph=[
             {'type': 'line',
              'entities': ns.lines}, 
              ]  
     -%}
    {{ graph }}      
card:
  type: custom:history-explorer-card

Simple things, like your request, can be done using a template filter.
With the template-entity-row you can generate rows with whatever you like, instead of an entity. I used them to list devices

Then consider closing your issue in auto-entities github.

…It is closed

Thank you for your help with the history explorer card. Been looking so long for that.

I got some extra gray hair as well to get that working :face_with_peeking_eye:

Haha I’ve lost hair over this…

I’ve circled back to trying to get auto entities and history Explorer to work together two or three times over the last couple of years and had still not come up with a solution.

I think I even raised a feature request on the repository for history Explorer asking to be able to provide the graph definitions from a template

I knew the solution needed <card_param> but I just couldn’t get it t work.

This is going to make my Bayesian sensor diagnostics page maintenance free.

1 Like

Even you have posted that example long time ago, have you found solutions for the open items?
I have started to adopt the idea a little bit:

type: custom:template-entity-row
name: >-
  {{state_attr(config.entity, 'friendly_name')|regex_replace(find='17Track Paket
  ', replace='', ignorecase=True)}}
secondary: |-
  {% if state_attr(config.entity, 'location') %}
    {% if state_attr(config.entity, 'location') == "CN" %}
      China:
    {% else %}
      {{state_attr(config.entity, 'location')}}:
    {% endif %}
  {% endif %}
  {% if state_attr(config.entity, 'info_text') %}
    {{state_attr(config.entity, 'info_text')}}
  {% endif %}
icon: |
  {% if states(config.entity) == "In Transit" %} 
    mdi:truck-delivery
  {% elif states(config.entity) == "Delivered" %}
    mdi:package-variant
  {% elif states(config.entity) == "Not Found" %}
    mdi:briefcase-search
  {% elif states(config.entity) == "Returned" %}
    mdi:directions-fork
  {% elif states(config.entity) == "Undelivered" %}
    mdi:help-box
  {% elif states(config.entity) == "Expired" %}
    mdi:timer-off
  {% elif states(config.entity) == "Collection" %}
    mdi:package-variant-closed
  {% else %}
    mdi:alert-circle
  {% endif %}
tap_action: |
  {
    "action": "url",
    "url_path": {
      "https://t.17track.net/en#nums={{ state_attr(config.entity, 'tracking_number')}}"
    },
  }
card_mod:
  style: |
    :host {
      --card-mod-icon-color:
        {% if states(config.entity) == "In Transit" %} 
          blue
        {% elif states(config.entity) == "Delivered" %}
          green
        {% elif states(config.entity) == "Not Found" %}
          red
        {% elif states(config.entity) == "Returned" %}
          orange
        {% elif states(config.entity) == "Undelivered" %}
          red
        {% elif states(config.entity) == "Expired" %}
          grey
        {% elif states(config.entity) == "Collection" %}
          purple
        {% else %}
          red
        {% endif %}
        ;
    }

tap_action template works, animation has been deleted.

Can anyone tell me why this template is not working in my auto-entities card? It works to produce a list in developer tools so I’m at a loss.

type: custom:auto-entities
card:
  type: entities
  state_color: true
  title: ''
filter:
  template: |
    {{ states
    | selectattr('entity_id', 'in', integration_entities('zha'))
    | selectattr('state', 'in', ['off'])
    | map(attribute='entity_id')
    | map('device_attr', 'name_by_user') 
    | reject('match', 'None')
    | unique
    | list 
    }}

I am getting this as the card output:

The developer tools output is this:

As you are effectively using the standard HA entities card, you need to provide the entity_id under the entity: key, not the friendly name. That’s what the error is telling you anyway.

Test removing | map('device_attr', 'name_by_user')

Yes, that does produce something. I was hoping to have a list that would just show unique devices, though, and not the various entities for each device.

Appreciate it. I removed the "| map(‘device_attr’, ‘name_by_user’) " as suggested by another commenter and it produces something. I was ultimately wanting a list of unique devices but maybe that is not possible with the auto-entities card.

You could build a list of the entities and include device_id. Then, get them by unique id.

Use the second code section in this post as an example
Devices and Areas - Configuration / Frontend - Home Assistant Community (home-assistant.io)

can it be that the Action-Taps in templtes doenst work any more? (you use it right? @Mariusthvdb )
when i add it, no enteties are there, without all fine

  template: |-
    {% for state in states.climate %}
      {%- if state.entity_id | regex_match("climate.*_klimaanlage", ignorecase=False) 
        and state.state in ["auto", "cool", "heat", "dry"] -%}
        {{
          {
            'type': "tile",
            'entity': state.entity_id,
            'name': state.attributes.friendly_name.split(' Klimaanlage')[0]
            'icon_tap_action': {'action':'toggle'}
          }
        }},
      {%- endif -%}
    {% endfor %}