I want to create a list of colours from a calendar entry

alias: Festival Lights
description: >-
Cycles coloured LEDs through a given list of colours. My thanks to Didgeridrew
for all his help.
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.festival_lights
        data:
        color_name: “{{ colors | join }}”
        brightness_pct: 100
        transition: 300
        default:
    • repeat:
      sequence:
      - repeat:
      for_each: “{{ colors }}”
      sequence:
      - service: light.turn_on
      data:
      color_name: “{{ repeat.item }}”
      brightness_pct: 100
      transition: 300
      target:
      entity_id: light.festival_lights
      - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
      - service: light.turn_on
      data:
      color_name: “{{ repeat.item }}”
      target:
      entity_id: light.festival_lights
      - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
      count: 10000
      icon: mdi:firework
      mode: single

& this is where I’m up to on the script. I KNOW it works because I’ve triggered it and walked off for a couple of hours. Still running when I came back.
You’ll notice that I trigger the lights twice. Some of them are Zigbee bulbs and have a pretty low connection value so, they can be a bit stubborn.

I’ve just noticed I have a duplicate loop. I’ve taken the outer, “repeat for 10000”, loop out of the script.

Please format your configuration blocks properly.

It looks like you added a repeat in the automation which is not necessary and will cause issues if your don’t set the automation mode properly.

The script should have 2 loops… the outer one can be counted, while, or until; the inner loop is the repeat for each.

Oops! I never thought of that! Good catch! Sorry about the indents, I understand how irritating it must be. Still learning. :slight_smile:

alias: Trigger Festival Lights
description: >-
  Trigger when calendar event is active and the current time changes to the
  start time of the event. Use to turn on the lights. My thanks to Didgeridrew
  for all his help.
trigger:
  - platform: template
    value_template: >
      {% set start =
      (state_attr('calendar.festivals','start_time')|as_datetime|as_local).time()
      %}

      {{ is_state('calendar.festivals', 'on') and now() >= today_at(start) }}
condition:
  - condition: not
    conditions:
      - condition: template
        value_template: state_attr('calendar.festivals', 'description') is none
action:
  - service: script.turn_on
    data:
      variables:
        colors: >
          {{ state_attr('calendar.festivals', 'description').split(', ') | list
          }}
    target:
      entity_id: script.1702063362821

alias: Festival Lights
description: >-
  Cycles coloured LEDs through a given list of colours. My thanks to Didgeridrew
  for all his help.
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.festival_lights
            data:
              color_name: "{{ colors | join }}"
              brightness_pct: 100
              transition: 300
    default:
      - repeat:
          sequence:
            - repeat:
                for_each: "{{ colors }}"
                sequence:
                  - service: light.turn_on
                    data:
                      color_name: "{{ repeat.item }}"
                      brightness_pct: 100
                      transition: 300
                    target:
                      entity_id: light.festival_lights
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 1
                      milliseconds: 0
                  - service: light.turn_on
                    data:
                      color_name: "{{ repeat.item }}"
                    target:
                      entity_id: light.festival_lights
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: 10
                      milliseconds: 0
          until:
            - condition: template
              value_template: >
                {% set end =  (state_attr('calendar.festivals',
                'end_time')|as_datetime|as_local).time() %}

                {{ is_state('calendar.festivals', 'on') and (now() >
                today_at(end)) }}
  - service: light.turn_off
    target:
      entity_id: light.festival_lights
    data: {}
icon: mdi:firework
mode: single

So that’s the automation and script I have now and, it works! Thanks you. :slight_smile:

Further development:
I want to transfer the end time to the script from the automation as a field. For flexibility.
I want transfer the lights to be lit to the script as a field too. Again for flexibility.
I want to define half a dozen “chase” modes to ripple the colours. Just for fun.

I really appreciate all of your assistance and patience. Thanks a lot!

OK so, here’s the next stage in the development. I have an automation that’s triggered by the Google Calendar entries. Second, I have a script that cycles the chosen light group through the colours defined in the Google Calendar. Third I have another script that chases the colour through the light group.

alias: Trigger Festival Lights
description: >-
  Trigger when calendar event is active and the current time changes to the
  start time of the event. Use to turn on the lights. My thanks to Didgeridrew
  for all his help.
trigger:
  - platform: template
    value_template: >
      {% set start =
      (state_attr('calendar.festivals','start_time')|as_datetime|as_local).time()
      %}

      {{ is_state('calendar.festivals', 'on') and now() >= today_at(start) }}
condition:
  - condition: not
    conditions:
      - condition: template
        value_template: state_attr('calendar.festivals', 'description') is none
action:
  - service: script.turn_off
    target:
      entity_id: script.1702063362821
    data: {}
  - service: light.turn_off
    target:
      entity_id: light.festival_lights
    data: {}
  - service: script.turn_on
    data:
      variables:
        colours: >
          {{ state_attr('calendar.festivals', 'description').split(', ') | list
          }}
        end: >-
          {{ (state_attr('calendar.festivals',
          'end_time')|as_datetime|as_local).time() }}
        light_group: light.festival_lights
        dwell: 0.5
        cycle_time: 5
    target:
      entity_id: script.1702063362821

alias: Festival Lights
description: >-
  Cycles coloured LEDs through a given list of colours. My thanks to Didgeridrew
  for all his help.
fields:
  colours:
    name: Colours
    description: A list of color_names to set the lights to or loop through
    required: true
  end:
    description: The time of day the lights should turn out
  light_group:
    description: The group of lights to be lit
  dwell:
    description: The time to dwell on each light if chasing. 0 means no chase
    default: 0
  cycle_time:
    description: The time to wait at the end of each colour change
    default: "{{ len(light_group) }}"
sequence:
  - if:
      - condition: template
        value_template: "{{ colours | count == 1 }}"
    then:
      - service: light.turn_on
        target:
          entity_id: "{{ light_group }}"
        data:
          color_name: "{{ colours | join }}"
          brightness_pct: 100
      - wait_template: |
          {{ now() > today_at(end) }}
        continue_on_timeout: true
    else:
      - repeat:
          sequence:
            - repeat:
                for_each: "{{ colours }}"
                sequence:
                  - service: script.1702406801067
                    data:
                      lights: "{{ light_group }}"
                      pause: "{{ dwell }}"
                      brights: 100
                      colour: "{{ repeat.item }}"
                  - delay:
                      hours: 0
                      minutes: 0
                      seconds: "{{ cycle_time }}"
                      milliseconds: 0
          until:
            - condition: template
              value_template: |
                {{ now() > today_at(end) }}
  - service: light.turn_off
    target:
      entity_id: "{{ light_group }}"
    data: {}
icon: mdi:firework
mode: single
alias: Chase a colour through a light group
fields:
  lights:
    description: The light group to be lit
  pause:
    description: How long to dwell on each light
  brights:
    description: The brightness_pct to illuminate the lights to
  colour:
    description: The color_name to illuminate the lights to
sequence:
  - variables:
      light_list: >-
        {{ expand(state_attr(lights,
        'entity_id'))|map(attribute='entity_id')|list }}
  - repeat:
      sequence:
        - service: light.turn_on
          data:
            brightness_pct: "{{ brights }}"
            color_name: "{{ colour }}"
          target:
            entity_id: "{{ repeat.item }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: "{{ pause }}"
            milliseconds: 0
      for_each: "{{ light_list }}"
mode: parallel