New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Calendar timing issues -- event trigger, on-off state, and event details not synchronous #111147
Comments
Hey there @allenporter, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) local_calendar documentation |
Event triggers were added because you can't do what you want with state attributes and it doesn't handle cases like overlapping or multiple concurrent events at once. Event triggers should be used instead of the state, and not combined together. You can query the calendar using the get events service call if you need additional upcoming events, and parse the results with service responses. |
Note the guidance on https://www.home-assistant.io/integrations/calendar which says to use triggers instead of state, and it describes the get events service for more detail. |
Thanks. I cannot use the trigger event data for the reasons explained in post 1. I am already using the event triggers to trigger the automation, not the on/off state, but I do test the on/off state to discover whether there is any active event. That is in practice less problematic because there is little chance I would do that within the 4 second lag, but there is a small theoretical chance of an incorrect result. To read the data of the current event (by my definition), I could probably use the calendar.get_events service call to return all active events from now until 1 second in the future then sort the response data to pick the one that started latest? Would that do what I am looking for? I would have to try it out to check. I could also use that instead of calendar state to determine if there are any events at all. I am not sure that invalidates my issue because it is a lot more complicated than just reading the calendar attributes. It feels more like a workaround. Is there a good reason for the lags between the event start, the change of state, and the availability of the event details in the calendar attributes? |
I did not recommend using state changes at all because they don't cover all the cases, don't handle overlapping events such as all day events, or concurrent events. They can't both reflect an end event and a start event at the same time. Triggers are implemented differently so they can handle all the cases correctly. Triggers can represent events that state changes cannot. I think you should acknowledge that what you are doing is very advanced and embrace the advanced APIs of querying events on the calendar that have no caveats. |
@allenporter "I think you should acknowledge that what you are doing is very advanced..." -- Er .... if you like (!), but I have a genuine need and I think I am exploiting the power of Local Calendar demonstrating how this marvellous innovation can be used to schedule temperatures for a heating system. I have 18 calendars, one for each room. If you think the state and calendar attribute should not be used you should say so in the documentation, with a relevant warning on the limitations. It took me a long while to figure it out! With a lot of help of the Home Assistant Community forum I have come up with what appears to be a robust solution for my requirement based only on calendar event start and end triggers and the calendar.get_event service. My requirement is get the currently active event that started last and the next event. I also need to test in each case whether there are any. The solution is summarised in the following code, which is from Heating X2 blueprint It appears at the start of the automation, so runs whatever the trigger is (start_event, end_event and several others).
The rest of the automation uses the four variables I set.
Other templates refer to
... and similarly for I have the required temperature in the description between two hashes, so that is extracted as
|
See the documentation at https://www.home-assistant.io/integrations/calendar/ which does not document state. It calls out the limitations and only documents how to use the trigger and get events service. For context, a couple years ago only the state existed and it didn't really work for handling cases users needed for automations. I added the trigger and get events service to be able to support these more complex cases. (e.g. being able to determine things about future events like "do i need my car today") Thanks for sharing your solution. Closing this issue since continuing discussion in the community forums is the right place. |
The problem
At the start of an event I expect the following to happen at the same time
Similarly, at the end of an event I expect the following to happen at the same time
The issue is that these actually do NOT happen at the same time. The event start/end triggers occur at the correct time and details are available in the trigger attributes, but I measured a typical 4 seconds lag before the calendar state change to on/off and by experimentation I found that sometimes, 30 seconds after the event has started the details of that event are still not in the calendar attributes - they are blank or still set for the previous contiguous event.
The trigger attributes are correct but I need repeated access to the information throughout the duration of the event, and storing it myself in helpers or a file is unnecessarily complicated -- I originally made a working solution with 4 helpers per calendar but that makes for an over-complicated blueprint and system when there are several calendars. My current workaround is to poll the calendar every minute, but that is inaccurate and not very efficient.
The fix I am looking for is that event start, state change, and availability of the event details in calendar attributes all happen at exactly the times that the event is scheduled. These times are known in advance so the necessary processing time can be planned in advance.
What version of Home Assistant Core has the issue?
24.02.2
What was the last working version of Home Assistant Core?
None. I believe this issue has always been there since Local Calendar was introduced.
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Local Calendar
Link to integration documentation on our website
No response
Diagnostics information
None available. My figures were obtained fro traces during testing.
I guess one would have to create a custom automation that writes a log file to measure exact timings over a period of time.
Example YAML snippet
Not applicable
Anything in the logs that might be useful for us?
Additional information
I discovered this while testing the Heating X2 blueprint
The text was updated successfully, but these errors were encountered: