appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

run_every with start="now" doesn't run immediately

Open Big4SMK opened this issue 8 months ago • 1 comments

What happened?

With the introduction of version 4.5.0 the run_every function changed in behavior regarding the start parameter

before 4.5.0:

start – A Python datetime object that specifies when the initial callback will occur, or can take the now string alongside an added offset. If given in the past, it will be executed in the next interval time.

when passing "now" for start and e.g. a 10 minute interval, the callback would run immediately, and then 10 minutes later, another 10 minutes later, etc.

4.5.0+:

start (str, datetime.time, datetime.datetime, optional) – Start time for the interval calculation. If this is in the future, this will be the first time the callback is triggered. If this is in the past, the intervals will be calculated forward from the start time, and the first trigger will be the first interval in the future.

If this is a str it will be parsed with parse_time().

If this is a datetime.time object, the current date will be assumed.

If this is a datetime.datetime object, it will be used as is.

If you pass the same "now" for start and a 10 minute interval, the first callback run would be in 10 minutes, and then 10 minutes after that, etc. Basically missing the expected immediate run.

Version

4.5.0+

Installation type

Home Assistant add-on

Relevant log output


Relevant code in the app or config file that caused the issue


Anything else?

No response

Big4SMK avatar Jun 25 '25 06:06 Big4SMK

I also have a similar effect with run_in with a delay of zero seconds. In that case, the callback is also not triggered. I'm not sure whether that is the intended behavior.

Just a guess: Those functions scheduling a callback for a later time (read: in 0 seconds). Once the callback should be executed, the expected execution time is already in the past and the callback is not called.

A run_in callback with a delay of 1 second works just fine.

But another thing I just realized while writing this: Using something like now+1 or even now+5 as start for run_every does not workaround the issue just like the short delay for run_in. It just moves the next execution further.

For example, if I configure a callback to be executed every 10 seconds and specify now+5, the first call won't be in 5 seconds but in 15 seconds.

Programie avatar Jul 11 '25 21:07 Programie

Should be fixed by #2518.

cebtenzzre avatar Dec 29 '25 01:12 cebtenzzre