Controlling RGB light with separate addresses

Hello,

I have twoo rgb strips over KNX. These strips have a different address per color. The knx implementation of RGB only seems to support RGB lights that have one address for all the colors.

Now i’m trying to fix this with a template and some scripts but the lack of documentation on anything keeps getting in the way.

The problem now is getting the value from the color selector card and parsing it from the template to the script.

the template in configuration.yaml

light:
  - platform: template
    lights:
      rgb_lights:
        color_template: "({{states('light.red') | int}}, {{states('light.green') | int}}, {{states('light.blue') | int}})"
        turn_on:
          service: script.rgb_light_on #works
        turn_off:
          service: script.rgb_light_off #works
        set_color:
          service: script.set_rgb_color #gives error
          data:
            rgb_value: "255, 11, 150" #want this to be a variable
            r_address: "6/1/1"
            g_address: "6/1/2"
            b_address: "6/1/3"

The script in scripts.yaml

rgb_light_on:
  sequence:
    - service: light.turn_on
      data:
        entity_id: light.red, light.green, light.blue
  mode: single
rgb_light_off:
  sequence:
    - service: light.turn_off
      data:
        entity_id: light.red, light.green, light.blue
  mode: single
set_rgb_color:
  sequence:
    - service: knx.send
      data:
        address: "{{ r_address }}" #works
        payload: "{{ rgb_value|regex_findall_index('\\d+\"',0)|int }}" #gives error. I tried index 1, same result
        type: "1byte_unsigned"
    - service: knx.send
      data:
        address: "{{ g_address }}" #works
        # "payload": rgb_value|regex_findall_index("\d+",1)|int 
        payload: 10 #works but want this as a parameter
        type: "1byte_unsigned"
    - service: knx.send
      data:
        address: "{{ b_address }}" #works
        # "payload": rgb_value|regex_findall_index("\d+",2)|int
        payload: 200 #works but want this as a parameter
        type: "1byte_unsigned"

The address parameters work fine (after an update, waisted 2 hours on that). The rgb_value gives the following error: “Error rendering data template: IndexError: list index out of range”

So i’m guessing that the regex does not have any matches or something, I don’t know.

There is something I want to fix before this and that is getting the actual RGB values from the light card. So right now these values are hard coded. What I want to know now is how do I get the RGB color from the light card when I select a color in the color wheel.

I hope that someone can help me with this.

Thanks!

Just specify index this way:

{{ rgb |regex_findall_index(find='\d+',index=0)|int }}

Change index to 0,1,2 for each one like you are.

If you want to use the color picker, you’ll have to use the default hue/saturation passed in {{h}}, {{s}} and convert those to a color. I’d follow some other example, like: Using HSV / HSB to set colored lights

thank you for your reply.

does it just return h and s? if I’m not mistaking I need a third value for brightness.

Is there a color wheel that uses RGB?

Yup. You can get the current brightness value from the light itself. set_color only deals with hs_color.

If your light doesn’t support set_level, then I guess you could just assume it’s full brightness in your calculation.

The issue is template_lights set_color command only do hue/saturation. Even if something else passes in rgb, I think it will get converted in the backend somewhere…