Error with templating. Need help

Hey guys, I am getting this error

TypeError: list indices must be integers, not str
17-01-25 21:52:47 homeassistant.core: Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got '33,12,255'

when i run this script.

    alias: "Keep kitchen on but change color"
      - service: light.turn_on
          rgb_color: >
            {% if is_state('light.television', 'on') %}
              {%set values = states.light.television.attributes.rgb_color %}
            {% endif %}

It’s telling me that it needs to be a integer and not a string but i’m lost at what to do.

if anyone could help me out that would be great.

Please use the preformatted option when posting your code; it helps others to see spacing and formatting correctly.

In your post editor, select the code block and press this button to use the preformatted text option:

Fixed. Thank you.

well, for the first error, that is pretty simple, you are using the service light.turn_off and you are trying to pass it an rgb_color, which it cannot take.

I think the only way to resolve that is to not try to template your services inside the script and instead template your call to a given script.

For the 2nd error, it looks like states.light.television.attributes.rgb_color returns (R, G, B) instead of [R, G, B] (I don’t have any light components, so I can’t confirm). You can get around this with some string formatting.

{%set values = states.light.television.attributes.rgb_color.strip('()').split(',') %}
1 Like

You helped me with the first error and almost the second. I updated the OP if you could help again.


I believe you can either use int(values[0]) or values[0]|int to cast from string to int.

Unfortunately I am still getting the “None for dictionary value @ data[‘rgb_color’]” error.

I don’t think you can programmatically access color settings in lights.