Support for platform workday templating on add_holidays

Hi.

As discussed on this issue: https://github.com/home-assistant/home-assistant/issues/23831

The yaml:

  - platform: workday
    country: PT
    add_holidays: 
      - '{{ now().strftime("%Y") }}-06-13'

Generates an error:

Error while setting up platform workday

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 75, in __keytransform__
    key = parse(key).date()
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1358, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 649, in parse
    raise ValueError("Unknown string format:", timestr)
ValueError: ('Unknown string format:', '{{ now().strftime("%Y") }}-06-13')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/workday/binary_sensor.py", line 100, in setup_platform
    obj_holidays.append(add_holidays)
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 151, in append
    return self.update(*args)
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 146, in update
    self[item] = "Holiday"
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 130, in __setitem__
    if key in self:
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 87, in __contains__
    return dict.__contains__(self, self.__keytransform__(key))
  File "/usr/local/lib/python3.7/site-packages/holidays.py", line 77, in __keytransform__
    raise ValueError("Cannot parse date from string '%s'" % key)
ValueError: Cannot parse date from string '{{ now().strftime("%Y") }}-06-13'

Templating would allow to add static holidays, regardless the year, as the example above. Instead of the proposed one on the current documentation: https://www.home-assistant.io/components/workday/

binary_sensor:
  - platform: workday
    country: DE
    workdays: [mon, wed, fri]
    excludes: [sat, sun, holiday]
    add_holidays: 
      - '2018-12-26'
      - '2018-12-31'

Surely a better option would be for the year to be ommited entirely, given that they (Easter and a few others notwithstanding) generally fall on the same date each year?

Hi.

Eventually, that could also be a good option.

Thanks.

Any update on this? You won’t need it for Easter since it is covered by the country-specific holidays (isn’t it?), but I’d like to add December 24 as a holiday for each year.

1 Like