Skip to content

Instantly share code, notes, and snippets.

@Didgeridrew
Last active February 1, 2024 04:55
Show Gist options
  • Select an option

  • Save Didgeridrew/3a2e5fc49042e100af37f706474109de to your computer and use it in GitHub Desktop.

Select an option

Save Didgeridrew/3a2e5fc49042e100af37f706474109de to your computer and use it in GitHub Desktop.
HA - Script Loop Light Colors
script:
color_loop_light:
alias: Color loop light
description: ""
fields:
colors:
name: Colors
description: A list of color names to set the lights to or loop through
required: true
sequence:
- choose:
- alias: Single color turn on - no loop needed
conditions:
- condition: template
value_template: "{{ colors | count == 1 }}"
sequence:
- service: light.turn_on
target:
entity_id: light.gledopto_lightbar_01
data:
color_name: "{{ colors | join }}"
default:
- repeat:
while:
- condition: template
value_template: "{{ now() < today_at('23:59:01') }}"
sequence:
- repeat:
for_each: "{{ colors }}"
sequence:
- service: light.turn_on
data:
color_name: "{{ repeat.item }}"
target:
entity_id: light.gledopto_lightbar_01
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
automation:
- id: calendar_based_color_loop
alias: Light - Holiday Color Loop
description: ''
trigger:
- alias: >-
Trigger when calendar event is active and the current time changes to >=
the start time of the event. Use to turn on the lights
id: "on"
platform: template
value_template: >
{% set start =
(state_attr('calendar.festival_lights','start_time')|as_datetime|as_local).time()
%}
{{ is_state('calendar.festival_lights', 'on') and now() >= today_at(start)
}}
- alias: >-
Trigger when calendar event is active and the current time changes to >=
the end time of the event. Use to turn off the lights
id: "off"
platform: template
value_template: >
{% set end =
(state_attr('calendar.festival_lights','end_time')|as_datetime|as_local).time()
%}
{{ is_state('calendar.festival_lights', 'on') and now() >= today_at(end)
}}
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: "on"
sequence:
- service: script.turn_on
data:
variables:
colors: >
{{ 'white' if
state_attr('calendar.festival_lights','description')
is none else
(state_attr('calendar.festival_lights','description')).split(',
')|list }}
target:
entity_id: script.ztest_color_loop_light
- conditions:
- condition: trigger
id: "off"
sequence:
- alias: Stop the loop
service: script.turn_off
data: {}
target:
entity_id: script.ztest_color_loop_light
continue_on_error: true
- alias: Turn off the light
service: light.turn_off
target:
entity_id: light.gledopto_lightbar_01
data: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment