Expand Template with both Area and Label

I would like to have a template that find all entities in an area with a particular label that are on.

Use Case: I have lights in the living room that are ambient lights and have the label ‘Ambient’ and a pendant light that has the label ‘Overhead’. However i also have a light in the office with the label ‘Overhead’. If the lights with the label ‘Ambient’ are on and the on button is pushed then the pendant light will turn on as well.

I’ve got this far, but it still returns all the Overhead lights.

 {{ area_entities('Living')
   and label_entities('Overhead') | select('is_state', 'on') | select('search', 'light\.') | list }}

Listens for:

This template listens for the following state changed events:

Entity: light.living_room_pendant
Entity: light.office_uplight
{{ area_entities('Living')
   |select('in', label_entities('Overhead'))
   |select('is_state', 'on')
   |select('search', 'light\.')
   |list }}

Alternative:

{{ set(area_entities('Living')).intersection(label_entities('Overhead'))
   |select('is_state', 'on')
   |select('search', 'light\.')
   |list }}
1 Like