node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
2 lines (1 loc) • 3.36 kB
JSON
[{"id":"2bdd6fb7.15743","type":"server-state-changed","z":"b9bff4863336dc6b","name":"","server":"","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":[],"substring":["binary_sensor.button_bedroom"],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":284,"y":1520,"wires":[["c2a9ffac.1e05d"]]},{"id":"c2a9ffac.1e05d","type":"ha-get-entities","z":"b9bff4863336dc6b","name":"","server":"","version":1,"rules":[{"condition":"stateObject","property":"entity_id","logic":"includes","value":"sensor.phon_charging,sensor.watch_charging,sensor.kaylas_phone_charging,lock.lock","valueType":"str"},{"condition":"stateObject","property":"state","logic":"includes","value":"no,unlocked","valueType":"str"}],"outputType":"array","outputEmptyResults":true,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":562,"y":1520,"wires":[["2950c181.1ef95e"]]},{"id":"2950c181.1ef95e","type":"function","z":"b9bff4863336dc6b","name":"","func":"let lockFD = null;\nlet PC = false;\nlet WC = false;\nlet KP = false;\nlet FD = false;\n\nmsg.payload.forEach(entity => {\n switch(entity.entity_id) {\n case \"sensor.phone_charging\":\n PC = true;\n break;\n case \"sensor.watch_charging\":\n WC = true;\n break;\n case \"sensor.kaylas_phone_charging\":\n KP = true;\n break;\n case \"lock.lock\":\n FD = true;\n lockFD = { payload: true };\n break;\n }\n \n});\n\nlet message = \"Goodnight.\";\nif(PC && WC) {\n message = `${message} Don’t forget to charge your phone and watch.`;\n} else {\n message = `${message} Don’t forget to charge your ${PC ? 'phone' : 'watch'}.`\n}\nif(KP) {\n message = `${message} Remind Kayla to charge her phone${PC ? ' too':''}.`;\n}\nif(FD) {\n message = `${message} The door is now locked.`\n}\nmsg.payload = message;\nreturn [msg, lockFD];\n","outputs":2,"noerr":0,"x":702,"y":1520,"wires":[["ca4a5643.9bf0d8"],["64374b0e.f72394"]]},{"id":"ca4a5643.9bf0d8","type":"cast-to-client","z":"b9bff4863336dc6b","name":"","url":"","contentType":"","message":"","language":"en","ip":"192.168.1.29","port":"","volume":"40","x":886,"y":1520,"wires":[[]]},{"id":"64374b0e.f72394","type":"api-call-service","z":"b9bff4863336dc6b","name":"lock door","server":"","version":6,"debugenabled":false,"action":"scene.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["scene.lock_door"],"labelId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","domain":"scene","service":"turn_on","output_location":"payload","output_location_type":"msg","x":856,"y":1568,"wires":[[]]}]