My takeaway from our exchanges so far was that light groups wonāt work for this because I need to get a list of all the lights that are not part of any group, except the light.presence_simulation
group, which is only possible via templates.
So what I currently have is this:
# Define list of all groups, whose members should be excluded from the list of ungrouped lights
{% set groups = (states.light
| selectattr('attributes.entity_id','defined')
| rejectattr('entity_id', 'eq', 'light.presence_simulation')
| map(attribute='entity_id')
|list) + (states.light
| selectattr('entity_id', 'search', '.*\.group_.*')
| map(attribute='entity_id')
| list
) | list
%}
# expand group to get the actual members
{% set members = groups | expand
| map(attribute='entity_id')
| list
%}
# from this list also exclude a couple of members due to my specific setup
{% set individualLights = states.light
| rejectattr('entity_id', 'in', label_entities('exclude'))
| rejectattr('entity_id', 'in', area_entities('System'))
| map(attribute='entity_id')
| reject('in', groups +members)
| list
%}
[
{% for e in individualLights %}
{
"type": "custom:decluttering-card",
"template": "illumination_light-card-single",
"variables": {
" - Light": "{{ e }}" },
},
{% endfor %}
]
This is basically an adaptation of what youāve posted from @TheFes - thanks!
Iāve also tried to put this exact list into its own sensor to clean up the code, but that just adds unnecessary complication, so currently Iām working with the full code above.
The output of this in the template tester is the following:
But something is offā¦ as soon as I put it into an actual template filter, this is the resulting card:
code of auto-entities card
type: custom:mod-card
card_mod:
style:
hui-grid-card $: |
#root {
grid-template-columns: 1fr !important;
}
card:
type: custom:auto-entities
card:
type: grid
square: false
card_param: cards
show_empty: false
filter:
template: |
{% set groups = (states.light
| selectattr('attributes.entity_id','defined')
| rejectattr('entity_id', 'eq', 'light.presence_simulation')
| map(attribute='entity_id')
|list) + (states.light
| selectattr('entity_id', 'search', '.*\.group_.*')
| map(attribute='entity_id')
| list
) | list
%}
{% set members = groups | expand
| map(attribute='entity_id')
| list
%}
{% set individualLights = states.light
| rejectattr('entity_id', 'in', label_entities('exclude'))
| rejectattr('entity_id', 'in', area_entities('System'))
| map(attribute='entity_id')
| reject('in', groups +members)
| list
%}
[
{% for e in individualLights %}
{
"type": "custom:decluttering-card",
"template": "illumination_light-card-single",
"variables": {
" - Light": "{{ e }}" },
},
{% endfor %}
]
include: []
exclude: []
Result:
- It finds the correct entities that should be displayed
- YAML seems to be written almos correctly, theres just the quotes around the
- Light
and the indentation seems to be a bit off.
Iāve also tried switching the quotes up a bit:
[
{% for e in individualLights %}
{
"type": "custom:decluttering-card",
"template": "illumination_light-card-single",
"variables": {
' - Light': {{ e }} },
},
{% endfor %}
]
but this messes it up completely, as now every line gets rendered as an individual entity:
Do you have any idea how to fix this?