listen_state should take into account entity's `last_changed` for immediate triggers
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.
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…
Yeah that works but it's pretty verbose and seems like something that would have its place in AppDaemon's framework.