Hello everyone.
I’m trying to make a template light for my zigbee RGBW dimmer which z2m recognizes as RGBCCT.
Essentially what I want to do is visible from my yaml where I tried to do it.
I want to set kelvins for white when selecting white on RGB wheel and set hs_color when choosing anything else.
set_color:
service: light.turn_on
target:
entity_id: light.rgbw_dimmer
data: >-
{% if "{{ h }}" == 0 and "{{ s }}" | float(0.392) %}
kelvin: 2000
{% else %}
hs_color:
- "{{ hs[0] }}"
- "{{ hs[1] }}"
{% endif %}
Is this logic possible? Because as a response I get:
Failed to call service light.turn_on. Error rendering data template: Result is not a Dictionary
You can’t nest templates inside templates, you just use the variables by themselves.
You can’t use templates to build yaml the way your example is trying to do.
The main issue I see is the if statement. Where are the values for h and s coming from?
What are you trying to do with the second clause of your if, s | float(0.392)… is there supposed to be a > or < in there?
This is untested, but you might be able to do it like (once you sort out the if question above):
data: >
{% if hs[0] == 0 and hs[1] | float < (0.392) %} {# I think this is what you were trying to do #}
{{ {'kelvin': 2000} }}
{% else %}
{{ {'hs_color': (hs[0], hs[1])} }}
{% endif %}
If that doesn’t work you should be able to use an If/Then or a Choose action.