Same procedure... Christmas Automation

Hi there,

I need a little bit of a help for my Christmas automation.
For perfect automation I have it currently “touchless”. The automation switches my Hue zone with the lights on or off, depending on month and time:

alias: Weihnachtsbeleuchtung AN
description: ""
triggers:
  - at: "06:15:00"
    trigger: time
  - at: "16:15:00"
    trigger: time
conditions:
  - condition: template
    value_template: |
      {% set date = now() %} {{ date.month == 12 and 1 <= date.day <= 31 }}
actions:
  - type: turn_on
    device_id: 734130xxxxxxxxxxxxxxxxxxx
    entity_id: 7457c62xxxxxxxxxx
    domain: light
mode: single

My wife now insists on having it on earlier (starting on 5th Monday before Christmas). Obviously I still want it to be touchless (and not switching on/off manually until 1st of December)

Anyone having a clue how to configure the automation to start at the Monday in the 5th week before Christmas?

Thanks a lot!

/KNEBB

Honestly, I’d just create an entry manually in the HA calendar integration at 6:15 for the next 20 years. Have your automation triggered by the start of the calendar event & job done.

Ps. You have a duplicate trigger in your current automation - remove it.
Also, you’re missing a trigger to switch off the lights. If you follow my above advice, set the end timestamp of the calendar event as the switch off trigger.

This calculation will get you the date of the Monday five weeks before Christmas week.

{%- set fiveweeksbefore = ((now().year~'-12-25') | as_datetime) - timedelta(weeks=5) %}
{{ fiveweeksbefore }}
{%- set thatmonday = fiveweeksbefore - timedelta(days=(fiveweeksbefore.strftime('%w')|int-1)) %}
{{ thatmonday }}

You could use an automation to set a date helper to that date. Of course, if you are calculating the date for next year before this year ends, you’ll have to add a year to it.

I did it a little different from Jeff

{%- set current = today_at() %}
{%- set xmas = current.replace(month=12, day=25) %}
{%- set wd_adjust = (0 - xmas.weekday()) % 7 %}
{%- set start = (xmas + timedelta(days=wd_adjust)) - timedelta(weeks = 6) %}
{{ (start.month,start.day) <= (current.month, current.day) <= (12,31) }}
1 Like

No way to do it this way. If I got this right I have to create a daily schedule for the full five weeks which repeats yearly. So adding 35 similar calendar entries. This is not what I understand as “automation”.

Sorry again- no I have not. It is supposed to switch on on both times.
And of course I have a switch off trigger, just not mentioned here.

/KNEBB

This looks pretty nice. Even though I do not really understand everything there but at least it seems to be logical and I will give it a try.

/KNEBB

It looks like you copied it right as I was making a couple changes…

Ok, got it- but explain the added line, please…

{%- set current = today_at() %}
{%- set xmas = current.replace(month=12, day=25) %}

current is set to Christmas date by replacing month and day of current date by 12 and 25.

{%- set wd_adjust = (0 - xmas.weekday()) % 7 %}

Now takes a modulo operation for the weekday of Christmas. Result is something between 0 and 6.

{%- set start = (xmas + timedelta(days=wd_adjust)) - timedelta(weeks = 6) %}

Herre I am struggling. What is the timedelta()function doing?
Calculates the start by adding the previous value somehow to xmas date. And then counting back six weeks?

{{ (start.month,start.day) <= (current.month, current.day) <= (12,31) }}

Struggling again. Does not fit the 1st of August as well?

/KNEBB

That’s finding the number of days to add to Christmas’ date to get the next Monday. 0 is the weekday() value for Monday.

Yes.

The first one is adding the weekday adjustment (resulting in the Monday after Christmas) then the second is subtracting 6 weeks… resulting in start holding a the Monday 5 weeks before Christmas.

The timedelta() could actually be done in one shot, but I thought it would be more confusing:

(xmas + timedelta(days=wd_adjust, weeks = -6))

No, because start holds the datetime for the Monday 5 weeks before Christmas. If current.month returned 8 the statement would be false for the first tuple comparison because 11 is not less than or equal to 8.

Why not just enabling a purely time-based automation on the right Monday and disabling it on December 31st?
Because that’s no fun, I guess :disappointed:

1 Like

Thanks for the other explanations- got it now.

But did not get this last one. Ok, startholds the Monday I am looking for… thinking twic I got it now.
It checks if the current date is between start date and Dece, 31st. Yeah, perfect!

That seems to match perfectly now.

/KNEBB

You answered yourself.

An automation is not an automation if I have to enable and disable it manually…
/KNEBB

You actually don’t have to do it manually.

You could do it with another automation using either of the above calculations and December 31st.

An automation enabling and disabling another automation. How much more fun can you have? LOL

Of course, that was the point.

I tried to take a look myself and my friend Chad came up with a pretty good solution, but I’m not allowed to post it here :wink:

1 Like

I have this template running.
Covers all November, December thru the 12th day of Christmas.
Gives me a sensor to monitor everything Christmas, everywhere, all at once…

Apologies, you’re right on both counts. Don’t know where my brain went yesterday.

1 Like