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