Support for platform workday templating on add_holidays


As discussed on this issue:

The yaml:

  - platform: workday
    country: PT
      - '{{ 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/", line 75, in __keytransform__
    key = parse(key).date()
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/", line 1358, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/dateutil/parser/", 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/", line 126, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.7/asyncio/", line 416, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/workday/", line 100, in setup_platform
  File "/usr/local/lib/python3.7/site-packages/", line 151, in append
    return self.update(*args)
  File "/usr/local/lib/python3.7/site-packages/", line 146, in update
    self[item] = "Holiday"
  File "/usr/local/lib/python3.7/site-packages/", line 130, in __setitem__
    if key in self:
  File "/usr/local/lib/python3.7/site-packages/", line 87, in __contains__
    return dict.__contains__(self, self.__keytransform__(key))
  File "/usr/local/lib/python3.7/site-packages/", 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:

  - platform: workday
    country: DE
    workdays: [mon, wed, fri]
    excludes: [sat, sun, holiday]
      - '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?


Eventually, that could also be a good option.


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