Getting 2 lights to match each others state

i have a light that i want to control with a remote. this remote cannot directly change the other light, so instead it appears to home assistant as its own light, and i need to apply the brightness and RGB values to the other light. i have figured out how to match the brightness, however, for the rgb colour, my sensor outputs a tuple, which my light cannot work with, and with the help of the discord server i got code to make the light accept a hex code string as the colour value, but i get told to “go build my own knowledge” when i asked how to get a string from the light.

this is the sensor:

  - platform: template
    sensors:
      brightness_fakepixel1:
        friendly_name: "Brightness Fake Pixel 1"
        value_template: '{{ states.light.fake_neopixel_1.attributes.brightness }}'
  - platform: template
    sensors:
      rgb_fakepixel1:
        friendly_name: "RGB Fake Pixel 1"
        value_template: '{{ states.light.fake_neopixel_1.attributes.rgb_color }}'

this is the automation:

  trigger:
  - entity_id: light.fake_neopixel_1
    platform: state
  condition: []
  action:
  - data_template:
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
      rgb_color:
          - '{{ (rgb_fakepixel1[0],rgb_fakepixel1[1])|join|int(0,16) }}'
          - '{{ (rgb_fakepixel1[2],rgb_fakepixel1[3])|join|int(0,16) }}'
          - '{{ (rgb_fakepixel1[4],rgb_fakepixel1[5])|join|int(0,16) }}'
      entity_id: light.table_light
    service: light.turn_on

someone from the discord server got back to me and said i could get a value from a tuple using [1] and [2], so now my code is

  action:
  - data_template:
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
      rgb_color:
            - '{{ states.sensor.rgb_fakepixel1.state[1] | int  }}'
            - '{{ states.sensor.rgb_fakepixel1.state[2] | int  }}'
            - '{{ states.sensor.rgb_fakepixel1.state[3] | int  }}'

this works without throwing up errors, but its a bit confused on the colours. for example, when the input is (0, 255, 63) , the output is (255, 255, 255). with an input of (63, 0, 255), the output is (255, 126, 0)

Don’t know if this helps:
Light groups

If Light Groups doesn’t solve your problem, please post the complete state of one of the lights from the Developer Tools / States screen, so we can see what we’re dealing with.

Like this, but for your light:

“The group light platform lets you combine multiple lights into one entity. All child lights of a light group can still be used as usual, but controlling the state of the grouped light will forward the command to each child light.” basicly, if i change one light in a group, the others dont follow. the group creates another light entity that controlls all the lights in the group, which acts as a normal light. i cant edit the values of a light the way i need them to, so a light group doesnt do anything for me.

as for the states:
top is input, bottom is output

To get the rgb_color numbers from the fakepixel light, you want:

{{ states.light.fake_neopixel_1.attributes.rgb_color[0] }}
{{ states.light.fake_neopixel_1.attributes.rgb_color[1] }}
{{ states.light.fake_neopixel_1.attributes.rgb_color[2] }}

Try these in Developer Tools / Templates to see what’s happening.

You have states.light.fake_neopixel_1.state which is either on or off; then states.light.fake_neopixel_1.attributes which is a dictionary of the brightness etc.

To access the three components of the rgb_color you need to count from 0, not 1.

thanks, that works.
i changed it from counting from 0 to counting from 1 because counting from 0 produced obviously wrong results. counting from 1 did not improve these results, so i just stuck with it.

but im confused, my sensor is reading the rgb values correctly, and im reading the values from the tuple correctly, arent i? why doesnt it work with my method then?

If you mean this:

{{ states.sensor.rgb_fakepixel1.state[1] | int  }}

you’re reading the second character from the state (“n” or “f”) and trying to convert it to an integer.

If you’re referring to a different bit of non-working code that you’d like to understand, post it and we’ll try to help.

that is the code that isnt working. it seems to return random values instead of tha values in the tuple, and i cannot understand why

From your screenshot, states.sensor.rgb_fakepixel1.state looks like it’s on or off, so you can’t go indexing that; it’s states.sensor.rgb_fakepixel1.attributes.rgb_color you need to be digging into.

The sensor reutrns correct values between 0 and 255, while states.sensor.rgb_fakepixel1.state returns incorrect values between 0 and 255. its not on or off

Apologies, I was getting mixed up between your lights (as in the screenshot) and sensors, it was a long day :crazy_face:.

If you still care, now it’s working as you want, can you screenshot the state of sensor.rgb_fakepixel1 as you did for the lights?