@Ralph_Bisschops wrote:
Hi All,
I’m trying to change a rather ugly piece of code in a script into something nice.
Here is the original script:## Added V1.2.0 ## Script for setting Hue lamps in video or normal mode ## used in package_media_center hue_mode_change: alias: Licht aanpassen voor video of normale mode sequence: - service: script.set_hue_scene_auto data_template: brightness_stop_group_1: > {% if (states.input_select.livingroom_lights_mode.state == "Video") %} 90 {% else %} 100 {% endif %} brightness_stop_group_2: > {% if (states.input_select.livingroom_lights_mode.state == "Video") %} 100 {% else %} 150 {% endif %} profile_stop_1: > {% if (states.input_boolean.christmas_mode.state == "on") %} "christmas_normal_1" {% else %} "normal_1" {% endif %} profile_stop_2: > {% if (states.input_boolean.christmas_mode.state == "on") %} "christmas_normal_2" {% else %} "normal_2" {% endif %} transition: 5
Bassically I wnat to get rid of the double if statements
This is what I’d like to do after trying other variants as well:## Added V1.2.0 ## Script for setting Hue lamps in video or normal mode ## used in package_media_center hue_mode_change: alias: Licht aanpassen voor video of normale mode sequence: - service: script.set_hue_scene_auto data_template: brightness: > {% if (states.input_select.livingroom_lights_mode.state == "Video") %} {% set brightness = {"one": 90, "two": 100} %} {{ brightness }} {% else %} {% set brightness = {"one": 100, "two": 150} %} {{ brightness }} {% endif %} profile: > {% if (states.input_boolean.christmas_mode.state == "on") %} {% set profile = {"one": "christmas_normal_1", "two": "christmas_normal_2"} %} {{ profile }} {% else %} {% set profile = {"one": "normal_1", "two": "normal_2"} %} {{ profile }} {% endif %} transition: 5
With the last example code the next script should do this:
## Script for setting Hue lamps into a new mode (from off) ## set_hue_scene_auto: alias: Set hue mode overgang naar andere scene sequence: - service: light.turn_on data_template: entity_id: light.lage_kasten_hue # brightness: "{{ brightness_stop_group_1 }}" # profile: "{{ profile_stop_1 }}" brightness: "{{ brightness.one|int }}" profile: "{{ profile.one }}" transition: "{{ transition|float }}" - service: light.turn_on data_template: entity_id: light.staande_lampen_hue # brightness: "{{ brightness_stop_group_2 }}" # profile: "{{ profile_stop_2 }}" brightness: "{{ brightness.two|int }}" profile: "{{ profile.two }}" transition: "{{ transition|float }}"
I left in the original code lines (commented) that were in the code that worked with the original script.
Who can help me out here. The code is not reporting errors (on config check) but is not working.
Thanks all,
Ralph
Posts: 1
Participants: 1