Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Set variables before calling service in script?

$
0
0

@daave wrote:

I’m trying to swap the state of two lights randomly. When I call the script, nothing happens. Also, where should I be putting code to set variables before I call the services with that variables? this code checks out as valid, but doesn’t appear to do anything.

lights_swap:
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: >
            {% set sl_light_1_name =  ( ['kitchen_1','kitchen_2','kitchen_3','kitchen_4','kitchen_5','kitchen_6','livingroom_lamp']|random )  %}
            {% set sl_light_1_rgb = (  states.light[sl_light_1_name].attributes.rgb_color ) %}
            {% set sl_light_1_brightness = (  states.light[sl_light_1_name].attributes.brightness ) %}
            {% set sl_light_2_name =  ( ['kitchen_1','kitchen_2','kitchen_3','kitchen_4','kitchen_5','kitchen_6','livingroom_lamp']|random )  %}
            {% set sl_light_2_rgb = (  states.light[sl_light_2_name].attributes.rgb_color ) %}
            {% set sl_light_2_brightness = (  states.light[sl_light_2_name].attributes.brightness ) %}
            light.{{sl_light_1_name}}
        brightness: '{{ sl_light_2_brightness }}'
        rgb_color: '{{ sl_light_2_rgb }}'
        transition: 5
    - service: light.turn_on
      data_template:
        entity_id: >
            light.{{sl_light_2_name}}
        brightness: '{{ sl_light_1_brightness }}'
        rgb_color: '{{ sl_light_1_rgb }}'
        transition: 5

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>