Hi, I have a question about the helper function async_track_point_in_time
. Is the listener guarenteed to be called or not?
I have developed an integration that switches the energy tariffs (peak / off-peak) which are 3 in my country. The helper function needs to be called 3 or 4 times a day at specific “exact” times (o’clock, i.e. with 0 minutes and 0 seconds). For example, I have a sensor value that returns 3 from midnight to 6:59:59 and this value must change to 2 at 7:00:00, then to 1 at 8:00:00 and only at 19:00:00 change to 2 again.
So in my integration I called async_track_point_in_time
at startup (during async_setup_entry
) to schedule the first update (7:00:00 in the example). When it is 7:00:00 the function to update the value is called and the next update is scheduled with another call of async_track_point_in_time
.
In my system it always works perfectly and the listener never miss any execution (I have a log message there to check). But I have some other users that use my integration that sometimes report the missing listener call, so that the value change does not happen and neither the scheduling of the next call (because it’s inside the listener function, which has to calculate the hour when it has to trigger next).
Is this behaviour normal? How can I trigger a change on specific hours and be sure it will run exactly at the xx:00:00 of the clock for every user? Previously I tried with a coordinator that runs every 10 minutes, but I cannot choose the minutes and seconds of the trigger, so I switched to async_track_point_in_time
which solved the problem… but not for everyone, unfortunately.
I noticed from the log of the users with the issue that there are other integrations with errors (for example, some looking for a web query that fails) but… shouldn’t async_track_point_in_time
trigger anyway - maybe with some delay - if Home Assistant is busy with other activities at the scheduled time?
Have you got any suggestions?