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

Hi Thomas,
I need your help. I have been trying to make this card work with a template for hours. Without success.

  - title: Stats
    cards:
      - type: custom:auto-entities
        card:
          type: entities
        filter:
          template: |
            {% for state in states.sensor | selectattr('attributes.device_class', '==', 'battery') %}
              {% if 0 <= state.state | int(-1) <= 100 | int %}
                {{ state.name }}
              {% endif %}
            {% endfor %} 
            {% for state in states.binary_sensor | selectattr('attributes.device_class', '==', 'battery') %}
                {{ state.name }}
            {% endfor %}

      - type: custom:auto-entities
        card:
          type: entities
        filter:
          template: |
            {% for light in states.light %}
            {% if light.state == "on" %}
                {{ light.entity_id }},
              {% endif %}
            {% endfor %}

I get nothing in the card - see first block.
I included the example from your page to confirm the card works (second block with two lights on).

HOWEVER, when I use Template in the Developer Tools, the result shows the list of all batteries (with %) along with all the sensors that have a battery.

Can you please help me understand what I am not doing right?
Thanks in advance,
Gerard

I am trying to figure out how to use the or: for filters in custom:auto-entities and canā€™t find any example or reference to it.

In the documentation, filter section, it lists the special option:

Special options:
...
or: Match any in a list of filters.

I canā€™t figure out where and how to apply the or: clause. I was trying to find a way to make this look ā€˜betterā€™:

  filter:
    include:
      - entity_id: "sensor.ble_temperature_*"
        options: { type: "custom:mushroom-entity-card" }
      - entity_id: sensor.netatmo_indoor_temperature
        options: { type: "custom:mushroom-entity-card" }
      - entity_id: sensor.indoor_temperature_average
        options: { type: "custom:mushroom-entity-card" }

The intention would be to only have to specify the card type once - instead for each entity that is included. I guess I could contruct a regex for entity_id but that would probably not look very nice either.

Can this be done differently ?

1 Like

I try to combine a template filter with a secondary info, but cannot get it to work. Maybe someone with more experience can spot the problem:

  - type: custom:auto-entities
    card:
      show_header_toggle: false
      type: entities
    filter:
      template: |
        {%- for s in states.binary_sensor %}
          {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' %}
            {%- if not state_attr(s.entity_id, 'installed_version') == state_attr(s.entity_id, 'latest_stable_version') %}
              {{
                {
                  'type': 'custom:secondaryinfo-entity-row',
                  'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
                  'secondary_info': 'test'
                }
              }},
            {%- endif %}
          {%- endif %}
        {%- endfor %}
      include:
        - entity_id: '*firmware_update'
          state: 'off'
          options:
            type: custom:secondaryinfo-entity-row
            secondary_info: '[[ this.entity_id.attributes.installed_version ]]'
      exclude:
        - attributes:
            installed_version: '*rc*'
        - attributes:
            installed_version: '*beta*'
        - attributes:
            latest_stable_version: ''

Idea is to show a list of shelly devices that have a firmware upgrade due and offer the option to upgrade in place. The secondary info, once it displays at all, should show the current and new firmware.

At the bottom of the list (via include) come the remaining shelly devices with the current firmware installed as secondary info.

I understand that I cannot use options: for templates, which would make this easier. Correct?

1 Like

Answering my own question, Iā€™ve now figured it out. Essentially, I was not closing {%- with -%}. Correct code:

type: vertical-stack
cards:
  - type: custom:button-card
    name: Shelly Firmware Upgrades
    template: label_card
  - type: custom:auto-entities
    card:
      show_header_toggle: false
      type: entities
    filter:
      template: >
        {%- for s in states.binary_sensor -%}
          {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' -%}
            {%- if not state_attr(s.entity_id, 'installed_version') == state_attr(s.entity_id, 'latest_stable_version') -%}
              {{
                {
                  'type': 'custom:secondaryinfo-entity-row',
                  'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
                  'secondary_info': state_attr(s.entity_id, 'latest_stable_version') + "<br>" + state_attr(s.entity_id, 'installed_version')
                }
              }},
            {%- endif -%}
          {%- endif -%}
        {%- endfor -%}
      include:
        - entity_id: '*firmware_update'
          state: 'off'
          options:
            type: custom:secondaryinfo-entity-row
            secondary_info: '[[ this.entity_id.attributes.installed_version ]]'
      exclude:
        - attributes:
            installed_version: '*rc*'
        - attributes:
            installed_version: '*beta*'
        - attributes:
            latest_stable_version: ''

resulting in

To make it a bit easier on the eye, Iā€™ve put in a divider as well:

type: vertical-stack
cards:
  - type: custom:button-card
    name: Shelly Firmware Upgrades
    template: label_card
  - type: custom:auto-entities
    card:
      show_header_toggle: false
      type: entities
    filter:
      template: |
        {%- for s in states.binary_sensor -%}
          {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' -%}
            {%- if not state_attr(s.entity_id, 'installed_version') == state_attr(s.entity_id, 'latest_stable_version') -%}
              {{
                {
                  'type': 'custom:secondaryinfo-entity-row',
                  'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
                  'secondary_info': state_attr(s.entity_id, 'latest_stable_version') + "<br>" + state_attr(s.entity_id, 'installed_version')
                }
              }},{{
                {
                  'type': 'divider'
                }
              }},
            {%- endif -%}
          {%- endif -%}
        {%- endfor -%}
      include:
        - entity_id: '*firmware_update'
          state: 'off'
          options:
            type: custom:secondaryinfo-entity-row
            secondary_info: '[[ this.entity_id.attributes.installed_version ]]'
      exclude:
        - attributes:
            installed_version: '*rc*'
        - attributes:
            installed_version: '*beta*'
        - attributes:
            latest_stable_version: ''

nice work :wink: I am hoping an update to template-entity-row can fix the Button, (by adding a button: true option) so for now this is in my test pages:

          filter:
            template: >
              {%- for s in states.binary_sensor -%}
                {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' -%}
                    {{
                      { 'type': 'custom:template-entity-row',
                        'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
                        'state': 'BUTTON',
                        'secondary': state_attr(s.entity_id, 'installed_version')
                      }
                    }},
                {%- endif -%}
              {%- endfor -%}

reason of post: you can take put the test for the installed version != stable version can you? that is always the case if the binary is on?

@kongo09 Love your use of code around the shellies and their firmware version.
I tried using your code but Iā€™m missing the ā€œlabel_cardā€ template, can you possibly post the code and would that cure the undefined bit I see?

image

After looking into the codeā€¦
I think installed_version is old_version and latest_stable_version is new_version for me in the atrributes.
This corrected the undefined but I have no Shellyā€™s out of date to test the new version part.
Why the difference in attribute though?
I have mine added via MQTT

Hm, I guess you have a point here.

Apologies, the label_card template is actually not required and I use that only for my personal styling. You donā€™t need the whole vertical-stack part at all. Try:

type: custom:auto-entities
  card:
    show_header_toggle: false
    type: entities
  filter:
    template: |
      {%- for s in states.binary_sensor -%}
        {%- if s.object_id.endswith("firmware_update") and states(s.entity_id) == 'on' -%}
          {{
            {
              'type': 'custom:secondaryinfo-entity-row',
              'entity': "button." + s.object_id.replace("firmware_update", "ota_update"),
              'secondary_info': state_attr(s.entity_id, 'latest_stable_version') + "<br>" + state_attr(s.entity_id, 'installed_version')
            }
          }},{{
            {
              'type': 'divider'
            }
          }},
        {%- endif -%}
      {%- endfor -%}
    include:
      - entity_id: '*firmware_update'
        state: 'off'
        options:
          type: custom:secondaryinfo-entity-row
          secondary_info: '[[ this.entity_id.attributes.installed_version ]]'
    exclude:
      - attributes:
          installed_version: '*rc*'
      - attributes:
          installed_version: '*beta*'
      - attributes:
          latest_stable_version: ''

is it perhaps possible that i can only show devices that have the name ā€œfenstersensor XXXXā€
i tried different settings but i dont get only devices with this name

The auto-entities card is for generating a list of entities, not devices.
You may generate a list of entities associated to some defined device.

with this code it works very well

- entity_id: sensor.fenstersensor*_battery_level*
  attributes:
    device_class: battery

I want to list automation based on area. I can list all automation or entities based on area, can I combine both?
I named my automation in the following way, if the above is not possible, is it possible to filter the automation based on the first part of the automation name? eg: [Bedroom], [Dyson] etc?
image

Hello i have this card to show if something is open, is it possible to make like a ā€œbottom card templateā€ to reduce duplicate code when i have to add all my sensors?

type: custom:auto-entities
card:
  type: entities
  title: Security
  icon: mdi:shield-home
filter:
  include:
    - entity_id: binary_sensor.office_window_contact
      state: 'on'
      options:
        secondary_info: last-changed
        name: Office Window
        card_mod:
          style:
            hui-generic-entity-row:
              $: |
                state-badge {
                  {% if is_state('binary_sensor.office_window_contact', 'on') %}
                  animation:  blink 2s linear alternate infinite;
                  color: red !important;
                  {% endif %}
                }      
                @keyframes blink {
                  0% {opacity: 1;}
                  100% {opacity: 0;}
                }
                .info {
                  {% if is_state('binary_sensor.office_window_contact', 'on') %}
                  color: red;
                  {% endif %}
                }      
                @keyframes blinking {
                  0% {opacity: 1;}
                  100% {opacity: 0;}
                }
                .text-content:not(.info) {
                  {% if is_state('binary_sensor.office_window_contact', 'on') %}
                  animation:  blink 2s linear alternate infinite;
                  color: red;
                  {% endif %}
                }
        icon: mdi:window-open-variant

Any special reason to auto-create a list with just ONE entity with a known name?
Since you need to show the row only if ā€œONā€ - you may use a conventional conditional row.

In general (not for this case which is unclear for me) - try using decluttering-card.

1 Like

No special reason, I just didnā€™t know there was another way :roll_eyes: but thanks ill try it out!
Also I will see if I can figure out how to use decluttering-card

Thanks a lot for your answer!

Hi guys

How do I turn this into a grid layout.

type: custom:auto-entities
card:
  type: entities
  title: Fronius Readings
  state_color: true
filter:
  include:
    - integration: fronius
      options:
        type: custom:mushroom-entity-card
  exclude: []
sort:
  method: friendly_name

Hi,

I want to use filter template to display only entities for area based on input_text.
Now my code looks like:

type: custom:auto-entities
card:
  type: custom:layout-card
  layout: horizontal
  column_num: 2
  view_layout: horizontal
filter:
  exclude: []
  include:
    - domain: light
      options:
        type: custom:auto-entities
        card:
          type: custom:layout-card
        styles:
          card:
            - height: 200px
            - width: 200px
        filter:
          template: >-
            {% if area_name(config.entity) == states('input_text.room')
            %}           
              {{ [
                {
                  "type": "custom:button-card",
                  "entity": config.entity,
                }
             ] }}
            {% endif %}
        show_empty: false
show_empty: false

But not matching entities are not displayed, but are created and there are empty places .
DEV_ā€“Home_Assistant-_2022-04-03_19.03.47

How can i achieve list without this empties ?

Regards

Is it possible to show the value of an attribute in the card rather than the main state value?

I have a bunch of Zigbee sensors integrated through zigbee2mqtt. They all have linkquality and battery attributes and some have other attributes as well. I would like to have a battery card that showed the battery levels of all of them for example.

Kind of this:

  - type: custom:auto-entities
    card:
      type: entities
    unique: true
    show_empty: true
    filter:
      include:
        - entity_id: device_tracker.*
          attributes:
            ip: "*.*"
          sort:
            count: 2
            method: name
          options:
            type: attribute          ##### show attribute value
            attribute: ip
            secondary_info: last-changed

image

The most difficult issue is to specify a filter to show only your required entities.
In my example only trackers with present ā€œipā€ attribute are listed.

1 Like