🔹 Auto-entities - Automatically fill cards with entities

You could much easier use:

{{ (states.light | selectattr('state','eq','on') | map(attribute='entity_id')) | list}} 

The template posted above would return a string. This returns a list

Breaking that one line down …
Give me all lights
Whose state attribute is ‘on’
Grab the attribute entity_id for each
Put them into a list

Do yourselff a debugging favor and take your template and put it into developer tools, you would see this:

One long string in auto-entities will yield nothing and that is what you got, no entries.

To get the number on the button, you would just use:

{{ (states.light | selectattr('state','eq','on') | map(attribute='entity_id')) | list | count}} 

But if all you want is a list of names of the lights that are on in the popup, it is not clear why you are even using auto-entities. Just stick them into a markdown card like:

content: |
{% set lightson = (states.light | selectattr('state','eq','on') | map(attribute='entity_id')) | list %}
{% for light in lightson -%}
  {{ state_attr(light,'friendly_name') }}
{% endfor %}

You state:

Aim: I want a button card showing the current number of lights on.
When clicking on the button, a popup should appear and show the lights which are on.

Then you have no need at all for auto-entities. Just use a markdown card and style it as you wish.
Unless you intention is to control the lights, then auto-entities does apply and you could create buttons or whatever using the list of entities.

And after all that, if you really only want light domain entities that are “on”, why even use template filter at all? This gives a grid of all entities (lights and switches) that are on … excluding the ones that I do not want to show (filter is domain “light” and state “on” … no need for a template at all):

type: custom:stack-in-card
mode: vertical
cards:
  - type: custom:auto-entities
    card:
      title: Currently On
      type: grid
      columns: 1
      square: false
    card_param: cards
    filter:
      include:
        - domain: light
          state: 'on'
          options:
            state_color: true
            type: custom:mushroom-light-card
            show_brightness_control: true
            layout: horizontal
            fill_container: true
            show_color_temp_control: true
            card_mod:
              style: |
                ha-card {
                    box-shadow: none;
                }
        - domain: switch
          state: 'on'
          options:
            state_color: true
            type: custom:mushroom-light-card
            card_mod:
              style: |
                ha-card {
                    box-shadow: none;
                }
      exclude:
        - name 1: '*LEDs*'
        - area: Internet
        - name 2: Keypad*
        - name 3: FanLinc*
        - name 4: '*shuffle switch'
        - name 5: Deck TV*
        - name 6: '*normalization*'
        - name 7: Home Assistant*
        - name 8: '*Roborock*'
    show_empty: true

image

1 Like

Can anyone suggest how to replace the friendly name of listed entities by something else, e.g. a regex or the room name?

With the following the list has “Bedroom Aqara Temperature Sensor Humidity” and “Bathroom Upstairs Govee Sensor Humidity”, and I’d only want to see “Bedroom” or “Bathroom Upstairs” in the list:

type: custom:auto-entities
card:
  type: entities
  title: High humidity
filter:
  include:
    - entity_id: sensor.*_humidity
      state: '>=60'
sort:
  method: state
  numeric: true
  reverse: true

Thanks!

Replacing names dynamically may only be achieved by up using the “template” option.
Check here for mass-renaming.

I currently have this code to show Mushroom card updates.

type: custom:auto-entities
filter:
  include:
    - domain: update
      state: 'on'
      options:
        type: custom:mushroom-template-card
        primary: |
          {{state_attr(entity,'friendly_name')}}
        secondary: |
          {{ state_attr(entity, 'installed_version')}} → {{ state_attr(entity,
          'latest_version')}}
        icon: mdi:package-variant-closed-plus
        icon_color: orange
        tap_action:
          action: more-info
        card_mod:
          style: |
            ha-card {
              --secondary-text-color: white;
            }
    - domain: update
      state: 'on'
      options:
        type: custom:mushroom-update-card
        show_buttons_control: true
        primary_info: none
        secondary_info: none
        icon_type: none
sort:
  method: friendly_name
card_param: cards
card:
  square: false
  type: grid
  columns: 2

The result is:
image

But I wish to have something like this instead:
image

The code I tried, but doesn’t work is this:

type: custom:auto-entities
filter:
  include:
    - domain: update
      state: 'on'
      options:
        type: custom:stack-in-card
        mode: horizontal
        cards:
          - type: custom:mushroom-template-card
            primary: |
              {{state_attr(entity,'friendly_name')}}
            secondary: >
              {{ state_attr(entity, 'installed_version')}} → {{
              state_attr(entity, 'latest_version')}}
            icon: mdi:package-variant-closed-plus
            icon_color: orange
            tap_action:
              action: more-info
            card_mod:
              style: |
                ha-card {
                  --secondary-text-color: white;
                }
          - type: custom:mushroom-update-card
            show_buttons_control: true
            primary_info: none
            secondary_info: none
            icon_type: none
sort:
  method: friendly_name
card_param: cards
card:
  type: vertical-stack

It it possible to use stack within a stack somehow? Or anything to get similar look as in second image?

Thanks!

