Closed rccoleman closed 2 years ago
Thanks. That will not be an easy one š
Yeah, I puzzled over it for a while yesterday and couldn't come up with a clean solution. I started with an automation that triggers on an update to the holidays
calendar to force an update for the garbage_collection
sensor, but there are a lot of gates in way to prevent updates for which the state didn't change. The custom "update_state" service skips the event.
Maybe listening for a custom event in garbage_collection
that's sent by holidays
when it updates? Or listening for homeassistant_started
in garbage_collection
, although I don't know whether that happens late enough.
I can't make garbage_collection depending on holidays, many people don't use this integration. I wonder why the list of holidays is empty - I thought it should get the list from the last update. So even garbage collection triggers the event before holidays get updated, it should get the list anyhow. It does not change. Other option is to wait for the holidays update in the automation blueprint?
It definitely starts empty at startup every time and is then populated. Maybe also derive from RestoreEntity and populate the state & attributes with async_get_last_state
and async_get_last_extra_data
? That way, you can probably populate once at setup and whenever the config changes, but have the state & attributes available when the entities are added to hass.
It looks like you use that in garbage_collection
, but not in holidays
.
All right, try the Holidays beta 1.8.0b1. I did not Manage to restore the whole calendar with its entities, but I am loading at least the list of holidays that is used by the blueprint. The calendar is refreshed shortly after anyhow. So this should do. To test, you might want to restart twice (after the first restart it might not store the state as it will still be a standard entity).
Excellent, testing now! I can clearly see the saved state in core.restore_state
, so at least that part is working.
If this is solved by tne new release, please close it. Thanks.
It looks like it's working based on my limited testing, so I'll close it. Thanks for the quick turnaround!
Before you submit a new bug report, please check that
Describe the bug
I noticed over the last weekend that the July 4th holiday on Monday in the US didn't move my Monday garbage collection to Tuesday as expected, so I enabled debug and tried to get to the bottom of it. It looks like there's a potential race condition between the
holidays
integration and this one where thegarbage_collection_loaded
event can be fired before the holiday list is populated by theholidays
integration, causing themove_on_holiday
blueprint to run with an empty list and do nothing useful. The issue seems very timing-dependent, and is most likely to happen following an HA update when requirements are being installed. Once everything is installed and the boot process settles down from run to run, everything is updated/moved as expected.It's difficult to reproduce and I'm trying to capture logs of the situation, but it happened again earlier today with the release of 2022.7.0b4. I added some of my own logging to the
move_on_holiday.yaml
blueprint and monitored the HA logs and clearly saw that the blueprint automation was running before theholidays
integration had populated itsholidays
attribute, and the automation was running with a blank one. In the failing case, the following lines:came after the
garbage_collection
integration had its update method called and fired the event for the blueprint automation, and my additional logging showed that theholidays
attribute was blank when the automation ran. I toyed with addedholidays
as a dependency forgarbage_collection
in the manifest and it worked properly on the next boot, but then it still worked fine after removing it. It didn't look like it was doing the required sequencing based on the logs anyway.There are probably a few ways to address this, but I wanted to get this report in while I think about the best thing to do.
Configuration
I have two instances, but this is the one that should have moved the date from Monday to Tuesday yesterday:
Debug logs
Initial setup of the holidays integration:
Initial setup of the garbage_collection integration:
The garbage_collection integration updates & fires the event to kick off the blueprint automation:
As the automation iterates through the holiday list, you can see it come across 2022-07-04, which is a holiday:
I added some debug there to indicate that the "holidays" attributes exists ("Loaded? True"), but the attribute itself is blank ('holidays': {}). Sure enough, the last line determines that July 4 is not a holiday.
Later, after the automation finishes, I finally get this:
Now, the "holidays" attribute is finally populated, but it's too late for the automation.