Best way to dim/brighten a light group by holding in a button on a remote?

I’ve been trying to get a IKEA square remote which is connected through the ZHA integration and my Conbee 2 to dim/brighten a light group by holding in either the 0 or 1 button. I got a script on from a guy that I’ve modified a bit to my needs but its not working so good i think. The individual lights in the group iit dims/brigthens does not follow each other in their brightness level. Heres my automation which calls a script:

- id: ikea_remote_dim_function
  alias: IKEA Remotes Dæmpnings automatik
  mode: restart
  - event_type: zha_event
    platform: event
  - service: script.zha_ikea_square_dim_exec
      dim_step: 30
      light: >-
      {% set device_light_list = {
        '00:0d:6f:ff:fe:d0:a1:20': 'light.spisekokken_group'
      } %} 
      {{ device_light_list[] }}"
      args: '{{ }}'
      command: '{{ }}'

And heres the script(s) called:

        - service_template: >-
            {%- if 'move' in command %}
            {%- endif %}
            light: "{{ light }}"
            dim_step: >-
              {% if command == 'move' %}
                {{ 0 - dim_step }}
              {% else %}
                {{ dim_step }}
              {% endif %}

    - repeat:
        while: []
          - service: light.turn_on
              entity_id: "{{ light }}"
              brightness: >-
                {% set ds = dim_step | int %}
                {%- if ds < 0 %}
                  {{ [ state_attr(light, 'brightness') + ds, 1 ] | max }}
                {%- else %}
                  {{ [ state_attr(light, 'brightness') + ds, 254 ] | min }}
                {%- endif %}
              transition: 0.1
          - delay:
              milliseconds: 400

It actually does “work” just not good enough for the WAF (Wife approval factor).

Anyone have some other way of making a IKEA Square remote dim/brighten a light group on long press ?

This cookbook entry is a little outdated with the new brightness_step options, but the basic principle you’re working with here (and in there) is good.

However, if that’s a group of lights, maybe you’ll need to start by setting them all to the same brightness first?

Not sure. Even if i run it with all the lights set at the same brightness level they will still not be following each other. With the way I’m doing it, its like sometimes a single light source in the group skips a “step” which makes it out of sync.

Then, pick a master light and explicitly set the levels of the others to match.

By that you mean it should brighten/dim one light, and once i release the button it would set the other light(s) accordingly ?

No, I mean pick one light and make it the “primary”. Set the brightness of that, and then set all other lights to match.

You have to do that, the system won’t