I would like to create a holiday sensor 1 week in advance. I’ve came up with this. It works, but will display the last holiday until the next one occurs. It poses an issue when HA reboots or restarts causing the automation to retrigger. When there is no holiday 1 week out, I want it to state none. Is this possible? I have tried a few ways, but does not work.
Hi. Thank you for your aide. This is my final code. Instead of waiting until midnight for testing, I have the time triggered in real time. There is no holiday in the up coming week.
Upon adding the code and a reboot, the state shows unknown.
When I have it trigger in real time with the time trigger, the state changed to unavailable.
When I restart HA, the state shows unknown.
I think there will be an error. If the time trigger executed, then there will be no trigger.calendar_event and the template will fail with a “trigger has no attribute” message.
Logger: homeassistant.helpers.sensor
Source: helpers/template_entity.py:596
First occurred: 1:05:00 PM (6 occurrences)
Last logged: 3:41:00 PM
Error rendering state template for sensor.holidayinaweek_g: UndefinedError: 'dict object' has no attribute 'calendar_event'
Error rendering state template for sensor.holidaytomorrow_g: UndefinedError: 'dict object' has no attribute 'calendar_event'