appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

Add `Entity.listen_event`

Open dekiesel opened this issue 1 week ago • 3 comments

Is there an existing feature request for this?

  • [x] I have searched the existing issues

Your feature request

Analogous to Entity.listen_state consider adding a Entity.listen_event-function. This would make usage of Entitys more intuitiv and reduce code overhead since you don't need to extract the entity name from an Entity before listening for events of that entity.

dekiesel avatar Dec 16 '25 14:12 dekiesel

Not sure I follow you with this. I don't think Home Assistant generally emits events directly tied to entities that aren't state changes (state_changed events)

jsl12 avatar Dec 17 '25 03:12 jsl12

Wow this is embarrassing. I've been using appdaemon for at least four years now and your comment made me realize just now that listen_state is just a shorthand for listen_event("state_changed")

Apologies and thanks!

dekiesel avatar Dec 17 '25 07:12 dekiesel

I need to reopen this, unfortunately.

It seems it'd still be good to have an Entity.listen_event, simply because it exposes all of the data of the event.

Example:

def my_cb(self, event_name, data, kwargs):
        #now I can get the time and the user_id so that I can filter.
        user_id = data["metadata"]["context"].get("user_id", None)
        time_fired = self.convert_utc(data["metadata"]["time_fired"])

I can't do that with listen_state

    def my_cb(self, entity, attribute, old, new, kwargs):
        pass

dekiesel avatar Dec 17 '25 10:12 dekiesel