This is a modified version of Get state_changed Events Based on Area | node-red-contrib-home-assistant-websocket
[{"id":"cb4710e25393bf2a","type":"inject","z":"892eaca92f0b4509","name":"kitchen","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"kitchen\"}","payloadType":"json","x":226,"y":512,"wires":[["631d2715a44c822a"]]},{"id":"1c1ad28af6565ae0","type":"debug","z":"892eaca92f0b4509","name":"debug 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":708,"y":512,"wires":[]},{"id":"631d2715a44c822a","type":"link call","z":"892eaca92f0b4509","name":"","links":["d8335751137d9b1f"],"linkType":"static","timeout":"30","x":502,"y":512,"wires":[["1c1ad28af6565ae0"]]},{"id":"25ea45b9a197ebee","type":"inject","z":"892eaca92f0b4509","name":"kitchen light","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"kitchen\", \"domain\": \"light\"}","payloadType":"json","x":246,"y":560,"wires":[["631d2715a44c822a"]]},{"id":"c8ee1c4ec5b54fad","type":"inject","z":"892eaca92f0b4509","name":"bedroom","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"bedroom\"}","payloadType":"json","x":236,"y":656,"wires":[["631d2715a44c822a"]]},{"id":"de1a3368a45da440","type":"inject","z":"892eaca92f0b4509","name":"bedroom switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"bedroom\", \"domain\": \"switch\"}","payloadType":"json","x":256,"y":704,"wires":[["631d2715a44c822a"]]},{"id":"b5d2b2181056ad85","type":"inject","z":"892eaca92f0b4509","name":"kitchen light on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\":\"kitchen\",\"domain\":\"light\",\"rules\":[{\"property\":\"state\",\"logic\":\"is\",\"value\":\"on\",\"valueType\":\"str\"}]}","payloadType":"json","x":256,"y":608,"wires":[["631d2715a44c822a"]]},{"id":"4b59abd714c85582","type":"inject","z":"892eaca92f0b4509","name":"not an area","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"not an area\"}","payloadType":"json","x":242,"y":464,"wires":[["631d2715a44c822a"]]},{"id":"206de99787a0ba25","type":"inject","z":"892eaca92f0b4509","name":"bedroom kitchen lights","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"bedroom,kitchen\", \"domain\": \"light\"}","payloadType":"json","x":276,"y":752,"wires":[["631d2715a44c822a"]]},{"id":"cdf27cc16137e71a","type":"inject","z":"892eaca92f0b4509","name":"bedroom kitchen lights switches","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"area\": \"bedroom,kitchen\", \"domain\": \"light, switch\"}","payloadType":"json","x":306,"y":800,"wires":[["631d2715a44c822a"]]},{"id":"fa7ec3d063bfa2f3","type":"group","z":"892eaca92f0b4509","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["86c9e07cb01eec87","399cdb2310ef8964","03595b0f5a9a1d79","56092aa4390d93bf","8f6065e3a6ca3da7","9227dd2dc5056d39","072d3e5fd5e540cb","55b25821a65fcdde","2f3c8ac155fe3383","ba967a32b033e303","fe32233ac9184597","1afd1e966bd0aeb7","45e4dae99ba35745","17ea8e982fa2d280","d8335751137d9b1f","d096314b2fe43404"],"x":114,"y":103,"w":1078,"h":322},{"id":"86c9e07cb01eec87","type":"ha-api","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"areas","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/area_registry/list\"}","dataType":"json","responseType":"json","outputProperties":[{"property":"areas","propertyType":"msg","value":"","valueType":"results"}],"x":446,"y":336,"wires":[["03595b0f5a9a1d79"]]},{"id":"399cdb2310ef8964","type":"inject","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"Manual Update","repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":252,"y":336,"wires":[["86c9e07cb01eec87"]]},{"id":"03595b0f5a9a1d79","type":"ha-api","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"devices","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/device_registry/list\"}","dataType":"json","responseType":"json","outputProperties":[{"property":"devices","propertyType":"msg","value":"","valueType":"results"}],"x":586,"y":336,"wires":[["56092aa4390d93bf"]]},{"id":"56092aa4390d93bf","type":"ha-api","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"entities","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/entity_registry/list\"}","dataType":"json","responseType":"json","outputProperties":[{"property":"entities","propertyType":"msg","value":"","valueType":"results"}],"x":730,"y":336,"wires":[["9227dd2dc5056d39"]]},{"id":"8f6065e3a6ca3da7","type":"debug","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1076,"y":336,"wires":[]},{"id":"9227dd2dc5056d39","type":"function","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"","func":"const entities = {};\n\nmsg.entities.forEach(e => { \n const areaId = e.area_id ?? (e.device_id && msg.devices.find(d => d.id === e.device_id).area_id); \n if(!areaId) { \n return;\n }\n\n const area = msg.areas.find(a => a.area_id === areaId);\n if(area) {\n entities[e.entity_id] = {\n areaId: area.area_id,\n name: area.name,\n domain: e.entity_id.split(\".\")[0]\n };\n }\n});\n\nmsg.payload = entities;\nmsg.update = true;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":896,"y":336,"wires":[["8f6065e3a6ca3da7","072d3e5fd5e540cb"]]},{"id":"072d3e5fd5e540cb","type":"function","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"data","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 msg.payload = false;\n return msg;\n}\n\nconst area = toArray(msg.payload.area);\nconst entityDomain = toArray(msg.payload.domain);\n\nif(area.length === 0) {\n msg.payload = []; \n return [null, msg];\n}\n\nconst ids = Object.entries(data).filter(([entityId, {name, domain}]) => { \n if (entityDomain.length && !entityDomain.includes(domain)) return false;\n if(!area.includes(name.toLowerCase())) return false;\n\n return true;\n}).map(i => i[0]);\n\nif(ids.length === 0) {\n msg.payload = [];\n return [null, msg];\n}\n\nmsg.payload.rules ??= [];\n\nmsg.payload = { \n rules: [...msg.payload.rules, \n {\n \"property\": \"entity_id\",\n \"logic\": \"includes\",\n \"value\": ids.join(\",\"),\n \"valueType\": \"str\"\n }\n ]\n};\n\nreturn msg;\n\nfunction toArray(str = \"\") {\n return str.toLowerCase().split(\",\").map(a => a.trim()).filter(i => i) ?? [];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":446,"y":384,"wires":[["d096314b2fe43404"],["17ea8e982fa2d280"]]},{"id":"55b25821a65fcdde","type":"server-events","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"On Connect","server":"","version":2,"eventType":"home_assistant_client","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":210,"y":288,"wires":[["2f3c8ac155fe3383"]]},{"id":"2f3c8ac155fe3383","type":"switch","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"connected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connected","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":402,"y":288,"wires":[["86c9e07cb01eec87"]]},{"id":"ba967a32b033e303","type":"server-events","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"entity_registry_updated","server":"","version":2,"eventType":"entity_registry_updated","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":240,"y":144,"wires":[["45e4dae99ba35745"]]},{"id":"fe32233ac9184597","type":"server-events","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"device_registry_updated","server":"","version":2,"eventType":"device_registry_updated","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":250,"y":192,"wires":[["45e4dae99ba35745"]]},{"id":"1afd1e966bd0aeb7","type":"server-events","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"area_registry_updated","server":"","version":2,"eventType":"area_registry_updated","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":240,"y":240,"wires":[["45e4dae99ba35745"]]},{"id":"45e4dae99ba35745","type":"trigger","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"Update at most every 10 secs","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":542,"y":192,"wires":[["86c9e07cb01eec87"]]},{"id":"17ea8e982fa2d280","type":"link out","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"return entities by area","mode":"return","links":[],"x":751,"y":384,"wires":[]},{"id":"d8335751137d9b1f","type":"link in","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"get entities by area","links":[],"x":234,"y":384,"wires":[["072d3e5fd5e540cb"]],"l":true},{"id":"d096314b2fe43404","type":"ha-get-entities","z":"892eaca92f0b4509","g":"fa7ec3d063bfa2f3","name":"","server":"","version":0,"rules":[],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":618,"y":384,"wires":[["17ea8e982fa2d280"]]}]