When you dim a light group there some lights are on and some off, all lights turn on and them dim. This is understandable, but stupid.
This isn’t a major problem in automations, I can just check each light and dim them then, but then they don’t become the same brightness. I don’t know what Philips Hue’s rules are with dimming but they are perfect and the only reason I can’t get myself to migrate from the Hue bridge.
I actually created a template light to do just that for someone on Facebook yesterday
color_temp can be added as well, but that’s a bit more tricky as the min and max can vary between lights in the group
# Template light which uses a light group, but only adjust the brightness of the lights which are on
# Change object_id on line 8 and friendly_name on line 9
# Change all references to 'light.groep_speelhoek' to your own light group
light:
- platform: template
lights:
template_play_area:
friendly_name: "Template Play Area"
level_template: >
{% set group = 'light.groep_speelhoek' %}
{{
expand(group)
| selectattr('attributes.brightness', 'defined')
| selectattr('attributes.brightness')
| map(attribute='attributes.brightness')
| average(default=0)
}}
value_template: "{{ is_state('light.groep_speelhoek', 'on') }}"
turn_on:
- service: light.turn_on
target:
entity_id: light.groep_speelhoek
turn_off:
- service: light.turn_off
target:
entity_id: light.groep_speelhoek
set_level:
- variables:
group: light.groep_speelhoek
on_with_br: >
{{
expand(group)
| selectattr('attributes.brightness', 'defined')
| selectattr('attributes.brightness')
| map(attribute='entity_id')
| list
}}
- if: "{{ on_with_br | count > 0 or is_state(group, 'off') }}"
then:
- service: light.turn_on
target:
entity_id: "{{ on_with_br or group }}"
data:
brightness: "{{ brightness }}"
I’ve seen plenty of hacks / workarounds to this (though I must say yours is one of the nicer ones). Still it seems nuts that you have to program a page of yaml each time you want to work around this issue. Hence: WTH
Awesome solution! Works flawlessly!
I have a simple question. Is there a way for the icon on the dashboard to change color depending on the bulbs color?
Thank you very much for the immediate reply!
I am terribly sorry but I am not so advanced.
Would you be so kind as to show me where I should write these values? (I am not interested in white temperature) in the template above?
Thanks a lot for the solution @TheFes. Strangely I’m finding that when I change the brightness using this it still turns on any lights that were previously turned off. Any suggestions on how to debug this so I can try to adjust and make it work?
Thanks so much for the quick response. I figured it out. The issue was I was trying to control a group of lights that was from Hue. I created a group helper within HA that includes the lights and used that with your code and it works perfectly. Thanks again!
Thanks for posting. This does basically what I am looking for but when I use the brightness slider it bounces around before going to the selected brightness. Is it possible to add and remove lights from a group when they are turned on and off rather than compiling the list when the brightness is changed? I think this would have a smoother ui experience.
I have a group of lights that are rgb and cct…
The whole isse could be solved by dynamically adding members to the group but that isnt provided by home assistant… or adding such a feature into the group settings
This is a stupid problem. I think a fix would make alot of people happy
This post is really awesome. You mentioned using this for color_temp as well. Would you mind helping me out? I’ve tried this and it renders an error message "Failed to call service light/turn on. expected int for dictionary value @ data[‘color_temp’]
- platform: template
lights:
kontor_lampor_pa_temp:
friendly_name: "Kontor Lampor På Temperatur"
level_template: >
{% set group = 'light.kontor' %}
{{
expand(group)
| selectattr('attributes.color_temp', 'defined')
| map(attribute='attributes.color_temp')
| list
| default([0], true)
| average
}}
value_template: "{{ is_state('light.kontor', 'on') }}"
turn_on:
- service: light.turn_on
target:
entity_id: light.kontor
turn_off:
- service: light.turn_off
target:
entity_id: light.kontor
set_level:
- service: light.turn_on
target:
entity_id: >
{% set group = 'light.kontor' %}
{{
expand(group)
| selectattr('attributes.color_temp', 'defined')
| map(attribute='entity_id')
| list
}}
data:
color_temp: "{{ color_temp }}"
Thank you for the quick reply. I’m struggling to understand the templating. I feel that the documentation is a couple of levels above my understanding of yaml. I’ll give it a try again tomorrow as I find it better to understand it myself than be handed the answer.
EDIT: See updated template light from TheFes for best working version.
FYI if anyone is looking at this and its not working for them, I had to change the select line from the brightness entity to state as otherwise it would turn on all lights in the group (Wiz lights in a home assistant light group)