Automations and if/then with Public Holidays added

I have some automations using an ‘if’ time condition for workdays within an if/then action so I can have a different outcome on ‘else’ weekends. If I wanted to add public holidays to automation to behave same as weekends what would be best way to achieve that outcome?

Use this:


I’d definitely recommend using template conditions as I did (mine is quite complex but you’ll understand).

{% set today = today_at() %}
{% set tomorrow= today_at() + timedelta(days=1) %}

{% set is_weekend = now().isoweekday() in [6, 7] %}
{% set is_school_holiday = states('calendar.conges_scolaires') == 'on' %}
{% set is_public_holiday = states('calendar.jours_feries_en_belgique') == 'on' %}

{% set start_school_day_off= state_attr('calendar.conges_scolaires','start_time') | as_datetime | as_local %}
{% set start_public_holiday = state_attr('calendar.jours_feries_en_belgique','start_time') | as_datetime | as_local %}
{% set end_school_day_off= state_attr('calendar.conges_scolaires','end_time') | as_datetime | as_local %}
{% set end_public_holiday = state_attr('calendar.jours_feries_en_belgique','end_time') | as_datetime | as_local %}

{% if ( is_weekend ) 
      or ( tomorrow == start_school_day_off  )
      or ( (is_school_holiday)
           and (today != end_school_day_off) 
      or ( tomorrow == start_public_holiday)
      or ( (is_public_holiday)
           and (today != end_public_holiday) 
{% else %}
{% endif %} 

But you’ll have to setup a calendar (google, or since latest releases of HA, a local one) to manage the holidays.

Using the workday isn’t working for me as I’m also registering the school days off (including strikes …) in the calendar. And public holidays are not the same depending on regions in Belgium.

Finally, workday is in yaml, while the calendar events are much more easier to maintain.
But, it comes with a counterpart : a template code triggered automation.

1 Like

Thanks you. I’ll work my way through these solutions and see what works best. Much appreciated.

This integration has all the public holidays I need and looks quick and easy to config. I have two automations that run on [fri, sat, sun] and I would them to run on public holidays too. Would this be possible over and above running weekday [mon-fri] and excludes [sat, sun, holiday]?

This looks more flexible than workday integration but a little more setup required. I have not ventured into this level of complexity before and will need to investigate template conditions etc…

Thanks for sharing your solution. I may have questions :slight_smile:

Can you please explain how you imported those calendars? I live in France and also want to add school holidays, is this a mere ical?
EDIT: got it… just quite tricky to find and for now only this year 22/23

Feel free if I can help

Well… you have multiple sources, e.g. I live in France but work in CH, Kanton Aargau and sleep-over in Kanton Basel. This brings me 3 calendars if I want to take into account work/shops&services/kids…it depends a bit what you want to do.

You can include and exclude any days you want (see the config examples).
If you have 2 different types of rules, you can create two sensors with different rules.

I have set up second sensor with ‘workdays: [fri, sat, sun, holiday]’ I’m assuming the holiday component can be set as a workday?

EDIT: just been doing some testing and initially I thought this would not work until I noticed the Excludes from original sensor were being copied. I addressed this by placing the ‘excludes:’ entry and leaving it blank for new sensor and now everything is working perfectly in testing.

Thanks for your guidance.

Cheers will copy your setup and make changes from there.