Just remove remove_holidays. You’re excluding holidays already in the excludes line.
binary_sensor:
- platform: workday
country: US
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun, holiday]
^
Just remove remove_holidays. You’re excluding holidays already in the excludes line.
binary_sensor:
- platform: workday
country: US
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun, holiday]
^
That’s the problem, if you put holiday in the excludes list it excludes days like Presidents day which is a work day for me and most other people. If you remove holiday from the excludes list there are no holidays, not even days like Christmas or Thanksgiving even if you put them in a add_holiday list.
Then remove that from excludes and add your excluded holidays under remove_holidays.
binary_sensor:
- platform: workday
country: US
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun]
remove_holidays:
- '2021-02-15'
- '2021-02-22'
- '2021-04-02'
- '2021-04-05'
- '2021-10-11'
- '2021-11-11'
Your missing the point I’m trying to make. If you put remove_holiday in the sensor setup you will no longer have a workday sensor at all. HA does not recognize that in the config and it does not create the sensor at all even though it says this is a valid part of the setup in the documentation for the workday sensor.
Then why did your original post have the mutually exclusive configuration in it?
Posting 101: Post your real configuration when asking a question.
If the point of the post was to point out bad documentation, make the change. There’s a guide on how to do that and it’s very easy.
Is this bad documentation or is this something that is supposed to work but does not. If you look at the code for the workday sensor on Github it says that it added the function to remove workdays.
I’m trying to show the setup that does not work even thought it follows the documentation exactly. And this is my real configuration that does not work.
If you exclude all holidays, then there’s no holidays to remove. The configuration shouldn’t work.
You’re welcome to write up an issue, from what I know about voluptuous it can be fixed so that the configuration checker finds it.
I tried this workday sensor and found it lacking. I wrote my own sensor that uses a manually updated array of holidays. Yes, it’s manual, but it also only needs updated once a year with my next year’s non-weekend holidays.
date_workday:
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% set date = states('sensor.date') %}
{% set holidays = {
'2021-01-01' : '1',
'2021-05-31' : '1',
'2021-07-05' : '1',
'2021-09-06' : '1',
'2021-11-25' : '1',
'2021-12-23' : '1',
'2021-12-24' : '1',
'2022-01-01' : '1'} %}
{% if 'Saturday' in ct | timestamp_custom("%A") %}
off
{% elif 'Sunday' in ct | timestamp_custom("%A") %}
off
{% elif holidays[date] == '1' %}
off
{% else %}
on
{% endif %}
I created some time ago, so I’m sure it could be streamlined / improved - but, “If it ain’t broke, don’t fix it”
It can be optimized a bit, not sure if it’s for the better. Changing the dictionary into a list definitely makes ‘adding a date’ easier in the future. As_timestamp can now analyze strings directly too.
date_workday:
value_template: >
{% set date = states('sensor.date') %}
{% set today = as_timestamp(date) | timestamp_custom("%A") %}
{% set holidays = [
'2021-01-01',
'2021-05-31',
'2021-07-05',
'2021-09-06',
'2021-11-25',
'2021-12-23',
'2021-12-24',
'2022-01-01',
] %}
{% if today == 'Saturday' %}
off
{% elif today == 'Sunday' %}
off
{% elif date in holidays %}
off
{% else %}
on
{% endif %}
could be even a tiny bit smaller?:
{% if today in ['Saturday','Sunday'] or
date in holidays %}
off
{% else %}
on
{% endif %}
Thank you for the help. I like this idea much better since I don’t get off most “holidays” anyway, plus I need to edit it manually to add vacation days. My question is how to add it and how to use it.
I tried to add it to my configuration.yaml under the binary_sensor section and outside of the sensor section but no matter where I put it it does not seem to like it.
Also, to use it I assume I just check if date_workday is on or off, correct?
Here’s a simple way to create a “Holiday Binary Sensor” using a Template Binary Sensor.
binary_sensor:
- platform: template
sensors:
holiday:
friendly_name: 'Holiday'
value_template: >
{% set holidays = [
'2021-01-01',
'2021-05-31',
'2021-07-05',
'2021-09-06',
'2021-11-25',
'2021-12-23',
'2021-12-24',
'2022-01-01'] %}
{{ now().isoweekday() in [6, 7] or now().date()|string in holidays }}
It will report on
if the current weekday is Saturday or Sunday or if the current date matches any in the holidays
list.
That is exactly what I am looking for. Thank you everyone for all your help.
I have same problem with “remove_holidays”.
I will add new binary sensor for fixing this bug.
Seems adding remove_holidays
with any valid non-holiday day causes the integration not to load and pukes an error:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 200, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/workday/binary_sensor.py", line 105, in setup_platform
obj_holidays.pop(date)
File "/usr/local/lib/python3.8/site-packages/holidays/holiday_base.py", line 158, in pop
return dict.pop(self, self.__keytransform__(key))
KeyError: datetime.date(2021, 3, 18)
Testing on latest version of HA OS, i might not have enough skills to pinpoint the exact problem but seems to have issues out of the box. Haven’t filed a bug yet or searched for an existing one.
I have same problem with “remove_holidays"…
version HA: 2021.2.3