I have multiple lights in my living room that are in a light group. Sometimes I want to change color or brightness of all the lights that are currently on. When I use the group to modify the lights, ALL the lights in that group turn on. I don’t want that - lights in the group that are off should remain so, and only the ones that are on should change color or brightness. Is there any way to achieve that?
One way would be to use a filter that expands the group and only selects those lights that are currently on:
entity_id: >-
{{ expand('light.my_light_group')
| selectattr('state' ,'eq' ,'on')
| map(attribute='entity_id')
| list }}
Thanks for pointing me in the right direction. Here’s my solution.
First, I created a light group containing all the lights I wanted to be able to control and named it ALL_LIGHTS.
Then, I created this automation:
alias: Expand light group
trigger:
- platform: state
entity_id:
- light.smart_bulb_1
- platform: state
entity_id:
- light.smart_bulb_2
- platform: state
entity_id:
- light.smart_bulb_3
- platform: state
entity_id:
- light.smart_bulb_4
action:
- service: group.set
data:
object_id: active_lights
entities: |-
{{ expand('light.all_lights')
| selectattr('state' ,'eq' ,'on')
| map(attribute='entity_id')
| list }}
mode: queued
max: 10
This creates a group called group.active_lights. I can put this on my dashboard and it allows me to control color and brightness of all the lights that are on, restricted to those within the group ALL_LIGHTS, which is exactly what I wanted.
A note on the triggers. First I tried to use a state trigger that only watches for changes in the state of all_lights, but obviously this doesn’t work because the state only changes from off to on when one of the lights in the group is turned on. It doesn’t change when you turn on more lights, so this is not a sufficient trigger to update the dynamic group every time an additional light is turned on. I’m sure there’s a more elegant solution, but for now it works fine.
This method works fine on things like more-info but not with sliders I am afraid. The tile card or mushroom light card requires a light entity not a group entity. Only group options that is accepted are the ones made from the helpers section. I was planing to use this with a light slider but I guess it is not possible within Home Assistant.