EDIT: I managed to resolve my issue with card-mod

Hi all!

Is there a way to hide the state of the individual entities that appear on the card?

Context: I am trying to make a list of all “Alert” scripts that are active, but I don’t want the user to see the “RUN / CANCEL” button that appears next to the scripts on the card.

Is there a way to hide it somehow?
image

  1. Hide a state / button part by card-mod.
  2. Show as a simple-entity type.

Thanks for the tips @Ildar_Gabdullin. How do I show a simple entity type?

2 Likes

Options for entities - type:

But I am not sure that this way is the best. It will not show a button - but it will show a useless state.
I would choose the card-mod way.

Can anyone suggest a way to display (de-duplicated) devices instead of entities?

I have a card where I want to display devices that have not been seen for a while which might be offline, using last_seen: > 30m ago , but I’d want to display devices instead of a long list of entities belonging to these devices.

Is there a way to a) get the device friendly name from an entity, b) remove duplicates from that list and c) display these device names as e.g. entities card, preferrably with last-updated as the info displayed to the right of each name?

Thanks!

How can you say if some device is offline?

As mentioned, I filter entities by last_seen: > 30m ago and want to convert a (long) list of entities to a (shorter) list of devices these entities belong to.

None of cards show a DEVICE. But you may try to get a device name for some entities belonging to some devices and then print these names in Markdown. How to get a device name - reed docs for Templating.

Maybe someone else has an idea how to use auto-entities to display the (deduplicated) device names.

So, getting a device name from an entity is easy.

{{ device_attr(entity, 'name_by_user') if device_attr(entity, 'name_by_user') else device_attr(entity, 'name') }}

If you named the device, this gives that otherwise, it gives the device name given by HA. But, for devices not named by you, the ‘name’ seems to be the same for the same make and model.

For example, all of my zigbee door sensors are called ‘LUMI lumi.sensor_magnet.aq2’ if not named. So, if you have two of them that are not named, they would be grouped together. So, you need to use ‘id’ for uniqueness.

Now, to get unique by id. This is specifically all of my zigbee entities.

{%- set ns = namespace(devices=[]) -%}
{%- for entity in integration_entities('zha') -%}
  {%- set ns.devices = ns.devices + [{"device_id": device_attr(entity, 'id'), "device_name": device_attr(entity, 'name_by_user') if device_attr(entity, 'name_by_user') else device_attr(entity, 'name'), "area_id": device_attr(entity, 'area_id')}] -%}
{%- endfor -%}
{%- for device in ns.devices|unique(attribute="device_id") %}
{{ device }}
{%- endfor -%}

I added ‘area_id’ to help differentiate devices that are not named by you.

But, you don’t really need these attributes here. You could just use the ‘id’ and in the second loop, use that ‘id’ to get any attributes you need for your output using device_attr.

What I don’t understand is where you are going to get ‘last_seen’. Also, know that auto_entities expects entities. Not devices. So, you’d probably need to do this in markdown anyway.

Thanks a lot, that helps – at least I hope it does. I’ve named all devices, so that’s not an issue, but it’s great that you also added the id.

There’s a thread from December 2022 where someone is trying to use auto-entities to list unavailable devices. He got rather far, but didn’t solve all issues. But at least he listed devices in the auto_entities entities card layout.

As for my naïve attempt, I thought I’d filter all entities for last_seen: > 30m ago and store their last-updated info, then replace all entity names with device_attr(entity, 'name_by_user'), remove duplicates from the list and use that list to feed the auto-entities list, which could then even sort by last-updated.

The goal behind this effort is to keep track of (passive) devices that might have a bad connection and therefore most of the updates they broadcast don’t make it to the server. I would then know where I should add another thread/zigbee router or change some placement – or replace a battery, even if it’s at 100%.

Again:

  • auto-entities cannot show devices since none card can show it (all cards - except markdown & stacks - are associated with some entity, not a device)
  • use Markdown and HA templating to generate a list of devices, assoc with entties which last-change>xxxx
1 Like

In the thread you mention they are using a sensor to create a list of unavailable ‘entities’ out of devices.

You cannot do it straight from devices as discussed here like @Ildar_Gabdullin has posted.

So, what I have discussed above would go into the sensor. Then, use the sensor in the auto_entities.

I am unsure of why they wanted to put ‘unavailable’ like a status in a list of unavailable devices. They are all unavailable.

Also, use this in Developer Tools | Template and see that, at least in my zha devices, there are not ‘last-updated’ attributes.

Certainly play with others and see what you can find. You might need to look for unavailable like in the post you linked. Not sure you will get the > 30 minutes without a crapload of timers. Just saying:

{%- for entity in integration_entities('zha') %}
{{ entity }}
  {%- for attr in states[entity].attributes %}
  {{ attr }}-{{ state_attr(entity, attr) }}
  {%- endfor -%}
{%- endfor -%}

Any chance you could share your final code? I love where you have gone with this

Hi, I like your auto-entities card a lot. Is there a way to get tap_action : toggle working? That would improve usability a lot imho.