Hi!
Guys, I’m trying to solve it by myself. Initially it seemed to me that it will be very easy, but I’m stopped right now.
I have an two scripts for gu10 lights. Fox example:
kitchen_cooker_hood_white:
sequence:
- service: light.turn_on
data:
entity_id:
- light.kitchen_cooker_hood_left_gu10
- light.kitchen_cooker_hood_right_gu10
brightness: 255
color_temp: 153
kitchen_cooker_hood_warm:
sequence:
- service: light.turn_on
data:
entity_id:
- light.kitchen_cooker_hood_left_gu10
- light.kitchen_cooker_hood_right_gu10
brightness: 255
color_temp: 454
I want to changing the light color temperature by click on my ikea switch, if it is 153 - it means to turn on 454, if 454 - then turn on 153 and that’s it. Here is my action case, where I’m stopped now, I just post it as it is:
action:
- service: script.turn_on
data_template:
entity_id: >-
{%- if is_state_attr('light.kitchen_cooker_hood_left_gu10','color_temp','153') -%}
script.kitchen_cooker_hood_warm
{%- else -%}
script.kitchen_cooker_hood_white
{% endif %}
It’s possible to make my idea or not? Just not understandable now this direction.
Try removing the quotes around 153. The attribute is a number, not a string.
It seems that there is no difference between quotes or not - apparently the logic of the template itself is not correct, here is the answer of the template editor without quotes and with them (the same thing):
action:
- service: script.turn_on
data_template:
entity_id: >-script.kitchen_cooker_hood_white
Oh homie! U’re right! YES! I was almost right! Thanks for the help with quotation marks :))) Very grateful for the help.
Here is my full automations who works with scripts above:
- alias: kitchen_ikea_switch_down_button_long_switch_cooker_hood_lights_color_temp
initial_state: true
trigger:
- platform: event
event_type: deconz_event
event_data:
id: kitchen_ikea_switch
event: 3001
condition:
- condition: state
entity_id: light.kitchen_cooker_hood_left_gu10
state: 'on'
- condition: state
entity_id: light.kitchen_cooker_hood_right_gu10
state: 'on'
action:
- service: script.turn_on
data_template:
entity_id: >-
{%- if is_state_attr('light.kitchen_cooker_hood_left_gu10','color_temp',153) -%}
script.kitchen_cooker_hood_warm
{%- else -%}
script.kitchen_cooker_hood_white
{% endif %}
By the way, now I check only 1 light bulb out of two - maybe it’s worth checking the second one in the template too. I mean, should there be two lamps in the template, for example, for a more accurate response?
@pnbruckner Thanks buddy again! All works like out from the box!
No problem.
BTW, you can certainly do this without the need of the two scripts…
- alias: kitchen_ikea_switch_down_button_long_switch_cooker_hood_lights_color_temp
initial_state: true
trigger:
- platform: event
event_type: deconz_event
event_data:
id: kitchen_ikea_switch
event: 3001
condition:
- condition: state
entity_id: light.kitchen_cooker_hood_left_gu10
state: 'on'
- condition: state
entity_id: light.kitchen_cooker_hood_right_gu10
state: 'on'
action:
- service: light.turn_on
entity_id:
- light.kitchen_cooker_hood_left_gu10
- light.kitchen_cooker_hood_right_gu10
data_template:
brightness: 255
color_temp: >
{% if is_state_attr('light.kitchen_cooker_hood_left_gu10', 'color_temp', 153) %}
454
{% else %}
153
{% endif %}
1 Like