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

To solve my own question, fixed it wuthin the template code like @Ildar_Gabdullin said, thanks!
Hereā€™s the code original code;

      - type: custom:auto-entities
        card:
          type: entities
        filter:
          include:
            - entity_id: "sensor.nl_trash_*"
              options:
                type: custom:multiple-entity-row
                secondary_info:
                  attribute: remaining
        sort:
          method: attribute
          attribute: remaining_int
          numeric: true

And using template with a divider;

      - type: custom:auto-entities
        card:
          type: entities
        filter:
          template: |-
            {% set trash = [
              states.sensor.nl_trash_gft,
              states.sensor.nl_trash_paper,
              states.sensor.nl_trash_pmd,
              states.sensor.nl_trash_residual] | sort(attribute='attributes.remaining_int') %}
            {%- for t in trash -%}
              {{
                {
                  'type': 'custom:multiple-entity-row',
                  'entity': t.entity_id,
                  'secondary_info': t.attributes.remaining
                }
              }},{%- if not loop.last -%}{{
                {
                  'type': 'divider'
                }
              }},
              {%- endif -%}
            {%- endfor %}

Looks like it canā€™t handle ā€œthis.entity_idā€.

Is it possible to use auto entities card to sort out devices created by a specific integration?

In Home Assistant, under Integrations, I can view all devices controlled by a specific integration (ā€œFiltering by integrationā€).

I would like to do this in using a auto entities-card but I donā€™t know what filter to use? Is it even possible?

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