Closed flinthamm closed 1 year ago
which works fine in Developer Tools Templates
Are you saying that your 1st example shows a list of entities in Dev tools?
Actually, it cannot - no map(attribute='entity_id')
.
Here is how to show a list of entity_ids:
{{states.light | selectattr('state', '==', 'on') | map(attribute='entity_id') | list}}
Here is how to show a list of entity_ids:
{{states.light | selectattr('state', '==', 'on') | map(attribute='entity_id') | list}}
Yes with adding the map filter it works fine in the Dev Tools. But the short version also does not work for me with the card.
The difference is, that the long example generates a plain comma separated list of entity_id's, where the short example generates a list where the entities are listed between square brackets []: Results Long:
Entity_id, entity_id,
Results short:
[
Entity_id,
entity_id
]
So the card fails to import the result of a list filter. This works for me:
filter:
template: "{{states.light | selectattr('state', '==', 'on') | map(attribute='entity_id') | join(', ')}}"
The doc example seems to be just wrong (or outdated). Spent an hour to end in the same situation. 🙄
Fixed by #298?
Home Assistant: 2022.6.6 Auto Entities: 1.11.0
The example at the bottom of README.md does not work in it's shorter template form? I'm simply trying to display a list of lights that are currently on and exlude groups, by using rejectattr which works fine in Developer Tools Templates. Something like:
template: "{{ states.light | rejectattr('attributes.hue_type', 'defined') | rejectattr('attributes.entity_id', 'defined') | selectattr('state', 'eq', 'on') | list }}"
However, even if I try the example from the bottom of the README (i.e. without the rejectattr filters) this fails to work too. Does anyone else have this experience or a solution please?
template: "{{states.light | selectattr('state', '==', 'on') | list}}"