Pass json data into RGB color

OK, so I made a calibrated RGB sensor that sends back RGB data. Right now I have it set up as 3 separate sensors in HA. (Is there a way to combine them?)

I am able to read their values just fine and they show up on top of the page. They are 8-bit unsigned values from 0-255, to match the formatting desired by most color data sources.

Now, I want to set a hue light’s color based on these values.

Here is my attempt (I’m not sure how to do a code block

matchlights:
  alias: Match Lighting
  sequence:
    service: light.turn_on
    data:
      entity_id: light.office
      rgb_color: ['{{ sensor.red_sensor.state }}', '{{ sensor.green_sensor.state }}', '{{ sensor.blue_sensor.state }}']

As I expected, it doesn’t really like the formatting, but I’m not sure how it should be formatted. Online examples are of inserting a single data point, not an array of 3 data points.

First you need to use data_template not data. Second you need to make sure that those are int values.
Take a look here: Using template for xy_color

You config should look like this

matchlights:
  alias: Match Lighting
  sequence:
    service: light.turn_on
    data_template:
      entity_id: light.office
      rgb_color: ['{{ sensor.red_sensor.state | int }}', '{{ sensor.green_sensor.state | int}}', '{{ sensor.blue_sensor.state | int}}']
2 Likes

Excellent. I’ll give that a try real quick.

OK, it kinda went nuts on me with that one. 50 lines of error and the script apparently locked up.

“Error doing job: Task exception was never retrieved” seems to be the main error.

Edit:
Nevermind. It’s working now. Just needed to add “states.” in front of the values.

You’re a life saver. Thanks!

1 Like

Whoops didn’t notice that was missing my bad :smiley:

Thanks for confirming that it works now :slight_smile:

~Cheers