This right here is telling you what you need to change. According to the docs, rgb_color requires a list of integers. It’s saying that you gave it a string ‘245, 245, 245’. Essentially this:
‘245, 245, 245’
vs
[ 245, 245, 245 ]
This right here is telling you what you need to change. According to the docs, rgb_color requires a list of integers. It’s saying that you gave it a string ‘245, 245, 245’. Essentially this:
‘245, 245, 245’
vs
[ 245, 245, 245 ]
Sorry, I wasn’t clear. The above error is the OP’s. I’m trying to change the xy_color depending on the sensor.met_office_temperature. I’ve been following this thread, this one and this one, and trying to get it to work.
Here’s my current error
Invalid service data for light.turn_on: None for dictionary value @ data['xy_color']. Got '[0.4949,0.4202]'
and this is the automation
- id: test
alias: test
trigger:
platform: time
at: '10:00:00'
action:
service: light.turn_on
data_template:
entity_id: light.kitchen_strip
brightness: 200
xy_color: >
{% if states.sensor.met_office_temperature.state|int >=10 %}
[{{0.2309|float}},{{0.2889|float}}]
{% elif states.sensor.met_office_temperature.state|int <= 2 %}
[{{0.3542|float}},{{0.362|float}}]
{% else %}
[{{0.4949|float}},{{0.4202|float}}]
{% endif %}
floats are redundant and that jinja looks odd. You don’t need {{}} unless you are pulling the information from a variable. Because you are setting the lights directly, you should only need the number. You don’t even need to convert it to a float because you have a decimal place.
Personally, I’m starting to think that value templates don’t work for lists.
Anyways, try this out:
- id: test
alias: test
trigger:
platform: time
at: '10:00:00'
action:
service: light.turn_on
data_template:
entity_id: light.kitchen_strip
brightness: 200
xy_color: >
{% if states.sensor.met_office_temperature.state|int >=10 %}
[ 0.2309, 0.2889 ]
{% elif states.sensor.met_office_temperature.state|int <= 2 %}
[ 0.3542, 0.362 ]
{% else %}
[ 0.4949, 0.4202 ]
{% endif %}
Thank you for the reply, and your suggested yaml. The reason I tried floats and excessive {{}}'s was due to this post and this one. I don’t think I can use int as xy_color are decimals, so I tried floats.
Unfortunately, this is the log when I try your suggestion, so I think you might be right.
Invalid service data for light.turn_on: None for dictionary value @ data['xy_color']. Got '[ 0.4949, 0.4202 ]'
Maybe I need to do it like
{% if states.sensor.met_office_temperature.state|int >=10 %}
{% set x as 0.2309 set y as 0.2889 %}
{% elif states.sensor.met_office_temperature.state|int <= 2 %}
{% set x as 0.3542 set y as 0.362 %}
{% else %}
{% set x as 0.4949 set y as 0.4202 %}
{% endif %}
['{{x|float}}','{{y|float}}']
???
you don’t want the quotes if you were to try that. quotes turn items into a string. It’s expecting floats. The issue is that it doesn’t see that item as a dictionary value. I don’t think templates support lists, so all this is a lost cause. You’re better off creating the 3 automations.
{% if states.sensor.met_office_temperature.state|int >=10 %}
{% set l = [0.2309, 0.2889] %}
{% elif states.sensor.met_office_temperature.state|int <= 2 %}
{% set l = [0.3542, 0.362] %}
{% else %}
{% set l = [0.4949, 0.4202] %}
{% endif %}
{%- for v in l -%}
{{ v }}
{%- endfor -%}
Just try this… make sure the for loop has the {%- and -%}. You don’t need it on the {{ v }}.