Automation help turning on lights

I’m trying to setup an automation to turn on our ‘Holiday’ lights outside.

I thought I’d start with a simple automation first and then make it more complicated. the simple automation I want is to turn the lights on to a solid colour after sunset.

Below is the automation I tried last week, it didn’t work and I think it crashed HA taking the VM with it. Either that or the crash was a very precise coincidence.

alias: Holiday Light test
description: Turn on the Holiday Lights
trigger:
  - platform: template
    value_template: '{{ now().strftime("%m-%d") == "11-15" }}'
condition:
  - condition: sun
    after: sunset
action:
  - service: light.turn_on
    target:
      device_id: f8170eb7cc72b6712b87dec319a3cadf
    data:
      color_name: purple
      effect: Solid
mode: single

This automation will never execute…

If you made this last week… it wasn’t November 15th.

Also, that’s not the right trigger to use. Triggers execute upon a change, so when triggering off the date, the trigger executes after midnight. As far as Home Assistant is concerned, after midnight will always be before sunset not after.

Switch your trigger to be after sunset.

@Didgeridrew

I changed the date to one in the future :slight_smile:

So I want to set the trigger to ‘After sunset’ and then a condition template of {{ now().strftime("%m-%d") == "11-15" }} to have them turn on, on only the 15th of Nov?

Yes, that will work.

FWIW, this is the convention I like to use:

trigger:
  - platform: template
    value_template: '{{ (now().month, now().day) == (11,15) }}'

There are many ways to compare the current month and day to a desired month and day. The choice is often a personal one.