Template Group Recursion

Hi,

Would it be possible to create a jinja2 template that recurses through all groups associated with a specified group, and then list a particular entity type?

Example, I have a large hierarchy of groups as follows:

All -> Indoors -> Upstairs -> Bathroom
    |          |           |
    |          |           -> Bedroom
    |          |
    |          -> Downstairs -> Kitchen
    |                        |
    |                        -> Living Room
    -> Outdoors -> Porch
                |
                -> Garden

Entities will be linked to their lowest level group (i.e. Kitchen).

I would like to use a template which if I specified Upstairs, will list all entities (e.g. switches) of a given type and possibly of a given state.

Is this possible?

I’ve never experimented with nested groups but try this in the Template Editor and see what it reports:

{{ expand('group.upstairs') | map(attribute='entity_id') | list | join(', ')}}

If it lists all the entities you expected to see then we can add more filters to constrain it to a given state and/or type.

I think that might do the trick!

Thanks!