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.
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)
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.
“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.
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?
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