I actually like Phil’s solution better and am using it now.
- id: xmas_lights_on
alias: 'Xmas Lights On'
trigger:
platform: numeric_state
entity_id: sensor.outside_light_level
below: 660
condition:
- condition: sun
after: sunrise # Active 4 hours after sunrise (prevents false triggering at dawn)
after_offset: "+04:00:00"
- condition: template # Only between December 1 and January 6.
value_template: >
{% set n = now() %}
{{ n.month == 12 or ( n.month == 1 and ( 1 <= n.day <= 5 )) }}
action:
service: switch.turn_on
entity_id: switch.xmas_tree_lights
- id: xmas_lights_off
alias: 'Xmas Lights Off'
trigger:
- platform: time
at: '02:00:00'
- platform: state
entity_id: binary_sensor.dark_outside
to: 'off'
condition:
condition: state
entity_id: switch.xmas_tree_lights # only if the lights are on
state: 'on'
action:
service: switch.turn_off
entity_id: switch.xmas_tree_lights