Next holiday sensor

Sorry you are right, I didn’t make that plain.

Makes sense, thanks for the feedback. Glad it works.

So I made something like this using templates, one issue I ran into is that I would jump to the next holiday on the day of a current holiday, making automations useless. Is that what you’re doing here (haven’t looked at the code)

I anticipated that. The sensor state will remain on the holiday until the day after the holiday. So it’s more of a ‘next or current’ holiday sensor.

Relevant code here.

2 Likes

Does the sensor only show Holidays up to this year? Is it possible to show whatever python holiday has for next year as well?

Edit:

 
 ​        ​if​ ​next_holiday_date​ ​is​ ​None​: 
 ​            ​# lookahead into the next year 
 ​            ​holiday_data​.​update​(​_load_holidays​(​today​.​year​ ​+​ ​1​, ​self​.​_config​)) 
 ​            ​next_holiday_date​ ​=​ ​_find_next_holiday​(​today​, ​holiday_data​)

Would it be possible for us to pass in a config, eg if next holiday has only 3 in the list, start pulling from next year?

1 Like

Sure that’s totally doable. As you found we already do lookahead into the next year if there are no future holidays in the current year. But making that configurable is a great idea. Thanks for the suggestion.

Ok I have added and released a new optional global config option min_future_holidays that you can use for this.

Config example:

sensor:
  - platform: next_holiday
    min_future_holidays: 3
    sources: 
     - country: "USA"
       state: "WA"
       exclude:
         - "washington's birthday"
1 Like

This is pretty cool and useful for me, especially knowing when Thanksgiving is in the US. One question, though, in looking at the code and the result, it looks like you are examining the current year (i.e., Thanksgiving is showing up even though it has passed). I haven’t installed this yet, so maybe that was an old screenshot, but are you looking at a 12 month moving window or just the current year?

The holidays attribute includes all holidays of this and maybe next year. We do compute only ‘future holidays’ as well (and choose the first as the state) but we don’t expose that information as its own attribute. Would just a list of future holidays be useful? What kind of use case might people have for that? Easy to add if we want.

Well, for me at least, having a moving 12 month window from perhaps 30 days back to 11 months future would be pretty good. My use-case is also somewhat for holiday lighting because knowing the day after thanksgiving means I know when my lights turn on automatically. Right now I have an input-datetime that I plug in the next day-after-thanksgiving and I generally set it around October.

There are other great use-cases for knowing future holidays, such as blocking out calendars for long weekends in HA or auto-planning vacations based on “hey I take a road trip every Memorial Day”.

That’s a couple of thoughts.

Thank you for the quick implementation! I’ll try it out over the Christmas holidays! :smiley:

It would be awesome if you could add the current holiday as an attribute to the workday sensor in Core.

I like this sensor, but i just wonder, if it’s possible to turn dates around? I mean: 2022-01-22 is USA date form, while in most od EU we use other way around, so it should be 22-01-2022, or even better with dots instead of dashes, like: 22.1.2022.
Any way to do it?

This sensor is great for major holidays but what about Halloween, St. Patricks Day, Valentines Day, etc? Is it possible to add to the holiday list? I used this sensor to automate my outdoor lights based on the upcoming/current holiday. It would be great if this sensor supported non-major holidays and/or if I could add to the list. Thanks!

Hi, I want to create a sensor template which should calculate the last WORKING day of the current month.
For that I need to exclude weekends and holidays. Workday integration is good for evaluation whether today(or day with specified offset from today) is a working day.
But I need to check whether multiple dates (in sequence with steps -1 from last day of the month) are holidays or not. Installation is based on HassOS so the installation of custom components is not so free.

Not going to happen by the looks of it Add Halloween to US Holiday Schedule · Issue #714 · dr-prodigy/python-holidays · GitHub

In case anyone is interested…
This is how I’m using this and Thank you by the way for making this!!! :slight_smile:

I created a sensor like this:

- platform: template
  sensors:
    holiday_time:
      friendly_name: Next upcoming holiday
      value_template: >
        {%- set next = state_attr("sensor.next_holiday", "days_until_next_holiday") -%}
        {% if state_attr("sensor.next_holiday", "today_is_holiday") == false %}
        {%- if next == 1 -%} There is {{ state_attr("sensor.next_holiday", "days_until_next_holiday")}} days until {{ states("sensor.next_holiday") }}
        {%- elif next > 1 -%} There are {{ state_attr("sensor.next_holiday", "days_until_next_holiday")}} days until {{ states("sensor.next_holiday") }}
        {%- endif -%}  
        {% else %}
        Today is {{ states("sensor.next_holiday")}}  
        {% endif %}

So in the front end I get this:
Capture

Just thought I’d share.

4 Likes

Seems to work through HACS if I manually add the repo. If you’re bothered, then you can create a PR for HACS to have your repo added as default here: https://hacs.xyz/docs/publish/include/

One thing to note is that currently your README.md doesn’t currently pull through so you get this displayed, but I’ve just created a PR which should fix that: Update hacs.json to render the README.md by Gadgit83 · Pull Request #4 · partofthething/next-holiday-sensor · GitHub

Before:

After: image

Does anyone have any thoughts on how to use this sensor for custom holidays that don’t fall on the same date every year? I think I was able to come up with a workaround for Easter – adding Canada and the NYSE options as sources allows me to get Good Friday and Easter Monday as holidays. But it would be great to get holidays like Mother’s Day (the 2nd Sunday in May) or Father’s Day (the 3rd Sunday in June). I know the developers of the Python holiday package won’t be adding non-official holidays, but I’m wondering if there’s a way to define these types of holidays manually.

As far as I’m aware, the custom_holidays option only allows you to specify an absolute date. Does anyone know of a way to specify custom holidays like the ones above?

You could have a look at Webcal Guru