Merge 3 separated RGB entity in 1 using template

Hi,
i have a RGB light wich is separated in 3 channels: red, entity , green and blue. I create a template to control it with the rgb wheel and it works fine but when i try to set the brightness level it regulate all channel with same level changing to color to white. Switching back to color wheel and selecting light change to right color ibut at full brightness.

Ho can i say to HA to regulate brightness only in the active color?
Here the code:

light:
    - platform: template
      lights:
        dysl30e58630342335_rgb:
            friendly_name: "Lampada TEST RGB"
            value_template: "{% if is_state('light.dysl30e58630342335_red', 'on')
                                or is_state('light.dysl30e58630342335_green', 'on')
                                or is_state('light.dysl30e58630342335_blue', 'on') %}
                                on {% else %} off {% endif %}"
            rgb_template: (
              {{ state_attr('light.dysl30e58630342335_red',   'brightness')|d(0,true)|int }},
              {{ state_attr('light.dysl30e58630342335_green', 'brightness')|d(0,true)|int }},
              {{ state_attr('light.dysl30e58630342335_blue',  'brightness')|d(0,true)|int }},
              )
            
             
            turn_on:
              service: light.turn_on
              entity_id: light.dysl30e58630342335_red, light.dysl30e58630342335_green, light.dysl30e58630342335_blue
            turn_off:
              service: light.turn_off
              entity_id: light.dysl30e58630342335_red, light.dysl30e58630342335_green, light.dysl30e58630342335_blue
            
            set_level:
                action: light.turn_on
                entity_id: light.dysl30e58630342335_red, light.dysl30e58630342335_green, light.dysl30e58630342335_blue
                data:
                    brightness: "{{ brightness }}"
            
            set_rgb:
                - service: light.turn_on
                  entity_id: light.dysl30e58630342335_red
                  data:
                    brightness: "{{ r }}"
                - service: light.turn_on
                  entity_id: light.dysl30e58630342335_green
                  data:
                    brightness: "{{ g }}"
                - service: light.turn_on
                  entity_id: light.dysl30e58630342335_blue
                  data:
                    brightness: "{{ b }}"

HA has no notion of an “active” color, and you explicitly set all color component to the same brightness/hue in set_level