If you wanted you could even make it create separate sensors for each special holiday off of the same calendar. It’s pretty flexible. I did the same thing for SmartThings back when I had one of those.
Hi, newbie here and very first post.
Although new to Home Assistant, I have been putting around with home automation for a while. Was a Homeseer user, been using the ISY-994i now for over 2 years, but looking to supplement with something else. I’ve been trying OpenHab but someone pointed me to this solution and I like it already although I haven’t installed it yet.
I’ve been waiting for a few things, integration with Harmony Hub (I see that’s on it’s way) and a way to figure out holidays and birthdays/anniversaries. I like this solution from @fgabriel but I am wondering if there is something missing. How is this script getting triggered? Usually, such a script get triggered at midnight and on startup. Any examples for us newbies would be great. Also the python module Holidays 0.5 … could I also see a snippet of example on how yours is setup? Do we need to specify the year everytime in this file? we all know that xmas is 12/25 of every year. is there a wild card that can be used?
Thanks
Bernie
@berniebl: As far as I know, the sensor will be updated asyncron. You don’t have to define a year. It will always use the current year (year is an optional parameter for python module holidays; if not defined it pick the current year). To use the sensor you have to put following lines in your configuration.yaml - for example:
sensor:
- platform: isholiday
name: Today is a holiday
country: US
province: CA
name and province are optional. Please note, if you use a name, then the sensor will be named in this example sensor.today_is_a_holiday. Province means sometimes state. If you use a province which is not valid for the country, you will receive a error message in the log. Look at https://pypi.python.org/pypi/holidays/0.5 for valid countries and provinces.
Thanks … seems like I have a lot to learn with HA in order to understand all of this, but it will serve me as a good reference. Thanks again
I have just found out from this page that the sensor has to be in directory
custom_components/sensor
And here is Google Calendar Event component
I have tried to upgrade to v0.40 this morning, and I’m getting this error
ERROR:homeassistant.components.sensor:Error while setting up platform isholiday
Traceback (most recent call last):
File "/home/graham/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 148, in _async_setup_platform
entity_platform.async_schedule_add_entities, discovery_info
File "/home/graham/.homeassistant/custom_components/sensor/isholiday.py", line 56, in async_setup_platform
yield from async_add_devices([IsHolidaySensor(obj_holidays, name)], True)
TypeError: 'NoneType' object is not iterable
Any hints on how to fix it?
This error is due to a breaking change in 0.40. According to the release notes:
If you are using async custom components, the passed in async_add_devices method is now a callback instead of a coroutine function.
You have to edit line number 56 and remove the words “yield from”
yield from async_add_devices([IsHolidaySensor(obj_holidays, name)], True)
The line must contain
async_add_devices([IsHolidaySensor(obj_holidays, name)], True)
That’s it.
Thanks. That worked fine.
I am also looking to create a sensor that basically tell me if the a day is a work day or not. Looking at the google calendar event component I do not really understand how to create a “workday” sensor from it.
You’d have to have an all day event on days that are work days. Since it’s triggered off events on a calendar.
Depending on your schedule, it might be easier to setup recurring meetings on days that are not workdays and make your sensor report the absence of a meeting as being a workday.
I just tested this on 0.43.2.
Being new to HA I probably made all the possible erors, but will share here anyway.
My country is Norway (NO) and I noticed this is implemented in later versions of the holidays module, so I just added the country code ‘NO’ to the sensor script (and removed the ‘yield from’ in line 55).
Then I copied your example definition into configuration.yaml like this:
sensor: - platform: isholiday name: Today is a holiday country: NO
It took me a lot of debugging to see that the unquoted NO automagically translated into False, which is why I kept getting an invalid country code error. Adding double quotes around NO solved the problem. So any other Norwegian users out there should use this config entry:
sensor:
- platform: isholiday
name: Today is a holiday
country: "NO"
As much as I like it for convenience, weakly (or dynamically) typed languages sometimes are a real PIA.
Is there any way to use this sensor to check if tomorrow is a workday?
I was looking for the exact same thing.
The solution I found was to add a new config option ‘days_ahead’ specifying the offset in days for which to get the result. Then I just apply this offset to self._date
adding ‘datetime.timedelta(days=self._days_ahead)’
The sensor is defined like this:
- platform: isholiday
name: free.tomorrow
country: "NO"
days_ahead: 1
I have no real knowledge of python or any understanding of customizing Hass, but this seems to work fine for me.
I tried to install this custom components in “custom_components/sensor” folder and after adding:
- platform: isholiday
name: free.tomorrow
country: “US”
days_ahead: 1
and I got this error when restarting:
- Platform not found: sensor.isholiday
Any idea what I’m missing?
For some time there has been a workday binary sensor as component in home-assistant which you can use. You don’t have to define a custom component further. Look at https://home-assistant.io/components/binary_sensor.workday/.
Ah… thank you! Yeah… I already used that sensor… but I was hoping to have a special sensor for holidays
EDIT: after reading more about that workday sensor… I think I can use it for holidays as well… THANKS!
Is there a sensor to display how many days left for a birthday?
there is 2 I found quite interesting.
and