🔹 Auto-entities - Automatically fill cards with entities

I have an (iOS) device integrated by the official HA Companion app. It provides a battery state sensor storing the Low Power Mode in an attribute.

I want auto-entities to show all entities with state Low Power Mode: true. Unfortunately, auto-entities seems to not being able to handle the “not so precise” naming of this attribute.

E. g. this is working for the default attribute within a normal entities card:

      - type: attribute
        entity: sensor.phone_battery_state
        attribute: 'Low Power Mode'

But with auto-entities nothing is displayed. Doesn’t matter how I write the Low Power Mode. Bug or am I using it wrong?

type: custom:auto-entities
card:
  type: entities
  title: Power Saving Mode
  state_color: true
  show_header_toggle: false
entities: []
filter:
  include:
    - domain: sensor
      attributes:
        device_class: battery
        'Low Power Mode': true
      options:
        secondary_info: last-updated
  exclude: null
show_empty: false
unique: true
sort:
  method: last_changed
  reverse: true

This is what dev tools gives me, so YES, the naming of that attribute is just horrible.

Low Power Mode: true
device_class: battery
icon: mdi:battery-40
friendly_name: Phone Battery State

Any ideas?
(How) Can auto-entities handle “not well formatted” attributes?

    type: custom:auto-entities
    card:
      type: entities
      title: Integration
    unique: true
    show_empty: true
    filter:
      template: '{{integration_entities("kodi") }}'
    sort:
      method: name

изображение

1 Like

I do not see this attribute in this sensor:

изображение

As for “Low Power Mode” attribute.
In my experience, if some attribute is displayed as “Xxx Yyy Zzz”, that means that it’s actual name is “xxx_yyy_zzz”.
But this particular “Mobile App” integration is smth strange…
Check these templates:

That means that you may address this attribute only by using the "Xxx Yyy Zzz" name.
Try using this template (just replace “false” with “true”):

filter:
  template: >-
    {% for sensor in integration_entities("mobile_app") -%}
    {%- if is_state_attr(sensor,"Low Power Mode",false) -%}
    {{sensor}},
    {%- endif -%}
    {%- endfor %}

изображение

I tried using “selectattr” filter - does not work:

    {{states | selectattr('attributes["Low Power Mode"]', 'eq', false) |
    map(attribute='entity_id') | list }}
    {{states | selectattr('attributes.low_power_mode', 'eq', false) |
    map(attribute='entity_id') | list }}

I asked a question about using the “selectattr” filter, you may follow that thread if you like.

trying to fighter compress the yaml, it would be nice if I could replace this filter:

          filter:
            include:
              - entity_id: '*.[[id]]_*'
            exclude:
              - entity_id: 'switch.[[id]]'
              - entity_id: 'sensor.[[id]]_actueel'
              - entity_id: 'sensor.[[id]]_totaal'
              - entity_id: '*daily'
              - entity_id: '*daystart'
              - entity_id: '*power'
              - entity_id: '*energy'
              - entity_id: '*door*'
              - entity_id: '*battery*'

with a regex search for the wild card strings GitHub - thomasloven/lovelace-auto-entities: 🔹Automatically populate the entities-list of lovelace cards

          filter:
            include:
              - entity_id: '*.[[id]]_*'
            exclude:
              - entity_id: 'switch.[[id]]'
              - entity_id: 'sensor.[[id]]_actueel'
              - entity_id: 'sensor.[[id]]_totaal'
              - entity_id: '/^(daily|daystart|power|energy|door|battery$/'

I tried this, but upon refreshing my system went down ;-)…

please could anyone help me out finding the correct syntax?

update
wait, this seems to work nicely:

            exclude:
              - entity_id: 'switch.[[id]]'
#              - entity_id: 'sensor.[[id]]_actueel'
#              - entity_id: 'sensor.[[id]]_totaal'
#              - entity_id: '*daily'
#              - entity_id: '*daystart'
#              - entity_id: '*power'
#              - entity_id: '*energy'
#              - entity_id: '*door*'
#              - entity_id: '*battery*'
              - entity_id: '/(actueel|totaal|daily|day|power|energy|door|battery|position|afstand)/'

only doesnt filter out things like showing ‘cv stookhok’ in search ‘stookhok’…

adding - entity_id: '*.cv_[[id]]*' somehow fixes ist, even on cv_stookhok entities . huh?

You’re right the device_class: battery was a custom setting, nothing the integration seems to provide as default.

Your template worked :+1: But:

  • basically I try to avoid using templates whereever possible
  • the state shown is the state of the entity, not the one of the attribute.

This is desired output (the entity name does not matter):
grafik

…achieved by entities card default attribute:

      - type: attribute
        entity: sensor.phone_battery_state
        attribute: Low Power Mode
        name: Energiesmarmodus

This is what I get in auto-entities using the template:
grafik

Another workaround needed?

Maybe auto-entities can “just” work around those “crazy” attributes? So that

      attributes:
        'Strange Attribute Naming': true

would be accepted AND the attribute’s state is shown.

  - type: custom:auto-entities
    card:
      type: entities
      title: Power Saving Mode
      state_color: true
      show_header_toggle: false
    entities: []
    filter:
      template: >-
        {% for sensor in integration_entities("mobile_app") -%}
        {%- if is_state_attr(sensor,"Low Power Mode",false) -%}
        {{
          {
            'type': 'attribute',
            'entity': sensor,
            'attribute': 'Low Power Mode',
            'name': 'xyz'
          }
        }},
        {%- endif -%}
        {%- endfor %}
    show_empty: false
    unique: true
    sort:
      method: last_changed
      reverse: true

изображение

Or this:

          {
            'type': 'attribute',
            'entity': sensor,
            'attribute': 'Low Power Mode',
            'name': state_attr(sensor,'friendly_name').split(' Battery')[0]
          }

изображение

We use templates in Configuration to create template sensors, why not using templates in Frontend?)))

I do not think this is supported…
Every attribute which I have seen is a kind of “xxx_yyy_zzz” - and is presented in UI as “Xxx Yyy Zzz” - let’s call these attributes NORMAL. These attributes from Mobile App are STRANGE (I would call them in Russian by another word - and the whole Mobile App integration is unstable and unreliable, IMHO).

2 Likes

Thank you VERY MUCH! The output is pretty much exactly what I was looking for. Think I need to start using templates in the UI to get even more out of whole HA.

I’m not brave enough to raise an issue for the mobile_app integration but I double what you said - that’s not a ‘normal’ naming convention and it’s from the official app… anyway, auto-entities is working for now :smiley:

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: ''