All,
Is there a way to do this based upon day of week and month? Specifically, I want my Christmas Season to be after Thanksgiving, which would be the 4th Friday {after 4th Thursday, Thanksgiving) in November? I have a card in my mushroom dashboard that is only active at Christmas time, so I want to automate that date.
Currently I’m using the template above and manually setting the date, but the point of automation is to do it automatically.
Here is a formula for calculating Thanksgiving Day in the current year.
{% set current_year= now().year %}
{% set day_nov_starts = as_datetime( current_year ~ "-11-01").isoweekday() %}
{% if day_nov_starts > 4 -%} {# case that November starts on Friday, Saturday, or Sunday #}
{% set Thanksgiving_day = 33 - day_nov_starts %}
{%- else -%} {# case that November starts on Monday to Thursday #}
{% set Thanksgiving_day = 26 - day_nov_starts %}
{%- endif %}
{% set Thanksgiving = as_datetime( current_year ~ "-11-" ~ Thanksgiving_day) %}
I have made a binary sensor for christmas time, here christmas is between first advent sunday (the sunday f weeks before christmas) and the thirteens day ( 6th of january) and it works well, maybe it can be done a bit mor elegant.
- name: "christmas_time"
unique_id: 88bbd5ca-71ce-42c6-b8bd-66950579ab2e
state: >
{%- set week, day = 4, 6 %}
{%- set today = now().date() %}
{%- set christmaseve = today.replace(month=12, day=24) %}
{%- set christmasday = christmaseve + timedelta(days=1) %}
{%- set epiphany = today.replace(month=1, day=6) %}
{%- set temp = christmasday %}
{%- set adjust = (day - christmasday.weekday()) % 7 %}
{%- set temp = temp + timedelta(days=adjust) %}
{%- set firstadventsunday = temp - timedelta(weeks=week) %}
{%- set secondadventsunday = temp - timedelta(weeks=week-1) %}
{%- set thirdadventsunday = temp - timedelta(weeks=week-2) %}
{%- set fourthadventsunday = temp - timedelta(weeks= week-3) %}
{{ today <= epiphany or today >= firstadventsunday }}
I would want all the different days to be given as attributes to the binary sensor. I tried to just add attributes like this
Hi, not directly answering your question but, why do you not use the local calendar integration instead? For fixed dates it runs year after year, for the rest you do it ones per year. I use that for my christmas lighting, halloween, easter and all the other special days. I even put special events there to be spoken by TTS during the day.
So i do need to do the same calculation twice. Ones under the state: section and again under attributes: section. Ihoped there was a way to only do the calculations once. But hey, you can’t always get what you want.
But instead i got a great explenation of how to do it.
That’s absolutely a way to do it. I will check that too. I also wanted to learn how to do it and thought that a christmas binary sensor would be a great sensor to try with.
I was looking for the same and came multiple times on this topic. It’s a few years old so i thought i post an update on how it’s by done now. People who find this post through Google can use the most efficient way.
Create an input helper: schedule with the times when it should been displayed.
On the dashboard use the conditional card
On the conditional card add the condition: “Entity state” and select your input helper.
This should do the trick.
AWESOME when a system keeps updating and makes it everytime easyer to use.