Pull color state from light

Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got ['(228,223,255)']

Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got ['(228,223,255)']

Basiclly the same error both times.

I know this is probably more of a JSON thing than a YAML thing, but its picky and complex formatting is the main thing I have against YAML.

I wonder if rgb_color needs to be separated into red, green, and blue.

If you look at the old version of mine, it basically would have resulted in [‘255’, ‘255’, ‘255’]

I tried doing replacement for swapping , with ', ’
But it didn’t look like it actually change anything.

I’m not sure if it passes the data as a string, or tries to pass its constituent parts, but it might be looking for [int,int,int] and we are giving it [‘string’]

jinja does not return lists. Getting this method to work will not be easy. Your best option is to piece out each item like you had before:

rgb_color: [ '{{ state_attr("light.rgb_sensor", "rgb_color")[0] }}',  '{{ state_attr("light.rgb_sensor", "rgb_color")[1] }}',  '{{ state_attr("light.rgb_sensor", "rgb_color")[2] }}' ]

This of course assumes that the state_attr returns a tuple or list. You may need to convert to a tuple or a list but I doubt it.

5 Likes

What is the output of your sensor in the template editor?

Also, you can use the template editor to test your templates before moving them into your YAML config file. It saves a lot of restarts. Most of the time if they work in the template tool they just copy/paste into the config file, exception is changing ‘quotes’ to “quotes” or visa versa.

Sure enough. That seems to have worked. I’ll try it on the rest of my lights.

matchlights:
  alias: Match Lighting
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: light.bedroom_up
        brightness: 128
        rgb_color: [ '{{ state_attr("light.rgb_sensor", "rgb_color")[0] }}',  '{{ state_attr("light.rgb_sensor", "rgb_color")[1] }}',  '{{ state_attr("light.rgb_sensor", "rgb_color")[2] }}' ]

Boy do I love C++ so much more.

I’ll post back when I verify on my other lights.

4 Likes

Jinja is limited in its functionality. It’s a language meant for displaying information so it always expects to output 1 value.

Yep, that seems to have done it!

Thanks guys!

Would still be killer if they used a scripting language like javascript or maybe some other markup language. I’m starting to make heavier use of the python script component as well. Madness.

2 Likes