WTH can't light groups only dim lights that are on Hue-style

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.

Would this ultimately be a feature similar to what was mentioned here? Brightness control of groups - Month of “What the heck?!” - Home Assistant Community (home-assistant.io)

1 Like

I started a technical discussion / some development prototypes on this.

See: Add `light.adjust` service call · Discussion #537 · home-assistant/architecture · GitHub

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 }}"
2 Likes

Thanks.

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 :stuck_out_tongue:

1 Like

Brother please do not be annoyed. How do I add this to a fresh install of Home assistant?
My light group is light.store_room

place the code above in configuration.yaml and replace all the references to light.groep_speelhoek to light.store_room.

I do see I made some errors, everytime light.speelhoek was mentioned this should be light.groep_speelhoek

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?

That’s only possible on template lights if you define the fields that produce color for the template light

set_color and color_template

You’d have to do the same for white value or temperature too (if you want those)

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?

EDIT: I followed the code provided here https://www.home-assistant.io/integrations/light.template/ and added color_template and set_color but the icon’s color still doesn’t change

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?

Can you post your configuration for the template light?

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 }}"

Check the documentation for the template light

You need to use temperature_template and set_temperature in a similar way as I used level_template and set_level

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.

1 Like

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)

That won’t work if there are lights in your group which don’t support brightness, if that’s the case you still need to check if it’s defined.

I’ve changed my version

1 Like