Template: filter list based on string

Hi.

I tried to wrap my head around this for a while now and am stuck.

What I want to achive is to call a service for all cover entities in the room (area) where a script was triggered by an Echo device.

I managed to get a list of all entities in the same room:

{{area_entities(area_id(states('sensor.letzter_echo')))}}

the result is a list, like:

['light.abc','sensor.efg','cover.xyz',...]

Now I want to apply a filter to the list, so that the list only includes cover entities. I would to that with a string comparison and a select filter, but don’t know how or if I need to go another direction (loop?).

The result should be something like:

service: cover.open_cover
target:
  entity_id: <my template with list of cover entities>

P.s.: I am aware that I can use the list unfiltered, but I’d like to do it in a clean way.

{{ area_entities(area_id('sensor.letzter_echo')) | select('match', 'cover') | list }}
1 Like

Thanks.
I still need the state of the sensor, as the entity_id is stored within the sensor. So this is the final solution:

{{ area_entities(area_id(states('sensor.letzter_echo'))) | select('match', 'cover') | list  }}

Do you have some kind of secret Jinja documentation? The match test is not in the official documentation…

it’s in the HA documentation :wink:

I had assumed it was a copy-paste error so that’s why I removed the states() function. However now I understand why you were using it. Is sensor.letzter_echo a Template Sensor or is it based on some other integration?

A template sensor that checks which Echo media player entity was last triggered.

It would be really nice to have one single templating documentation. A christmas wish for the man that has everything :wink:

So you want us to recreate the 100+ page jinja documentation every new release of jinja because you can’t be bothered to look in the link that we point to from the HA templating documentation?

1 Like

Don’t take everything so serious :wink:

1 Like