I have a holiday lights automation that turns on various Zigbee lights for multiple holidays of the year. For Christmas, I currently use the local calendar integration as a condition to run a lighting script at sunset between November 29th (the last possible Friday after Thanksgiving that could occur) and December 31st. I would like to make this condition a little more dynamic and predict the day after Thanksgiving every year, which is always the fourth Friday in November. So, the condition should be “between the fourth friday of November and December 31st” instead of between November 29th and December 31st.
For reference, here is an excerpt of my lighting automation as it relates to Christmas lights (it controls other holidays as well):
alias: Holiday Auto Lights
description: Automates holiday lighting on front porch
triggers:
- event: sunset
id: sunset
trigger: sun
- event: sunrise
offset: "-02:00:00"
id: sunrise
trigger: sun
- entity_id:
- calendar.holidays_in_united_states
from: "on"
to: "off"
id: holiday ends
trigger: state
- entity_id:
- calendar.local_holiday_calendar
from: "on"
to: "off"
id: holiday ends
trigger: state
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- sunset
- condition: or
conditions:
- condition: state
entity_id: calendar.holidays_in_united_states
state: "on"
- condition: state
state: "on"
entity_id: calendar.local_holiday_calendar
- condition: state
entity_id: sensor.holiday_date_tracker
state: Tomorrow
sequence:
- choose:
- conditions:
- condition: state
entity_id: calendar.local_holiday_calendar
attribute: message
state: Christmas Month
- condition: state
state: "on"
entity_id: calendar.local_holiday_calendar
sequence:
- metadata: {}
data: {}
target:
entity_id: script.holiday_lights_christmas
action: script.turn_on
alias: Christmas
alias: Sunset/Activate Holiday Lights
- conditions:
- condition: trigger
id:
- sunrise
- condition: or
conditions:
- condition: state
entity_id: calendar.holidays_in_united_states
state: "on"
- condition: state
state: "on"
entity_id: calendar.local_holiday_calendar
- condition: state
entity_id: sensor.holiday_date_tracker
state: Tomorrow
sequence:
- metadata: {}
data: {}
target:
entity_id:
- script.holiday_lights_christmas
action: script.turn_off
- metadata: {}
data: {}
target:
entity_id:
- light.front_porch_light
- light.driveway_light
action: light.turn_off
alias: Sunrise Reset
- conditions:
- condition: trigger
id:
- holiday ends
sequence:
- delay:
hours: 4
minutes: 0
seconds: 0
milliseconds: 0
- metadata: {}
data: {}
target:
entity_id:
- script.holiday_lights_christmas
action: script.turn_off
- metadata: {}
data: {}
target:
entity_id:
- light.front_porch_light
- light.driveway_light
action: light.turn_off
alias: Holiday Ends Reset
mode: single