Expand light group not possible?

trying to simplify some scripts and automation, which now verbosely list several light entities more than once like this:

      service: light.turn_on
        entity_id: >

I was hoping to be able to do this with a made light group:

      service: light.turn_on
        entity_id: >

however the above merely returns the light.party_lights as entity_id…

while eg this


does randomly pick an entity from the group.

is this a bug, or by design (and would make the above require a true group after all)?
thanks if you could have a look.

The light group platform creates a light entity. You can’t expand an entity.

Yes you will have to use a standard group.

yes, thought as much, not sure if this is a pity or not… thanks anyways.

It might not have been possible then, but it sure is now

expand(state_attr('light.woonkamer', 'entity_id'))|map(attribute='entity_id')|list

That’s nice! Some time ago since I checked this, but I completely missed this change in the use of light groups.
Thanks for the nudge!

on further inspection: my config above and hence the conclusion still stands. We can not expand the light group itself:


Changing it to the format you provide solves that:

{{expand(state_attr('light.library_lights', 'entity_id'))|map(attribute='entity_id')|list}}

and probably has been available before, only we didnt think to try it… ?

anyways, might be a nice addition to the light group docs

@petro and @123 , please have a look here, has this been there all the time? seems quite an important feature in the templating tools we overlooked (so hence my tag, please don’t get mad)

I’m not mad but I haven’t been participating in this thread because I have little interest in the Light Group integration.

I have used expand extensively (its documentation seems adequate) but I have never used it with a Light Group, primarily because I don’t use Light Groups.

Maybe the example should be added to expand’s documentation?

yes, thats a fine idea too, I do think it is not known to a wider public here.

entity_id has existed from day one on light groups

1 Like

well, I hadn’t noticed a change in the integration either, so probably yes…
However, nobody realized we could use the expand() on them in light groups… so the fact we can using entity_id is still very useful information. Must say I don’t understand the inner workings though, as I’ve only seen it being used on groups

expand turns a list of entity_ids, an entity_id, or a group into state objects.

You inspired me to search through all my posts where I had offered examples for the use of the expand function. The majority of them expand groups but a few expand a comma-delimited entities:

and a recent post expanded the entities attribute of a Light Group:

As mentioned, the documentation is good; it includes examples of expanding a mix of entities and groups. Perhaps I was more familiar with its abilities because I had created a Feature Request and then followed the PR that implemented it very closely (thank you Tho85). FWIW, it was a difficult nut to crack; it took about three versions before it worked correctly. During its long gestation, I saw the developer’s examples for its usage.

1 Like

yes, I followed most of that, but admit having missed the expand on entities of the light group. I feel the documentation could benefit from an example how to iterate these using expand(), bot in the expand explanation in templates, and in the light.group docs though. Something like:

The entities configured in the light group are listed in the attribute entity_id which allows to iterate these entities in a Jinja template like using the expand() function on the light group:

{{ expand(state_attr('light.first_floor', 'entity_id')) | selectattr('state','eq','off') | map(attribute='entity_id') | join(',') }}

Since you have made a lot of effort in the expand() development, would you care to do that? If not, I would gladly do so.

It wasn’t until now, that I even realized entity_id was an attribute of the light.group. If I had seen that, I wouldn’t have posted this thread.

Put it in the expand section in templating, not light group. Also, I would phrase it in a way that shows you can grab any entity_id list as an attribute for the expand function, using light group as an example.