WebSocket Filter Events by entity_id

Is it possible to only receive events for a specified entity_id?

1 Like

Not sure if this is of help… I am far from an expert, but from my exploring it seems that the hierarchy of events is ‘event_type’ is at the top and you can get ‘entity_id’ at multiple places below that. For example in ‘state_changed’ event you get ‘entity_id’ three times within the ‘state_changed’ packet. Seems like you get the raw stream of all events, but you would need to look for ‘entity_id’ attribute in all packets and then if found filter for the entities you are interested in, but work seem to be on plate not HA. The utility ‘hass-cli’ is a useful tool to explore HA objects, events and other structure:

hass-cli  --output=json  event watch

https://github.com/home-assistant-ecosystem/home-assistant-cli

Yeah thank you. I did this already to filter on the WebSocket Client. But i wished i were able to register Events only to one specified entity_id, so i have not so much events on my small size client, currently i have to waste CPU time for filtering.

1 Like

Agreed. Seems like a useful function for the HA devs to add to core. Especially as more and more devices are published useful and weird events and at firehose rate.

Just curious, if I read your post correctly. How do you go about finding what web socket endpoint are available? I stumbled across one of use to me. But I do not see a way to find the ‘catalog’ of all. Thx!

I just saw this on github, might be your posting, but it seems in line with your thinking. You might want to participate in that discussion, kind of over my pay grade :wink:

Allow components to register events in the websocket API #488

1 Like

This seems now possible

            subscribe_payload = {
                "id": 1,
                "type": "subscribe_entities",               
                "entity_ids": ["binary_sensor.my_device_occupancy"]
            }

Interesting. Can you share more info in how you are using this in code? Thx.