Use `expand` on a value set from a target selector

Reading and participating in this discussion made me realize how challenging it is to use an input or parameter set using a target selector in a template. It works great if you want to just use it directly in a service call but if you want to filter some of the entities out things get difficult quickly.

It would be great if expand worked on this object. So you could simply expand it into a list of entities like a group and not have to separately deal with entities, devices and areas in the same complex template.

I ran into this recently while writing a blueprint - I wanted to provide the flexibility of a target selector, but I also wanted to be able to do some scripting where I check the state of the matched entities. (In my particular case, I wanted to check if any of the target lights were on in color temperature mode)

I don’t think it would make sense to overload the expand filter for this; that filter is explicitly for expanding groups. Instead some new filters should probably be provided for this use case. Here’s what I’m thinking of:

I don’t have a use case for it, but it might also make sense to have target_devices and target_areas filters too, which work analogously.

2 Likes

In the meantime…

this assumes you’re including your target via lights: !include lights and translates it into a list of entities.