Skip to content

Instantly share code, notes, and snippets.

@zachowj
Last active March 28, 2023 03:29
Show Gist options
  • Save zachowj/70cc73b384e37858e53c42901127b97e to your computer and use it in GitHub Desktop.
Save zachowj/70cc73b384e37858e53c42901127b97e to your computer and use it in GitHub Desktop.
[{"id":"884762f5.cd0d","type":"ha-api","z":"33f42d45.e29ad2","name":"areas","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/area_registry/list\"}","dataType":"json","location":"areas","locationType":"msg","responseType":"json","x":370,"y":256,"wires":[["611635f4.9fa17c"]]},{"id":"13514152.b154ef","type":"inject","z":"33f42d45.e29ad2","name":"Manual Update","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":176,"y":256,"wires":[["884762f5.cd0d"]]},{"id":"611635f4.9fa17c","type":"ha-api","z":"33f42d45.e29ad2","name":"devices","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/device_registry/list\"}","dataType":"json","location":"devices","locationType":"msg","responseType":"json","x":510,"y":256,"wires":[["4448646c.da0b7c"]]},{"id":"4448646c.da0b7c","type":"ha-api","z":"33f42d45.e29ad2","name":"entities","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/entity_registry/list\"}","dataType":"json","location":"entities","locationType":"msg","responseType":"json","x":654,"y":256,"wires":[["f8762fd9.e0cc3"]]},{"id":"2381740e.9aecdc","type":"debug","z":"33f42d45.e29ad2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1000,"y":256,"wires":[]},{"id":"371bf0a2.6e8a6","type":"server-events","z":"33f42d45.e29ad2","name":"","event_type":"state_changed","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":164,"y":352,"wires":[["5197f33e.a2ff9c"]]},{"id":"f8762fd9.e0cc3","type":"function","z":"33f42d45.e29ad2","name":"","func":"const entities = {};\n\nmsg.entities.forEach(e => {\n if(!e.device_id) return;\n \n const device = msg.devices.find(d => d.id === e.device_id);\n const area = msg.areas.find(a => a.area_id === device.area_id);\n if(area) {\n entities[e.entity_id] = {\n area_id: area.area_id,\n name: area.name\n };\n }\n});\n\nmsg.payload = entities;\nmsg.update = true;\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":256,"wires":[["2381740e.9aecdc","5197f33e.a2ff9c"]]},{"id":"5197f33e.a2ff9c","type":"function","z":"33f42d45.e29ad2","name":"set area","func":"if(msg.update) {\n node.status({fill:\"green\", shape: \"dot\", text: \"Area 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 Area Data\", })\n return;\n}\n\nconst area = data[msg.payload.entity_id];\nif(!area) return;\n\nmsg.area = area.name.toLowerCase(); \nnode.status({text: msg.area});\n\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":352,"wires":[["6ede39d0.65a3d8"]]},{"id":"f7f89cbc.3a30d","type":"debug","z":"33f42d45.e29ad2","name":"Kitchen","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":684,"y":336,"wires":[]},{"id":"e45f1284.7bfd","type":"debug","z":"33f42d45.e29ad2","name":"Bedroom","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":684,"y":384,"wires":[]},{"id":"6ede39d0.65a3d8","type":"switch","z":"33f42d45.e29ad2","name":"","property":"area","propertyType":"msg","rules":[{"t":"eq","v":"kitchen","vt":"str"},{"t":"eq","v":"bedroom","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":512,"y":352,"wires":[["f7f89cbc.3a30d"],["e45f1284.7bfd"]]},{"id":"1c556df0.6a4d62","type":"server-events","z":"33f42d45.e29ad2","name":"On Connect","event_type":"home_assistant_client","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":134,"y":208,"wires":[["998f0a84.cb57f8"]]},{"id":"998f0a84.cb57f8","type":"switch","z":"33f42d45.e29ad2","name":"connected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connected","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":326,"y":208,"wires":[["884762f5.cd0d"]]},{"id":"27cd5318.74cb9c","type":"server-events","z":"33f42d45.e29ad2","name":"entity_registry_updated","event_type":"entity_registry_updated","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":164,"y":64,"wires":[["762feff.79d5c1"]]},{"id":"e128db1a.83f8c8","type":"server-events","z":"33f42d45.e29ad2","name":"device_registry_updated","event_type":"device_registry_updated","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":174,"y":112,"wires":[["762feff.79d5c1"]]},{"id":"68f37d5c.c438b4","type":"server-events","z":"33f42d45.e29ad2","name":"area_registry_updated","event_type":"area_registry_updated","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":164,"y":160,"wires":[["762feff.79d5c1"]]},{"id":"762feff.79d5c1","type":"trigger","z":"33f42d45.e29ad2","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":false,"units":"s","reset":"","bytopic":"all","name":"Update at most every 10 secs","x":466,"y":112,"wires":[["884762f5.cd0d"]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment