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

got to love the new integration_entities template options, and a very nice template for auto-entities indeed!

whatā€™s your issue with it? I must confess after having switched over to the mobile app completely, and drop all other trackers, I havent seen an issue in location anymore.

Login is smooth as can be, local and external, and now we even have local notifications :wink:

Do you mean ā€œWhy do you dislike Mobile App integrationā€?

It is an off-topic here )))

Because sensors like ā€œbattery levelā€ are updating ONLY when I open the Companion App. I got iPad Air 2, iPhone 5S, iPhone 6S+ - all of them have ā€œBackground app refresh = ONā€ option in iOS settings but this does not help. And another issue is that Companion App is too buggy to be used. And one more issue is that iPhone 5S, 6S+ sometimes even cannot open a dashboard, just displaying a white screen. May be the latest iPad & iPhone work smooth.

ok, I see, and yes, its needs some more modern devices than my older iPad Air, on 12.5.5ā€¦ other than that, I think its really nice, and not buggy at all. but yep off-topicā€¦ sorry.

I might be running into an issue while using this auto-entities thingie. Iā€™m using it happily to display all my Shellyā€™s with an indicator whether or not a software upgrade is available. That works just fine. Since Shelly supports a button-type to OTA update the unit, I thought I might factor that in as a tap-action to these buttons.

The buttons look like this:
image
The code Iā€™m using for the button is as follows:

    filter:
      include:
        - entity_id: '*firmware_update*'
          options:
            type: custom:button-card
            template: status_button
            label: |
              [[[ entity.attributes.IP_Address ]]]
            icon: |
              [[[
                if (entity.state == "on") return 'mdi:update';
                else return 'mdi:check';
              ]]]
            show_icon: true
            show_state: false
            name: |
              [[[
                return entity.attributes.friendly_name.replace("firmware update","")
              ]]]
            show_name: true
            tap_action:
              action: call-service
              confirmation:
                text: |
                  [[[
                    return "Are you sure you want to upgrade " + entity.entity_id.replace("binary_sensor","button").replace("firmware","ota")
                  ]]]
              service: button.press
              service_data: {}
              target:
                entity_id: |
                  [[[
                    return '"' + entity.entity_id.replace("binary_sensor","button").replace("firmware","ota") + '"'
                  ]]]

Tapping to button to invoke the action displays the confirmation window just nicely with the entity_id of the shelly to be updated. However, it fails with:
image
Failed to call service button/press. must contain at least one of entity_id, device_id, area_id

If I separate the button from the auto-entities code, it works fine.

Is this per expectation?

Hi all,

Iā€™m using the exact config to only show the mediaplayers (different sonos devices) currently playing. BUT, and here comes the question, how do you give the options used by the entities in this type of card (auto-entities)

Question to be clear : How can I show the media_player AND the artwork in full-cover modus in above script ? artwork: full-cover ā† where to put it in the above script ?

Thanks a lot !

Kr,

Bart

Can someone help me to identify how to do this ? Adding attributes of the media_player into the auto-entities card ?.

I went a different way, and used conditional cards:

cards:
  - card:
      entity: media_player.portable_speaker
      type: media-control
    conditions:
      - entity: media_player.portable_speaker
        state_not: 'off'
      - entity: media_player.portable_speaker
        state_not: unavailable
    type: conditional
  - card:
      entity: media_player.study_speaker
      type: media-control
    conditions:
      - entity: media_player.study_speaker
        state_not: 'off'
      - entity: media_player.study_speaker
        state_not: unavailable
    type: conditional
  - card:
      entity: media_player.work_room
      type: media-control
    conditions:
      - entity: media_player.work_room
        state_not: 'off'
      - entity: media_player.work_room
        state_not: unavailable
    type: conditional
type: vertical-stack

But if you are using the default media_player card, there are no additional attributes? If you are using the media player entity, there are no additional attributes here either.

1 Like

hey all, im still dont understand how to code, but i do learn from examples
Id like to make the lights On into a Folder Entity??
where do i add this code

type: custom:fold-entity-row
      head:
        type: section
        label: Lights On
type: custom:layout-card
layout_type: masonry
layout: {}
cards:
  - type: custom:auto-entities
    card:
      type: entities
      title: Lights On
      state_color: true
      show_header_toggle: true
    filter:
      include:
        - options:
            secondary_info: last-changed
          state: 'on'
          domain: light
      exclude:
        - entity_id: '*group*'
    sort:
      method: entity_id
    card_mod: null
    style:
      .: |
        ha-card {
          border-radius: 10px;

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