MontyRisk
(Monty Risk)
April 20, 2021, 12:00pm
1
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 }}
1 Like
petro
(Petro)
April 20, 2021, 12:05pm
2
I use this, it keeps the lights on between the day after thanks giving and jan 15th
- platform: template
sensors:
christmas_season:
unique_id: christmas_season
friendly_name: Christmas Season
value_template: >
{%- set month, week, day = 11, 4, 3 %}
{%- set today = now().date() %}
{%- set temp = today.replace(month=month, day=1) %}
{%- set adjust = (day - temp.weekday()) % 7 %}
{%- set temp = temp + timedelta(days=adjust) %}
{%- set thanksgiving = temp + timedelta(weeks = week - 1) %}
{%- set jan15th = temp.replace(month=1, day=15) %}
{{ today <= jan15th or today > thanksgiving }}
This doesn’t turn them on jan 1st +
- platform: template
sensors:
christmas_season:
unique_id: christmas_season
friendly_name: Christmas Season
value_template: >
{%- set month, week, day = 11, 4, 3 %}
{%- set today = now().date() %}
{%- set temp = today.replace(month=month, day=1) %}
{%- set adjust = (day - temp.weekday()) % 7 %}
{%- set temp = temp + timedelta(days=adjust) %}
{%- set thanksgiving = temp + timedelta(weeks = week - 1) %}
{%- set jan1 = temp.replace(month=1, day=1) %}
{{ today < jan1 or today > thanksgiving }}
Question! How would i modify your sensor to turn them off the first saturday AFTER new years day?
petro
(Petro)
April 22, 2021, 3:47pm
5
- platform: template
sensors:
christmas_season:
unique_id: christmas_season
friendly_name: Christmas Season
value_template: >
{%- set month, week, day = 11, 4, 3 %}
{%- set today = now().date() %}
{%- set temp = today.replace(month=month, day=1) %}
{%- set adjust = (day - temp.weekday()) % 7 %}
{%- set temp = temp + timedelta(days=adjust) %}
{%- set thanksgiving = temp + timedelta(weeks = week - 1) %}
{%- set month, week, day = 1, 1, 5 %}
{%- set temp = today.replace(month=month, day=1) %}
{%- set adjust = (day - temp.weekday()) % 7 %}
{%- set temp = temp + timedelta(days=adjust) %}
{%- set firstsat = temp + timedelta(weeks = week - 1) %}
{{ today < firstsat or today > thanksgiving }}
2 Likes
Amazing, thank you! Now to learn what all this means so i can use it for other ideas!
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)?