I would create an automation to switch lights between two colors. One switch open and set 7 lights, 3 green, 4 red. But the loop (christmas_lights_loop) between red and green doesn’t work. Until the switch is open, the lights are looping. When I put off the switch, they stop the loop.
My code:
# ##########################################################################################
# # Inputs
# ##########################################################################################
input_boolean:
noel_switch:
name: Noel Mode
icon: mdi:string-lights
initial: off
# ##########################################################################################
# # Inputs
# ##########################################################################################
switch:
- platform: template
switches:
noel_switch:
value_template: '{{ states("input_boolean.noel_switch") }}'
friendly_name: 'Noel Mode'
turn_on:
- service: input_boolean.turn_on
entity_id: input_boolean.noel_switch
turn_off:
- service: input_boolean.turn_off
entity_id: input_boolean.noel_switch
##########################################################################################
# Scripts
##########################################################################################
script:
christmas_lights_on:
alias: Loop Noel on
sequence:
- service: light.turn_on
data:
entity_id:
- light.smart_rgb_bulb_corniche_gauche
- light.smart_rgb_bulb_corniche_droite
- light.smart_rgb_bulb_garage_gauche
- light.smart_rgb_bulb_garage_cote
rgb_color: [255, 0, 0] # Rouge
- service: light.turn_on
data:
entity_id:
- light.smart_rgb_bulb_corniche_centre
- light.smart_rgb_bulb_balcon
- light.smart_rgb_bulb_garage_droit
rgb_color: [0, 255, 0] # Vert
- service: script.turn_on
entity_id: script.christmas_lights_loop
christmas_lights_loop:
- variables:
rgb_colors:
- red
- green
- sequence:
repeat:
while: "{{ is_state('input_boolean.noel_switch', 'on') }}"
sequence:
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_corniche_gauche
data:
rgb_colors: "{{ rgb_colors[(repeat.index - 1) % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_corniche_centre
data:
rgb_colors: "{{ rgb_colors[repeat.index % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_corniche_droite
data:
rgb_colors: "{{ rgb_colors[(repeat.index + 1) % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_balcon
data:
rgb_colors: "{{ rgb_colors[(repeat.index + 2) % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_garage_gauche
data:
rgb_colors: "{{ rgb_colors[(repeat.index + 2) % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_garage_droit
data:
rgb_colors: "{{ rgb_colors[(repeat.index + 2) % 2] }}"
- service: light.turn_on
target:
entity_id: light.smart_rgb_bulb_garage_cote
data:
rgb_colors: "{{ rgb_colors[(repeat.index + 2) % 2] }}"
- delay:
minutes: 1
christmas_lights_off:
alias: Loop Noel off
sequence:
- service: light.turn_off
data:
entity_id:
- light.smart_rgb_bulb_corniche_gauche
- light.smart_rgb_bulb_corniche_droite
- light.smart_rgb_bulb_garage_gauche
- light.smart_rgb_bulb_garage_cote
- light.smart_rgb_bulb_corniche_centre
- light.smart_rgb_bulb_balcon
- light.smart_rgb_bulb_garage_droit
- service: script.turn_off
entity_id: script.christmas_lights_loop
##########################################################################################
# Automations
##########################################################################################
automation:
- alias: 'Loop Noel on'
id: 'Loop Noel ON'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.noel_switch
from: 'off'
to: 'on'
action:
service: script.christmas_lights_on
- alias: 'Loop Noel off'
id: 'Loop Noel OFF'
initial_state: true
trigger:
- platform: state
entity_id: input_boolean.noel_switch
from: 'on'
to: 'off'
action:
- service: light.turn_off
entity_id:
- light.smart_rgb_bulb_corniche_gauche
- light.smart_rgb_bulb_corniche_centre
- light.smart_rgb_bulb_corniche_droite
- light.smart_rgb_bulb_balcon
- light.smart_rgb_bulb_garage_gauche
- light.smart_rgb_bulb_garage_droit
- light.smart_rgb_bulb_garage_cote
- delay: 1
- service: script.christmas_lights_off
In the logs:
Script with object id ‘christmas_lights_loop’ could not be validated and has been disabled: expected a dictionary. Got [{‘variables’: {‘rgb_colors’: [‘red’, ‘green’]}}, {‘sequence’: {‘repeat’: {‘while’: “{{ is_state(‘input_boolean.noel_switch’, ‘on’) }}”, ‘sequence’: [{‘service’: ‘light.turn_on’, ‘target’: {‘entity_id’: ‘light.smart_rgb_bulb_corniche_gauche’}, ‘data’: {‘rgb_colors’: ‘{{ colors[(repeat.index - 1) % 2] }}’}}, {‘service’: ‘light.turn_on’, ‘target’: {‘entity_id’: ‘light.smart_rgb_bulb_corniche_centre’}, ‘data’: {‘rgb_colors’: ‘{{ colors[repeat.index % 2] }}’}}, {‘service’: ‘light.turn_on’, 'targe…