Using the below to turn on the Christmas Light Season sensor. It will turn on the day after Thanksgiving. Every year I need to enter the date for Thanksgiving as shown below.
Do you have any suggestions to make it do this automatically?
binary_sensor:
# Christmas Light Season
- platform: template
sensors:
christmas_light_season:
friendly_name: Christmas Light Season
value_template: >
{% set today = states('sensor.date').split('-') %}
{% set month = today[1]|int %}
{% set day = today[2]|int %}
{{ month == 11 and day > 25 or month == 12 }}
Sorry to necro the thread, how would I adjust this for additional seasons? I tried to comprehend, but its so elegant, I couldn’t reverse engineer it.
Specifically, the last Saturday of September through (but also including) Halloween night. (Halloween Season)?
For anyone as lost as I was, install the “Templates” integration, create a new integration for “Christmas lights season” and paste the code from “value_template” into the “State template” box.
Here’s a more readable (imo) version. I want the last night of Christmas lights to be New Years Day… and I still want them to switch off on the morning of Jan 2. So I set the end date to be noon on Jan 2 and the start date is noon on Thanksgiving (USA).
{# https://community.home-assistant.io/t/301306/8 #}
{% set now = now() -%}
{# https://stackoverflow.com/a/78339774 #}
{% set days = namespace(nov=[]) -%}
{% for n in range(1,30) -%}
{% set d = now.replace(now.year,11,n,12) -%}
{% if d.weekday()==3 -%}
{% set days.nov = days.nov + [d] -%}
{% endif -%}
{% endfor -%}
{% set thanksgiving = days.nov[3] -%}
{% set jan2 = now.replace(now.year,1,1,12) -%}
{{ not jan2 <= now <= thanksgiving }}