Hi, I’m trying to use templates to ‘copy’ light states. In this case I want to copy light.bank to light.televisie
I have it working for brightness and color_temp, but not for color
What I have so far is:
the xy_color template returns for example: [0.5017, 0.4152], but in the log i have the following error:
17-02-27 16:25:09 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data['xy_color']. Got '[0.5017, 0.4152]'
Hey I think the problem here is that Jinja renders the whole thing as a string. So you only get the string “[0.5017, 0.4152]” but not the actual list. You could try to seperate x and y and put those there like that e.g.
Unfortunately there are no attributes like x_color and y_color.
However i tried the following because it is essentially the same i think
xy_color: '[{{states.light.bank.attributes.xy_color | first}},{{states.light.bank.attributes.xy_color | last }}]'
returns the same error:
17-02-27 21:09:30 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data['xy_color']. Got '[0.5017, 0.4152]'
As you show, templates require quotes. And that might be part of why HASS is seeing a string. But I wonder if some alternate methods of expressing the data might work.
Like
xy_color: >-
[{{states.light.bank.attributes.xy_color | first}},{{states.light.bank.attributes.xy_color | last }}]
or
xy_color:
- {{states.light.bank.attributes.xy_color | first}}
- {{states.light.bank.attributes.xy_color | last }}
quotes should only be around the template values which are also converted to floats
I guess the same should work for rgb_color but instead of using float, you use int.
For future reference you can use the template editor (http://(your ip):8123/dev-template) when working to see if your template works, hopefully you knew about that . Then for syntax questions you can always google to find answers for jinja.
Not just directed at you btw, just for anyone reading.
I knew that, but the problem wasn’t that the template did not work, it was in an incorrect format for the service using it. (string instead of a list of floats)
Thanks for posting the solution. You can also mark it as such for future reference if someone else is struggeling with this. Makes it easiert to find it