Hi,
I would like to toggle through light colors by adjusting the hs_color value, which I want to trigger with a remote.
Therefore I try to increment the hue value of the hs_color attribute of the light. Since values over 360 seems not be permitted, I want to catch the exception using an if statement.
Here is my code:
service: light.turn_on
data:
hs_color:
{%- if state_attr(states('input_select.selectedlight'), 'hs_color') %}
{%- if state_attr(states('input_select.selectedlight'), 'hs_color')[0] + 18 > 360 %}
{%- set hue = (state_attr(states('input_select.selectedlight'), 'hs_color')[0] + 18 - 360) %}
{%- set sat = (state_attr(states('input_select.selectedlight'), 'hs_color')[1] ) %}
{%- else %}
{%- set hue = (state_attr(states('input_select.selectedlight'), 'hs_color')[0] + 18) %}
{%- set sat = (state_attr(states('input_select.selectedlight'), 'hs_color')[1] ) %}
{%- endif %}
{%- else %}
{%- set hue = 10 %}
{%- set sat = 100 %}
{%- endif %}
- {{hue}}
- {{sat}}
target:
entity_id: '{{ states.input_select.selectedlight.state }}'
This results in the following code in the template editor, which works if I copy & paste it into the service call:
service: light.turn_on
data:
hs_color:
- 242.916
- 70.196
target:
entity_id: 'light.lampe_couch_level_light_color_on_off'
Unfortunately, the dynamic code with the if statements doesn’t work in the service call and after a few hours I still haven’t figured out why.
Could somebody please advise?
Thanks
Steffen