appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

listen_state should take into account entity's `last_changed` for immediate triggers

Open Ten0 opened this issue 1 year ago • 2 comments

Is there an existing feature request for this?

  • [X] I have searched the existing issues

Your feature request

Currently, for immediate listen_states, AppDaemon will wait at least the specified duration after AppDaemon's start (or trigger creation) before running the trigger, even if we can know that we can actually wait for less time and still be sure that the state we are listening for has not changed for longer than that time.

To solve this, when registering a listen_state, we could look at entity's last_changed that comes back from HomeAssistant's API when choosing how long to actually wait for. This would make such triggers survive AppDaemon reboots/reloads much better, as it would mean that such triggers could typically recover their "I've already waited for this long" state.

Ten0 avatar Dec 27 '24 01:12 Ten0

My current approach is to have two listeners one for immediate and another with the wait duration. In the callback function I check the last updated attribute and decide what to do…

runningman84 avatar Feb 28 '25 16:02 runningman84

Yeah that works but it's pretty verbose and seems like something that would have its place in AppDaemon's framework.

Ten0 avatar Mar 02 '25 21:03 Ten0