Dimmer script to only dimm lights that are on in a specific group not working

I’m trying to use a script to only dimm lights that are on in a specific light group.
I use ControllerX to dim up and down with a Philips Hue dimmer.
script is called with:

up_short_release: 
      - service: script.light_dimmer_up
        data:
          lightgroup: group.dimmer_test

script:

light_dimmer_up:
  description: increase light level when dim up button is pressed
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: >
          {{ expand( "{{ lightgroup }}" )| selectattr('state','eq','on') |
          map(attribute='entity_id') | list | join(', ') }}
      brightness_step_pct: 5
entity_id stays empty which results in the error:  not a valid value for dictionary value @ data['entity_id']
probably my syntax for the nested "lightgroup" variable isn't correct.

I can’t get it right :frowning:

Try changing the expand part to this:

{{ expand(lightgroup) | ....

And I think you can also leave out the join at the end as entity_id should accept a list.

1 Like

Thank you!! That was it. Sometimes it’s dead simple, but couldn’t get it right.
Working like a charm now.

You can’t nest templates. It’s as simple as that.

Even if nesting was permitted, there’s still no need for it here because lightgroup is a variable and will be evaluated as a variable by the outer set of braces.

1 Like

Can you please mark my post as the solution, so that others will quickly find the answer and the topic will be narked as solved.

Done. And again thanks for taking the time to help me out.

thanks for the explanation. Scripting isn’t my strongest skill :sweat_smile: