Events by Label
Here's a flow inspired by a feature request that listens for state_changed
events with a specific label. This is great for filtering by domain or capturing all events linked to a particular label.
💡 What it does:
- Listens for
state_changed
events in Home Assistant. - Filters events based on a defined label.
- Option to filter by domain or capture all events with that label.
[{"id":"56092aa4390d93bf","type":"ha-api","z":"3aa045026af17229","name":"entities","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/entity_registry/list\"}","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":540,"y":304,"wires":[["9227dd2dc5056d39"]]},{"id":"9227dd2dc5056d39","type":"function","z":"3aa045026af17229","name":"","func":"const entities = {};\n\nmsg.payload.forEach((e) => { \n entities[e.entity_id] = e.labels;\n});\n\nmsg.payload = entities;\nmsg.update = true;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":724,"y":304,"wires":[["072d3e5fd5e540cb"]]},{"id":"072d3e5fd5e540cb","type":"function","z":"3aa045026af17229","name":"add label","func":"if(msg.update) {\n node.status({fill:\"green\", shape: \"dot\", text: \"data loaded\", })\n context.set(\"data\", msg.payload);\n return;\n}\nconst data = context.get(\"data\");\n\nif(!data) {\n node.status({fill:\"red\", shape: \"ring\", text: \"no data\", })\n return;\n}\n\nmsg.labels = data[msg.payload.entity_id];\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":352,"wires":[["666d393a4c0cb248"]]},{"id":"55b25821a65fcdde","type":"server-events","z":"3aa045026af17229","name":"on connect","server":"","version":3,"exposeAsEntityConfig":"","eventType":"home_assistant_client","eventData":"","waitForRunning":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":172,"y":304,"wires":[["2f3c8ac155fe3383"]]},{"id":"2f3c8ac155fe3383","type":"switch","z":"3aa045026af17229","name":"connected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"running","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":374,"y":304,"wires":[["56092aa4390d93bf"]]},{"id":"ba967a32b033e303","type":"server-events","z":"3aa045026af17229","name":"entity_registry_updated","server":"","version":3,"exposeAsEntityConfig":"","eventType":"entity_registry_updated","eventData":"","waitForRunning":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":212,"y":256,"wires":[["56092aa4390d93bf"]]},{"id":"afb909fb7dfdcf47","type":"server-events","z":"3aa045026af17229","name":"","server":"","version":3,"exposeAsEntityConfig":"","eventType":"state_changed","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":212,"y":352,"wires":[["072d3e5fd5e540cb"]]},{"id":"01591113936768d5","type":"inject","z":"3aa045026af17229","name":"manual update","props":[],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":206,"y":208,"wires":[["56092aa4390d93bf"]]},{"id":"666d393a4c0cb248","type":"switch","z":"3aa045026af17229","name":"labels to watch for","property":"labels","propertyType":"msg","rules":[{"t":"cont","v":"lights","vt":"str"},{"t":"cont","v":"random_stuff","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":602,"y":352,"wires":[["972412bcf4727a99"],["87c4e2b7970975bd","7f08bcaf874489bf"]]},{"id":"87c4e2b7970975bd","type":"switch","z":"3aa045026af17229","name":"filter by domain","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"regex","v":"^light.","vt":"str","case":false},{"t":"regex","v":"^switch.","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":2,"x":816,"y":448,"wires":[["b79d2219a9d190c3"],["7fe6ea5d9b84d446"]]},{"id":"972412bcf4727a99","type":"link out","z":"3aa045026af17229","name":"events with \"lights\" label","mode":"link","links":["852b8bf86a74dce5"],"x":844,"y":352,"wires":[],"l":true},{"id":"b79d2219a9d190c3","type":"link out","z":"3aa045026af17229","name":"events with \"random stuff\" label and light domain","mode":"link","links":["a936f44cd50ff333"],"x":1138,"y":448,"wires":[],"l":true},{"id":"7fe6ea5d9b84d446","type":"link out","z":"3aa045026af17229","name":"events with \"random stuff\" label and switch domain","mode":"link","links":["6329fdc276129897"],"x":1138,"y":496,"wires":[],"l":true},{"id":"7f08bcaf874489bf","type":"link out","z":"3aa045026af17229","name":"events with \"random stuff\" label","mode":"link","links":["63e253fa6c8e08f1"],"x":866,"y":400,"wires":[],"l":true},{"id":"852b8bf86a74dce5","type":"link in","z":"3aa045026af17229","name":"state_changed event for \"lights\" label","links":["972412bcf4727a99"],"x":264,"y":544,"wires":[["aa74be0a11e1d63d"]],"l":true},{"id":"aa74be0a11e1d63d","type":"debug","z":"3aa045026af17229","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":544,"wires":[]},{"id":"a936f44cd50ff333","type":"link in","z":"3aa045026af17229","name":"events with \"random stuff\" label and light domain","links":["b79d2219a9d190c3"],"x":296,"y":592,"wires":[["b5a888fa9acdabc0"]],"l":true},{"id":"b5a888fa9acdabc0","type":"debug","z":"3aa045026af17229","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":582,"y":592,"wires":[]},{"id":"6329fdc276129897","type":"link in","z":"3aa045026af17229","name":"events with \"random stuff\" label and switch domain","links":["7fe6ea5d9b84d446"],"x":306,"y":640,"wires":[["3dfddc440cb1a5aa"]],"l":true},{"id":"3dfddc440cb1a5aa","type":"debug","z":"3aa045026af17229","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":640,"wires":[]},{"id":"63e253fa6c8e08f1","type":"link in","z":"3aa045026af17229","name":"events with \"random stuff\" label","links":["7f08bcaf874489bf"],"x":246,"y":688,"wires":[["bf5aca1357af9a13"]],"l":true},{"id":"bf5aca1357af9a13","type":"debug","z":"3aa045026af17229","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":582,"y":688,"wires":[]}]