node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
2 lines (1 loc) • 2.11 kB
JSON
[{"id":"953f4576.faa588","type":"ha-get-entities","z":"6cb9e978.bf4588","server":"8d00ebbc.99a928","name":"Get States","rules":[{"property":"entity_id","logic":"is","value":"^(light|switch|climate)\\.+","valueType":"re"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":294,"y":80,"wires":[["2dab5a86.e54686"]]},{"id":"821d957.d510168","type":"inject","z":"6cb9e978.bf4588","name":"Store states","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":118,"y":80,"wires":[["953f4576.faa588"]]},{"id":"5bc878cb.d80f08","type":"comment","z":"6cb9e978.bf4588","name":"How I would do store states","info":"","x":152,"y":32,"wires":[]},{"id":"2dab5a86.e54686","type":"function","z":"6cb9e978.bf4588","name":"transform data","func":"const entities = msg.payload.map((e) => {\n const domain = e.entity_id.split('.')[0];\n const payload = {};\n\n switch(domain) {\n case 'switch':\n case 'light':\n payload.domain = domain;\n payload.service = `turn_${e.state}`;\n payload.data = { entity_id: e.entity_id }; \n break;\n case 'climate':\n payload.domain = 'climate';\n payload.service = `set_temperature`;\n payload.data = {\n entity_id: e.entity_id,\n temperature: e.attributes.temperature,\n target_temp_low: e.attributes.min_temp,\n target_temp_high: e.attributes.max_temp,\n operation_mode: e.attributes.operation_mode\n };\n break;\n }\n return payload;\n});\n// Save the states\nflow.set('savedStates', entities);\n\n// create a blank message object with out new payload\nmsg = { payload: entities };\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":80,"wires":[["ceaf42e4.e245d"]]},{"id":"ceaf42e4.e245d","type":"debug","z":"6cb9e978.bf4588","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":646,"y":80,"wires":[]}]