Advertisement
TCr82

Node-RED Websock Connect for SmarthomeNG

Jan 16th, 2022 (edited)
974
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [{"id":"1afb24fb6efd1e6e","type":"tab","label":"SmarthomeNG-WS","disabled":false,"info":"","env":[]},{"id":"ea4e16b279f7c713","type":"websocket in","z":"1afb24fb6efd1e6e","name":"WS IN","server":"","client":"dc23a71d348a101d","x":83,"y":687,"wires":[["2701605ff2ed0180","91381041705b5d2b"]]},{"id":"978131458f042444","type":"inject","z":"1afb24fb6efd1e6e","name":"Init Msg","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":93,"y":453.75,"wires":[["58fb0c6d90da74aa","5973ad41d0fd33fc","6516ec3691291ec0","a8c9281077e13146","91381041705b5d2b"]]},{"id":"19dd6042c369fc27","type":"websocket out","z":"1afb24fb6efd1e6e","name":"WS OUT","server":"","client":"dc23a71d348a101d","x":1163,"y":159,"wires":[]},{"id":"67431e3235fb51c5","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"identity\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"","payloadType":"date","x":133,"y":317,"wires":[["5973ad41d0fd33fc"]]},{"id":"6b23c7ade586ae60","type":"debug","z":"1afb24fb6efd1e6e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":437,"y":795.5,"wires":[]},{"id":"7fb8aee5a8f4e160","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"monitor\",\"items\": ...}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.4","topic":"","payload":"","payloadType":"date","x":175,"y":396,"wires":[["a8c9281077e13146"]]},{"id":"74231a7fdea608c2","type":"function","z":"1afb24fb6efd1e6e","name":"","func":"if (msg.payload.cmd == \"item\")\n{\n    var items = msg.payload.items\n    var newItems = {}\n    //msg.payload = items\n    Object.values(items).forEach(item => {\n        //node.warn(item[0])\n        //newItems += { [item[0]] : item[1]};\n        newItems = Object.assign({}, newItems, {[item[0]]: item[1]}); \n    });\n    msg.payload = newItems\n    return [msg, null];\n} else {\n    return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":427,"y":687,"wires":[["6f16c81bfd129a26","c4f75ec7fc039b06","b29d57e74da7e9d1","2cd01e2b4d1d5189","53d77a37fabd1b4d","7db09a7b2f941511"],["598a9f41b75d0a1c"]],"outputLabels":["Items","Misc"]},{"id":"2701605ff2ed0180","type":"json","z":"1afb24fb6efd1e6e","name":"","property":"payload","action":"","pretty":false,"x":230,"y":687,"wires":[["6b23c7ade586ae60","74231a7fdea608c2"]]},{"id":"598a9f41b75d0a1c","type":"debug","z":"1afb24fb6efd1e6e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":437,"y":739.5,"wires":[]},{"id":"3119dd3b19972a36","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"list_items\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"list_items\",\"path\":\"env\"}","payloadType":"json","x":143,"y":140,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"5fb2321b6161ccd3","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"list_logics\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"list_logics\",\"enabled\":1}","payloadType":"json","x":143,"y":179,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"1a6da09ac34e7b07","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"log\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"log\",\"name\":\"env.core.log\",\"max\":5}","payloadType":"json","x":123,"y":50,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"210b158b68f8c09e","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"ping\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"ping\"}","payloadType":"json","x":123,"y":90,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"2aed71dfd999c50d","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"monitor\"}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.3","topic":"","payload":"true","payloadType":"bool","x":133,"y":356,"wires":[["6516ec3691291ec0"]]},{"id":"02a4cdeabe3d26a2","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"item\",....}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"cmd\":\"item\",\"id\":\"eg.sz.licht\",\"val\":\"1\"}","payloadType":"json","x":133,"y":226,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"70a59b322b443740","type":"comment","z":"1afb24fb6efd1e6e","name":"https://github.com/smarthomeNG/plugins/blob/develop/visu_websocket/developer_doc.rst","info":"See Developer Docs for more informations...","x":679,"y":26,"wires":[]},{"id":"6f2be9ba561405e1","type":"ui_switch","z":"1afb24fb6efd1e6e","name":"","label":"Schlafzimmer Licht","tooltip":"","group":"c97b24d92d98db53","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":989,"y":605,"wires":[["7f1d4cdb07418de1"]]},{"id":"6f16c81bfd129a26","type":"function","z":"1afb24fb6efd1e6e","name":"Filter: eg.sz.licht","func":"for (item in msg.payload)\n{\n    if(item == \"eg.sz.licht\")\n    {\n        msg.payload = msg.payload[item];\n        msg.topic = item\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":721,"y":605,"wires":[["6f2be9ba561405e1"]]},{"id":"7f1d4cdb07418de1","type":"function","z":"1afb24fb6efd1e6e","name":"Build Item cmd","func":"if(msg.topic == \"Stromzähler\")\n{\n    Object.keys(msg.payload).forEach((key) => {\n        newMsg = {}\n        switch (key)\n        {\n            case \"1-0:1.8.0*255\":\n                newMsg.payload = {\n                    \"cmd\":\"item\",\n                    \"id\": \"technik.sonstiges.pm1.bezug_kwh\",\n                    \"val\": msg.payload[key].values[0].value\n                }\n                break;\n\n            case \"1-0:16.7.0*255\":\n                newMsg.payload = {\n                    \"cmd\":\"item\",\n                    \"id\": \"technik.sonstiges.pm1.leistung_w\",\n                    \"val\": msg.payload[key].values[0].value\n                }\n                break;\n\n            case \"larry\": \n                newMsg = null;\n                break;\n\n            default:\n                newMsg = null\n        }\n        node.send(newMsg, false);\n    })\n} else {\n    msg.payload = {\"cmd\":\"item\", \"id\": msg.topic, \"val\": msg.payload}   \n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":967,"y":453.75,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"c4f75ec7fc039b06","type":"function","z":"1afb24fb6efd1e6e","name":"Filter: eg.flur.licht1","func":"for (item in msg.payload)\n{\n    if(item == \"eg.flur.licht1\")\n    {\n        msg.payload = msg.payload[item];\n        msg.topic = item\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":731,"y":660,"wires":[["457c17ed5c4b3f8a"]]},{"id":"457c17ed5c4b3f8a","type":"ui_switch","z":"1afb24fb6efd1e6e","name":"","label":"Flur Licht 1","tooltip":"","group":"c97b24d92d98db53","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":969,"y":660,"wires":[["7f1d4cdb07418de1"]]},{"id":"b29d57e74da7e9d1","type":"debug","z":"1afb24fb6efd1e6e","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":711,"y":551,"wires":[]},{"id":"067acf0326c78d88","type":"trigger","z":"1afb24fb6efd1e6e","name":"","op1":"","op2":"true","op1type":"date","op2type":"bool","duration":"-1","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":477,"y":453.75,"wires":[["58fb0c6d90da74aa","5973ad41d0fd33fc","6516ec3691291ec0","a8c9281077e13146","b29d57e74da7e9d1"]]},{"id":"58fb0c6d90da74aa","type":"change","z":"1afb24fb6efd1e6e","name":"{\"cmd\":\"proto\",\"ver\":4}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"cmd\":\"proto\",\"ver\":4}","tot":"json"},{"t":"delete","p":"_session","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":467,"y":278,"wires":[["7fe5e539aad29aa6"]]},{"id":"7fe5e539aad29aa6","type":"delay","z":"1afb24fb6efd1e6e","name":"","pauseType":"delay","timeout":"0.1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":732,"y":278,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"5973ad41d0fd33fc","type":"change","z":"1afb24fb6efd1e6e","name":"{\"cmd\":\"identity\"}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"cmd\":\"identity\",\"sw\":\"Node-RED\",\"ver\":\"v1\",\"browser\":\"Node-RED\",\"bver\":\"1\"}","tot":"json"},{"t":"delete","p":"_session","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":457,"y":317,"wires":[["2d313b1d0df2e4e7"]]},{"id":"2d313b1d0df2e4e7","type":"delay","z":"1afb24fb6efd1e6e","name":"","pauseType":"delay","timeout":"0.2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":733,"y":317,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"595161507c7a60f0","type":"inject","z":"1afb24fb6efd1e6e","name":"TEST: {\"cmd\":\"proto\",\"ver\":4}","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"","payloadType":"date","x":153,"y":278,"wires":[["58fb0c6d90da74aa"]]},{"id":"6516ec3691291ec0","type":"change","z":"1afb24fb6efd1e6e","name":"{\"cmd\":\"monitor\"}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"cmd\":\"monitor\",\"items\":[]}","tot":"json"},{"t":"delete","p":"_session","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":457,"y":356,"wires":[["c3a65ba8fda2d9dd"]]},{"id":"c3a65ba8fda2d9dd","type":"delay","z":"1afb24fb6efd1e6e","name":"","pauseType":"delay","timeout":"0.3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":732,"y":356,"wires":[["8a94b28805b292fe","19dd6042c369fc27"]]},{"id":"a8c9281077e13146","type":"change","z":"1afb24fb6efd1e6e","name":"{\"cmd\":\"monitor\",\"items\": ...}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"cmd\":\"monitor\",\"items\":[\"aussen.eingang.temperature\",\"aussen.eingang.licht\",\"aussen.eingang.licht.property.last_change\",\"aussen.terasse.licht\",\"eg.flur.temperature\",\"eg.flur.licht1\",\"eg.flur.licht2\",\"eg.flur.licht_tag\",\"eg.flur.haustuer.open\",\"eg.flur.rtr.heizt\",\"eg.flur.rtr.stellwert\",\"eg.kueche.temperature\",\"eg.kueche.licht\",\"eg.kueche.rolladentuer.open\",\"eg.kueche.rolladenfenster.open\",\"eg.kueche.rtr.heizt\",\"eg.kueche.rtr.stellwert\",\"eg.ez.temperature\",\"eg.ez.licht1\",\"eg.ez.licht2\",\"eg.ez.rolladen.open\",\"eg.wz.temperature\",\"eg.wz.licht1\",\"eg.wz.licht2\",\"eg.wz.rolladentuer.open\",\"eg.wz.rolladenschwingfenster.open\",\"eg.wz.rolladenfenster.open\",\"eg.wz.rtr.heizt\",\"eg.wz.rtr.stellwert\",\"eg.sz.temperature\",\"eg.sz.licht\",\"eg.sz.rolladen.open\",\"eg.sz.rtr.heizt\",\"eg.sz.rtr.stellwert\",\"eg.kz.temperature\",\"eg.kz.licht\",\"eg.kz.rolladen.open\",\"eg.kz.rtr.heizt\",\"eg.kz.rtr.stellwert\",\"eg.bz.temperature\",\"eg.bz.licht\",\"eg.wc.temperature\",\"eg.wc.licht\",\"og.wz.temperature\",\"og.wz.licht1\",\"og.wz.licht2\",\"og.wz.fenster.open\",\"og.wz.rtr.heizt\",\"og.wz.rtr.stellwert\",\"og.bz.temperature\",\"og.bz.licht\",\"og.bz.fenster.status\",\"og.bz.rtr.heizt\",\"og.bz.rtr.stellwert\",\"og.kz1.temperature\",\"og.kz1.licht\",\"og.kz1.fenster.open\",\"og.kz1.tuer.status\",\"og.kz1.rtr.heizt\",\"og.kz1.rtr.stellwert\",\"og.kz2.temperature\",\"og.kz2.licht\",\"og.kz2.fenster.open\",\"og.kz2.tuer.status\",\"og.kz2.rtr.heizt\",\"og.kz2.rtr.stellwert\",\"og.balkon.licht\",\"kg.flur.licht\",\"kg.hwr.licht\",\"kg.buero.licht\",\"kg.garage.licht\",\"kg.werkstatt.licht\",\"kg.hr.licht\",\"technik.sicherheit.anwesend\",\"zentral.rollaeden.alle.auto\",\"env.system.name\",\"env.core.version\",\"env.system.load\",\"env.core.threads\",\"env.core.memory\",\"env.system.start\",\"env.core.start\",\"env.location.sunrise\",\"env.location.sunset\",\"env.location.moonrise\",\"env.location.moonset\",\"env.location.moonphase\",\"env.location.moonlight\"]}","tot":"json"},{"t":"delete","p":"_session","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":487,"y":396,"wires":[["c59f6ef2f6a8206a"]]},{"id":"c59f6ef2f6a8206a","type":"delay","z":"1afb24fb6efd1e6e","name":"","pauseType":"delay","timeout":"0.4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":731,"y":396,"wires":[["19dd6042c369fc27","8a94b28805b292fe"]]},{"id":"91381041705b5d2b","type":"trigger","z":"1afb24fb6efd1e6e","name":"","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"1","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":250,"y":510,"wires":[["18bd1a92cc9a90cc"],["067acf0326c78d88"]],"info":"Wird von der Init Msg und eingehenden Nachrichten aktiviert.\n\nNach ausbleiben neuer Nachrichten, wird der zweite Trigger aktiviert, der Solange den Init anstöst, bis wieder Nachrichten hier eingehen.\n\nDenn dann wird hier auf dem 2. Kanal das msg.reset erzeugt, was den 2. Trigger deaktiviert.\n"},{"id":"18bd1a92cc9a90cc","type":"change","z":"1afb24fb6efd1e6e","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":447,"y":510,"wires":[["067acf0326c78d88"]]},{"id":"8a94b28805b292fe","type":"debug","z":"1afb24fb6efd1e6e","name":"","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":963,"y":92,"wires":[]},{"id":"de85206e94ed4d4f","type":"link in","z":"1afb24fb6efd1e6e","name":"","links":["8b1a5ac492ef9f08"],"x":786,"y":454,"wires":[["7f1d4cdb07418de1"]]},{"id":"0a8832b0795c1875","type":"ui_text","z":"1afb24fb6efd1e6e","group":"c97b24d92d98db53","order":2,"width":0,"height":0,"name":"","label":"SmartHomeNG Version:","format":"{{msg.payload}}","layout":"row-spread","className":"","x":1009,"y":712,"wires":[]},{"id":"2cd01e2b4d1d5189","type":"function","z":"1afb24fb6efd1e6e","name":"Filter: env.core.version","func":"for (item in msg.payload)\n{\n    if(item == \"env.core.version\")\n    {\n        msg.payload = msg.payload[item];\n        msg.topic = item\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":741,"y":712,"wires":[["0a8832b0795c1875"]]},{"id":"53d77a37fabd1b4d","type":"function","z":"1afb24fb6efd1e6e","name":"Filter: env.core.start","func":"for (item in msg.payload)\n{\n    if(item == \"env.core.start\")\n    {\n        var d = new Date(msg.payload[item]);\n        var options = { timeZone: 'Europe/Berlin', year: 'numeric', month: '2-digit', day: '2-digit', hour: `2-digit`, minute: `2-digit`, second: `2-digit`};\n        var _resultDate = d.toLocaleDateString('de-DE', options);\n        msg.payload = _resultDate\n        msg.topic = item\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":760,"wires":[["7ab34252128899e7"]]},{"id":"7ab34252128899e7","type":"ui_text","z":"1afb24fb6efd1e6e","group":"c97b24d92d98db53","order":2,"width":0,"height":0,"name":"","label":"SmartHomeNG Startzeit:","format":"{{msg.payload}}","layout":"row-spread","className":"","x":1008,"y":760,"wires":[]},{"id":"7db09a7b2f941511","type":"function","z":"1afb24fb6efd1e6e","name":"Filter: env.system.load","func":"for (item in msg.payload)\n{\n    if(item == \"env.system.load\")\n    {\n        msg.payload = msg.payload[item];\n        msg.topic = item\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":738,"y":806,"wires":[["945fb65dc01ec014"]]},{"id":"945fb65dc01ec014","type":"ui_chart","z":"1afb24fb6efd1e6e","name":"","group":"c97b24d92d98db53","order":4,"width":0,"height":0,"label":"System Load","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":968,"y":806,"wires":[[]]},{"id":"dc23a71d348a101d","type":"websocket-client","path":"ws://zentrale:2424","tls":"","wholemsg":"false","hb":"0"},{"id":"c97b24d92d98db53","type":"ui_group","name":"SmartHomeNG","tab":"a68ac1cbe2203ae5","order":1,"disp":true,"width":"10","collapse":false,"className":""},{"id":"a68ac1cbe2203ae5","type":"ui_tab","name":"HOME","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement