Quickest way to set holiday dates in boolean for automation

I have an “on_holiday” input boolean which I use to trigger various automations while I’m away. I’d like to automatically set and unset this boolean at the start and end of the holiday. I’ve created an automation to set the boolean when the holiday starts - e.g. at 11:15am on September 25th. Is this the most efficient way to achieve the one-off setting of this boolean? (I want to avoid creating an automation which runs more often than is needed)

alias: Set holiday start date-time
description: ""
trigger:
  - platform: time
    at: '11:15:00'
condition:
  - condition: template
    value_template: >
      {% set n = now() %}
      {{ n.year == 2022 and n.month == 9 and n.day == 25  }}
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.on_holiday
mode: single

Why not use this as a trigger?

{% set n = now() %}
{{ n.year == 2022 and n.month == 9 and n.day == 24 and n.hour == 11 and n.minute == 15 }}

I use a input.datetime helper for my holiday so I don’t have to fiddle around with yaml each time to change my holiday period

Depending on how many holidays you’re trying to do and whether they are mostly “standard” holidays for your area, you might want to look at the workday sensor. It uses a python module that figures out holidays for your area. You can add or delete holidays and include whatever days you want as your work week. So if you just want to track holidays and not weekends, every day of the week would be a workday.

Then you could just look for a change in the workday sensor and set the input_boolean to the opposite of the workday sensor. The workday sensor updates daily just after midnight if I remember correctly.

One note about the workday sensor documentation. The first example in the full examples is flat out wrong. It doesn’t work, nor is it supposed to. Just pretend it doesn’t exist and look at the other examples. I submitted a bug report for that issue in the docs, but it hasn’t been addressed yet.

You could also use a Google Calendar and drive holiday based on a calendar event.

Is it always 11:15 you want the holidays to start?
Or could it be 00:00 and that’s good enough?

Many thanks for all the suggestions. I hadn’t explored input.datetime helpers before. I think I’ll use that (helpers for holiday start/end dates), add it to my dashboard, and use them to trigger the setting of the boolean.

Instead of using an automation to set an input_boolean, you can create a Trigger-based Template Binary Sensor.

template:
  - trigger:
      - platform: time
        at: '00:00:00'
    binary_sensor:
      - name: Holiday
        state: >
          {{ (now().month, now().day) in
             [(1,1), (5,31), (12,24), (12,24)] }}

It updates at the beginning of each day and reports on if the current month and day matches one of the dates contained within the list. Otherwise it reports off.

It can also be easily enhanced to update for other events like startup (or a reload of Template Entities) by simply adding the appropriate trigger.

  - trigger:
      - platform: time
        at: '00:00:00'
      - platform: homeassistant
        event: startup

Or just use the Workday Binary Sensor as has already been suggested by pkscout.

2 Likes

The simplest method I can think of is to have a input_text like this:

This entity can now be placed on the dashboard for easy editing.

Then in the automation have it trigger on (or have condition) a template:

{{ now().date() | string in  states('input_text.dates').split(",") }}

EDIT, you actually don’t need the .split(",") and it’s actually better without it.

1 Like