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
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.
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.
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.