appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

[Feature request] Immediate callback from listen_state

Open petertufvesson opened this issue 3 years ago • 1 comments

I find it very common that I want to listen to a specific entity, or attribute of an entity, and then use "listen_state".

But very often my code is also interested to know the initial state of the same entity/attribute. Today I have to solve this by using "get_state", which leads to extra/duplicated code.

My feature request is that "listen_state" gets an option to trigger a callback immediately so my code can capture the initial value via the callback function.

Perhaps listen_state can be extended with a new argument "initial_callback" like this: listen_state(self, callback, entity=None, initial_callback=False, **kwargs)

Or a new function "listen_state_with_initial_callback" can be introduced listen_state_with_initial_callback(self, callback, entity=None, **kwargs)

petertufvesson avatar May 03 '21 09:05 petertufvesson

that feature already exists and its called immediate. see the listen_state docs: https://appdaemon.readthedocs.io/en/latest/AD_API_REFERENCE.html#state

ReneTode avatar May 03 '21 10:05 ReneTode