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

Thanks! You’re edit works for me now. I will edit my original reply

Many thanks for your work and the code. This seems to solve a long-term problem of mine. But unfortunately it doesn’t quite work yet… I can control the group with the template light, but it behaves in the same way as with the normal light group. if I switch off a lamp in the group and then dim the group via the template light/group, the lamp switches on again.

Am I missing something?

Here is my code:

light:
  - platform: template
    lights:
      template_lichtgruppe_arbeitszimmer:
        friendly_name: "Lichtgruppe Arbeitszimmer"
        level_template: >
          {% set group = 'light.arbeitszimmer' %}
          {{
            expand(group) 
              | selectattr('attributes.brightness', 'defined')
              | selectattr('attributes.brightness')
              | map(attribute='attributes.brightness')
              | list
              | default([0], true)
              | average
          }}
        value_template: "{{ is_state('light.arbeitszimmer', 'on') }}"
        turn_on:
          - service: light.turn_on
            target:
              entity_id: light.arbeitszimmer
        turn_off:
          - service: light.turn_off
            target:
              entity_id: light.arbeitszimmer
        set_level:
          - service: light.turn_on
            target:
              entity_id: >
                {% set group = 'light.arbeitszimmer' %}
                {{
                  expand(group) 
                    | selectattr('attributes.brightness', 'defined')
                    | selectattr('attributes.brightness')
                    | map(attribute='entity_id')
                    | list
                }}
            data:
              brightness: "{{ brightness }}"
1 Like

It only works with light groups created as helpers.
If you created the light groups in the configuration.yaml the template will not work and the lights will behave the same.

That’s not correct at all.

Light groups via the UI or yaml are identical. The above code will work with any group via the UI or yaml. It will also work with legacy groups.

The issue is this line

it needs to be removed

That line was intended to filter out none

That would be rejectattr('attributes.brightness', 'none').

Edit sorry on mobile

@petro Without passing a test, the input is tested as a boolean. So it will filter out the lights which are off

This works for me (simplified it a bit, as average accepts a default

          {% set group = 'light.groep_huis' %}
          {{
            expand(group) 
              | selectattr('attributes.brightness', 'defined')
              | selectattr('attributes.brightness')
              | map(attribute='attributes.brightness')
              | average(default=0)
          }}

Changed the version in post 4 as well

I used your code to make the same thing for color temperature and RGB color and it works nice!

Here is my code:

light:
  - platform: template
    lights:
      anton_lichtgruppe_final:
        friendly_name: "Lichtgruppe Anton"
        level_template: >
          {% set group = 'light.antonlicht' %}
          {{
            expand(group) 
              | selectattr('attributes.brightness', 'defined')
              | selectattr('attributes.brightness')
              | map(attribute='attributes.brightness')
              | list
              | default([0], true)
              | average
          }}
        value_template: "{{ is_state('light.antonlicht', 'on') }}"
        turn_on:
          - service: light.turn_on
            target:
              entity_id: light.antonlicht
        turn_off:
          - service: light.turn_off
            target:
              entity_id: light.antonlicht
        set_level:
          - service: light.turn_on
            target:
              entity_id: >
                {% set group = 'light.antonlicht' %}
                {{
                  expand(group) 
                    | selectattr('attributes.brightness', 'defined')
                    | selectattr('attributes.brightness')
                    | map(attribute='entity_id')
                    | list
                }}
            data:
              brightness: "{{ brightness }}"
        set_temperature:
          - service: light.turn_on
            target:
              entity_id: >
                {% set group = 'light.antonlicht' %}
                {{
                  expand(group) 
                    | selectattr('attributes.color_temp', 'defined')
                    | selectattr('attributes.color_temp')
                    | map(attribute='entity_id')
                    | list
                }}
            data:
              color_temp: "{{ color_temp }}"
        set_rgb:
          - service: light.turn_on
            target:
              entity_id: >
                {% set group = 'light.antonlicht' %}
                {{
                  expand(group) 
                    | selectattr('attributes.rgb_color','defined')
                    | selectattr('attributes.rgb_color')
                    | map(attribute='entity_id')
                    | list
                }}
            data:
              rgb_color: "{{[r,g,b] }}"

My issue now is that when the lights are in RGB mode and i want to change to color temp mode it doesnt do anything. If i change from Color temp to RGB it works

1 Like