Christmas lights automation not turning the lights off

I recently set up some christmas lights. As of current, I only have one smart switch (Zigbee switch in HA) running christmas lights but I set it up as a group so I can easily add more for next year. Then I setup a simple automation to turn the group on at sunset and off at 10:30PM like all of my other christmas lights (which are currently wifi switches controlled by Alexa). I also made a toggle for “christmas season”, with out outdoor christmas lights we mostly don’t need our regular exterior lighting, so this is really just there to tell tell HA to not turn on the porch light when the christmas lights are on.

Apparently, my wife (who stays up later than I do due to work schedules) has had to turn off the one switch controlled by HA every night, and I cant figure out why my automation isn’t turning it off. Any input on why this wouldn’t work as I expect is appreciated, see below for the YAML of the automation.

alias: Christmas Lights
description: >-
  Turn all devices in currently used in Christmas Devices helper entity on and
  off at scheduled time
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition:
  - condition: state
    entity_id: input_boolean.christmas
    state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.christmas_devices
  - wait_for_trigger:
      - platform: time
        at: "22:30:00"
    continue_on_timeout: false
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.christmas_devices
mode: single

The issue with this is that, if the automation reloads midway for some reason like restart or so, the wait for trigger will be cancelled. The best way is to set another trigger and use choose action like below. Please do try it and let us know if this works.

description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
    id: start
  - platform: time
    at: "22:30:00"
    id: stop
condition:
  - condition: state
    entity_id: input_boolean.christmas
    state: "on"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: start
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.christmas_devices
      - conditions:
          - condition: trigger
            id: stop
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.christmas_devices
mode: single
1 Like

Wow, I’m still new to this and that blew my mind a little. Seriously need to re-do another automation I did recently for my bathroom vent fan.

Given that you’re simply turning a switch on/off you can use a service template to select the correct service call.

alias: Christmas Lights
description: >-
  Turn all devices in currently used in Christmas Devices helper entity on and
  off at scheduled time
trigger:
  - platform: sun
    event: sunset
    offset: 0
  - platform: time
    at: "22:30:00"
condition:
  - condition: state
    entity_id: input_boolean.christmas
    state: "on"
action:
  - service: "switch.turn_{{ iif(trigger.platform == 'sun', 'on', 'off') }}"
    data: {}
    target:
      entity_id: switch.christmas_devices
mode: single

You might find this useful too as a source of inspiration. I stole most of it in another thread about controlling climate devices ,-).

- alias: "Weihnachstbaum Mega Automatisierung"
  id: ffcd3f5d-04e6-4e24-b788-372431122081
  trigger:
    - platform: time
      at:
        - &time_start "08:00:00"
        - &time_end "23:00:00"

    - platform: state
      entity_id:
        - switch.anwesend
      to:

    - platform: state
      entity_id:
        - light.couch
      to: "on"

    - platform: homeassistant
      event: start

    - platform: event
      event_type: automation_reload

    - platform: time_pattern
      hours: "/2"
      minutes: 0
      id: "shift_effect"

  variables:
    anchors:
      - &target
        target:
          entity_id: light.weihnachtsbaum

      - &turn_off
        <<: *target
        alias: "Turn off christmas tree"
        service: light.turn_off

      - &turn_on
        <<: *target
        alias: "Turn on christmas tree"
        service: light.turn_on
        data:
          brightness: 128
          effect: "Twinkly Stars"

      - &change_sequence
        <<: *target
        alias: "Turn on christmas tree with random effect"
        service: light.turn_on
        data_template:
          brightness: 128
          effect: '{{ states.light.weihnachtsbaum.attributes.effect_list | reject("==", "SEQUENCER") | list | random }}'

  condition:
    - condition: template
      alias: "Nur im Advent bis 14 Tage nach Weihnachten"
      value_template: |-
        {{ -14 <= (now().replace(month=12,day=24,hour=20) - now()).days <= 25 }}

  action:
    - choose:
        - conditions:
            - alias: "When house is in vacation mode"
              condition: state
              entity_id: switch.anwesend
              state: "off"
          sequence:
            - *turn_off

        - conditions:
            - alias: "Regular change of effect"
              condition: trigger
              id: "shift_effect"
            - alias: "When evening/night"
              condition: time
              after: *time_start
              before: *time_end
          sequence:
            - *change_sequence

        - conditions:
            - alias: "When evening/night"
              condition: time
              after: *time_start
              before: *time_end
          sequence:
            - *turn_on

      default:
        - *turn_off