[{"id":"6702597a.28fef8","type":"mbus-out","z":"20ec336f.eb7ccc","name":"","client":"b73343ba.166db","x":471,"y":242,"wires":[["2cd5169c.d4aeea"]]},{"id":"2cd5169c.d4aeea","type":"debug","z":"20ec336f.eb7ccc","name":"","active":false,"console":false,"complete":"false","x":690,"y":242,"wires":[]},{"id":"d4980b3e.ca2a68","type":"mbus-controller","z":"20ec336f.eb7ccc","name":"","client":"b73343ba.166db","x":511,"y":303,"wires":[["bff179c1.6fccc8","7c125709.048d18","d1839c75.ee69f","69c1f992.f212b8","86de123c.3289c"]]},{"id":"2cca6fa9.e151c","type":"inject","z":"20ec336f.eb7ccc","name":"scan","topic":"scan","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":122,"y":72,"wires":[["d4980b3e.ca2a68"]]},{"id":"7c125709.048d18","type":"debug","z":"20ec336f.eb7ccc","name":"","active":false,"console":false,"complete":"false","x":1070,"y":340,"wires":[]},{"id":"cbca6f36.59355","type":"inject","z":"20ec336f.eb7ccc","name":"Read ID 1","topic":"getDevice","payload":"{\"address\": 1}","payloadType":"json","repeat":"","crontab":"","once":false,"x":129,"y":146,"wires":[["d4980b3e.ca2a68"]]},{"id":"94ace647.545e58","type":"inject","z":"20ec336f.eb7ccc","name":"Get Devices","topic":"getDevices","payload":"","payloadType":"str","repeat":"60","crontab":"","once":true,"onceDelay":"","x":145,"y":220,"wires":[["d4980b3e.ca2a68"]]},{"id":"bff179c1.6fccc8","type":"ui_template","z":"20ec336f.eb7ccc","group":"6e8f4f35.a9295","name":"mbus-table","order":0,"width":"14","height":"10","format":"<table>\n <tr>\n <th>ID</th>\n <th>Primary ID</th>\n <th>Info</th>\n <th>Data</th>\n <th>Last Update</th>\n <th>Status</th>\n </tr>\n <tr style=\"cursor:pointer;\" ng-click=\"showData(device)\" ng-repeat=\"(id, device) in devices\">\n <td>{{ device.secondaryID }}</td>\n <td>{{ device.primaryID }}</td>\n <td ng-bind-html=\"getInfo(device)\"></td>\n <td>{{ device.DataRecord.length }}</td>\n <td>{{ device.lastUpdate }}</td>\n <td>\n <div class=\"online\" ng-style=\"{background: !device.error ? '#4CAF50' : '#f44336'}\">\n <md-tooltip md-direction=\"bottom\">{{ device.error ? device.error : 'OK' }}</md-tooltip>\n </div>\n </td>\n </tr>\n</table>\n\n<style>\ntable {\n border-collapse: collapse;\n width: 100%;\n}\n\nth, td{\n text-align: left;\n padding: 8px;\n background-color: #f2f2f2;\n color: black;\n}\n\nth {\n background-color: #4CAF50;\n color: white;\n}\n\n.online {\n\tbackground:#ff3333;\n\twidth:20px;\n\theight:20px;\n\tmargin:0 auto;\n\t-webkit-border-radius:50%;\n\t-moz-border-radius:50%;\n\tborder-radius:50%;\n}\n</style>\n\n<script>\n\n\n(function(scope) {\n \n scope.send({topic: 'getDevices'});\n scope.devices = [];\n \n scope.showData = function(device){\n scope.send({topic: 'deviceData', payload: device});\n }\n \n scope.getInfo = function(device){\n var text = '';\n var info = device.SlaveInformation;\n \n for(key in info){\n text += `<p><b>${key}</b>: ${info[key]}</p>`;\n }\n \n return text;\n }\n\n scope.$watch('msg', function(data) {\n if(data && data.topic){\n switch(data.topic){\n case \"getDevices\":\n if(data.payload && data.payload.devices)\n scope.devices = data.payload.devices;\n break;\n }\n }\n });\n \n})(scope);\n\n</script>\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":870,"y":300,"wires":[["3dc57553.aa2c0a"]]},{"id":"2b47be01.092042","type":"inject","z":"20ec336f.eb7ccc","name":"restart","topic":"restart","payload":"","payloadType":"num","repeat":"","crontab":"","once":false,"x":119,"y":108,"wires":[["d4980b3e.ca2a68"]]},{"id":"3dc57553.aa2c0a","type":"ui_template","z":"20ec336f.eb7ccc","group":"1e129f49.cc9c31","name":"data-table","order":0,"width":"14","height":"10","format":"<p><b>Device ID:</b> {{ID}} </p>\n\n<br>\n<br>\n\n<table>\n <tr>\n <th>ID</th>\n <th>Function</th>\n <th>Unit</th>\n <th>Value</th>\n <th>Timestamp</th>\n </tr>\n <tr ng-repeat=\"(key, data) in deviceData\">\n <td>{{ data.id }}</td>\n <td>{{ data.Function }}</td>\n <td>{{ data.Unit }}</td>\n <td>{{ data.Value }}</td>\n <td>{{ data.Timestamp }}</td>\n </tr>\n</table>\n\n<style>\ntable {\n border-collapse: collapse;\n width: 100%;\n}\n\nth, td{\n text-align: left;\n padding: 8px;\n background-color: #f2f2f2;\n color: black;\n}\n\nth {\n background-color: #4CAF50;\n color: white;\n}\n\n.online {\n\tbackground:#ff3333;\n\twidth:20px;\n\theight:20px;\n\tmargin:0 auto;\n\t-webkit-border-radius:50%;\n\t-moz-border-radius:50%;\n\tborder-radius:50%;\n}\n</style>\n\n<script>\n\n\n(function(scope) {\n \n scope.deviceData = [];\n scope.ID = '';\n\n scope.$watch('msg', function(data) {\n if(data && data.topic){\n switch(data.topic){\n case \"deviceData\":\n if(data.payload){\n scope.deviceData = data.payload.DataRecord;\n scope.ID = data.payload.SlaveInformation.Id;\n }\n break;\n }\n }\n });\n \n})(scope);\n\n</script>\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":1060,"y":300,"wires":[[]]},{"id":"b7c4e542.d485c8","type":"inject","z":"20ec336f.eb7ccc","name":"Read ID 2","topic":"getDevice","payload":"{\"address\": 2}","payloadType":"json","repeat":"","crontab":"","once":false,"x":130,"y":184,"wires":[["d4980b3e.ca2a68"]]},{"id":"20805b55.e29c74","type":"ui_button","z":"20ec336f.eb7ccc","name":"Scan","group":"9389bdc6.95222","order":3,"width":"2","height":"1","passthru":false,"label":"Scan","color":"","bgcolor":"","icon":"location_searching","payload":"","payloadType":"str","topic":"scan","x":97,"y":306,"wires":[["d4980b3e.ca2a68"]]},{"id":"dd533a94.524b18","type":"ui_button","z":"20ec336f.eb7ccc","name":"Restart","group":"9389bdc6.95222","order":4,"width":"3","height":"1","passthru":false,"label":"Restart","color":"","bgcolor":"","icon":"refresh","payload":"","payloadType":"str","topic":"restart","x":107,"y":343,"wires":[["d4980b3e.ca2a68"]]},{"id":"8556fef1.866cd","type":"ui_button","z":"20ec336f.eb7ccc","name":"GetDevices","group":"9389bdc6.95222","order":5,"width":"3","height":"1","passthru":false,"label":"Update Devices","color":"","bgcolor":"","icon":"refresh","payload":"","payloadType":"str","topic":"getDevices","x":115,"y":380,"wires":[["d4980b3e.ca2a68"]]},{"id":"276c88ff.ab54e8","type":"ui_button","z":"20ec336f.eb7ccc","name":"readAddress","group":"9389bdc6.95222","order":2,"width":"3","height":"1","passthru":false,"label":"Read Device","color":"","bgcolor":"","icon":"","payload":"deviceID","payloadType":"flow","topic":"getDevice","x":112,"y":419,"wires":[["f81c4f2c.42f6"]]},{"id":"693ff196.a26d2","type":"ui_text_input","z":"20ec336f.eb7ccc","name":"Device_ID","label":"ID: ","group":"9389bdc6.95222","order":1,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":110,"y":580,"wires":[["73e0093.d37f8f8"]]},{"id":"73e0093.d37f8f8","type":"function","z":"20ec336f.eb7ccc","name":"storeID","func":"\nflow.set('deviceID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":286,"y":580,"wires":[]},{"id":"f81c4f2c.42f6","type":"function","z":"20ec336f.eb7ccc","name":"readAddr","func":"var data = {address: msg.payload}\n\nmsg.payload = data;\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":419,"wires":[["d4980b3e.ca2a68"]]},{"id":"cadaaa6c.265a48","type":"status","z":"20ec336f.eb7ccc","name":"controller_status","scope":["d4980b3e.ca2a68"],"x":411,"y":97,"wires":[["725eb89d.1f87d8"]]},{"id":"f6ccff88.1d3a3","type":"status","z":"20ec336f.eb7ccc","name":"mbus_status","scope":["6702597a.28fef8"],"x":404,"y":142,"wires":[["e434f2c1.69ba1"]]},{"id":"725eb89d.1f87d8","type":"ui_text","z":"20ec336f.eb7ccc","group":"de1d88a7.2fbbf8","order":0,"width":0,"height":0,"name":"controller_status","label":"Controller","format":"{{msg.status.text}}","layout":"row-spread","x":623,"y":97,"wires":[]},{"id":"e434f2c1.69ba1","type":"ui_text","z":"20ec336f.eb7ccc","group":"de1d88a7.2fbbf8","order":0,"width":0,"height":0,"name":"mbus_status","label":"M-Bus","format":"{{msg.status.text}}","layout":"row-spread","x":613,"y":142,"wires":[]},{"id":"4c7a0fb4.d3a3b","type":"inject","z":"20ec336f.eb7ccc","name":"setPrimary","topic":"setPrimary","payload":"{\"newAddr\":3,\"oldAddr\":2}","payloadType":"json","repeat":"","crontab":"","once":false,"x":121,"y":35,"wires":[["d4980b3e.ca2a68"]]},{"id":"65b3019c.959eb","type":"ui_text_input","z":"20ec336f.eb7ccc","name":"Old_ID","label":"Old ID","group":"9389bdc6.95222","order":6,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":117,"y":620,"wires":[["1a1e851.d04317b"]]},{"id":"1a1e851.d04317b","type":"function","z":"20ec336f.eb7ccc","name":"storeID","func":"\nflow.set('oldID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":284,"y":620,"wires":[]},{"id":"69f64c1c.5f3964","type":"ui_text_input","z":"20ec336f.eb7ccc","name":"New_ID","label":"New ID","group":"9389bdc6.95222","order":7,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":114,"y":660,"wires":[["6c97a20a.13cd3c"]]},{"id":"6c97a20a.13cd3c","type":"function","z":"20ec336f.eb7ccc","name":"storeID","func":"\nflow.set('newID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":282,"y":660,"wires":[]},{"id":"9f0ed335.3f704","type":"ui_button","z":"20ec336f.eb7ccc","name":"SetPrimary","group":"9389bdc6.95222","order":8,"width":"3","height":"1","passthru":false,"label":"Set Primary ID","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"setPrimary","x":111,"y":460,"wires":[["97d46ac9.02efc8"]]},{"id":"97d46ac9.02efc8","type":"function","z":"20ec336f.eb7ccc","name":"setPrimary","func":"var data = {\n oldAddr: flow.get('oldID'), \n newAddr:flow.get('newID')\n }\n\nmsg.payload = data;\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":460,"wires":[["d4980b3e.ca2a68"]]},{"id":"2a280046.bb53e","type":"inject","z":"20ec336f.eb7ccc","name":"","topic":"getDevice","payload":"counter","payloadType":"flow","repeat":"60","crontab":"","once":false,"onceDelay":"","x":130,"y":520,"wires":[["4f6175e5.eb21bc"]]},{"id":"4f6175e5.eb21bc","type":"function","z":"20ec336f.eb7ccc","name":"scanPrimary","func":"\nif(msg.payload == null) msg.payload = 1;\n\nif(msg.payload >= 76) msg.payload = 1;\n\nmsg.payload++;\n\nflow.set(\"counter\",msg.payload);\n\nmsg.payload = {address: msg.payload};\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":520,"wires":[[]]},{"id":"72a29030.650be","type":"inject","z":"20ec336f.eb7ccc","name":"setDevices","topic":"setDevices","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":260,"wires":[["1b3b279.dededd8"]]},{"id":"1b3b279.dededd8","type":"function","z":"20ec336f.eb7ccc","name":"devices","func":"var devices = [\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\",\"32\",\"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\"41\",\"42\",\"43\",\"44\",\"45\",\"46\",\"47\",\"48\",\"49\",\"50\",\"51\",\"52\",\"53\",\"54\",\"55\",\"56\",\"57\",\"58\",\"59\",\"60\",\"61\",\"62\",\"63\",\"64\",\"65\",\"66\",\"67\",\"68\",\"69\",\"70\",\"71\",\"72\",\"73\",\"74\",\"75\",\"76\"];\n\nmsg.payload = devices;\n\nreturn msg;","outputs":1,"noerr":0,"x":258,"y":260,"wires":[["d4980b3e.ca2a68"]]},{"id":"d1839c75.ee69f","type":"function","z":"20ec336f.eb7ccc","name":"Extract + Format Kamstrup 302","func":"let TotalHeatEnergy = msg.payload.devices[\"67362961\"].DataRecord[1].Value; \nlet TotalCoolEnergy = msg.payload.devices[\"67362961\"].DataRecord[2].Value;\nlet FlowTemperature = msg.payload.devices[\"67362961\"].DataRecord[8].Value /100;\nlet ReturnTemperature = msg.payload.devices[\"67362961\"].DataRecord[9].Value /100;\nlet DiffTemperature = msg.payload.devices[\"67362961\"].DataRecord[10].Value /100;\nlet PowerInstValue = msg.payload.devices[\"67362961\"].DataRecord[11].Value *100;\nlet FlowInstValue = msg.payload.devices[\"67362961\"].DataRecord[13].Value;\n\nlet _msg = {\n payload: []\n};\n\n_msg.payload=\n {\n measurement: \"HeatEnergy\",\n\t\tfields: {\n\t\t\ttotalheatenergy: TotalHeatEnergy,\t\t\t\n\t\t\ttotalcoolenergy: TotalCoolEnergy,\t\n\t\t\tflowtemperature: FlowTemperature,\t\n\t\t returntemperature: ReturnTemperature,\t\n\t\t difftemperature: DiffTemperature,\n\t\t power: PowerInstValue,\n\t\t\tflow: FlowInstValue,\n\t\t},\n\t\ttags:{\n\t\t device: \"Kamstrup\",\n\t\t},\n\t\ttimestamp: flow.get('timestamp')\n\t}\n\n\nreturn _msg;","outputs":1,"noerr":0,"x":550,"y":480,"wires":[["61934bca.628ea4"]]},{"id":"54f285ef.c403fc","type":"debug","z":"20ec336f.eb7ccc","name":"","active":true,"console":false,"complete":"false","x":1030,"y":520,"wires":[]},{"id":"61934bca.628ea4","type":"join","z":"20ec336f.eb7ccc","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"8","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":790,"y":480,"wires":[["54f285ef.c403fc","d9ed35d9.3fd568"]]},{"id":"d9ed35d9.3fd568","type":"influxdb batch","z":"20ec336f.eb7ccc","influxdb":"e923a526.ab9e78","precision":"","retentionPolicy":"","name":"","x":1070,"y":480,"wires":[]},{"id":"b1cf367.ba85fc8","type":"comment","z":"20ec336f.eb7ccc","name":"Change the device ID number","info":"","x":540,"y":440,"wires":[]},{"id":"abf0b0f2.564db","type":"comment","z":"20ec336f.eb7ccc","name":"Change to your own influxdb server","info":"","x":1100,"y":440,"wires":[]},{"id":"69c1f992.f212b8","type":"function","z":"20ec336f.eb7ccc","name":"Extract + Format Kamstrup 302","func":"var TotalHeatEnergy = msg.payload.devices[\"67362961\"].DataRecord[1].Value; \nvar TotalCoolEnergy = msg.payload.devices[\"67362961\"].DataRecord[2].Value;\nvar FlowTemperature = msg.payload.devices[\"67362961\"].DataRecord[8].Value /100;\nvar ReturnTemperature = msg.payload.devices[\"67362961\"].DataRecord[9].Value /100;\nvar DiffTemperature = msg.payload.devices[\"67362961\"].DataRecord[10].Value /100;\nvar PowerInstValue = msg.payload.devices[\"67362961\"].DataRecord[11].Value *100;\nvar FlowInstValue = msg.payload.devices[\"67362961\"].DataRecord[13].Value;\n\nvar msg1 = {payload:{\"idx\": 26, \"nvalue\": 0, \"svalue\": String(TotalHeatEnergy)}};\nvar msg2 = {payload:{\"idx\": 27, \"nvalue\": 0, \"svalue\": String(TotalCoolEnergy)}};\nvar msg3 = {payload:{\"idx\": 20, \"nvalue\": 0, \"svalue\": String(FlowTemperature)}};\nvar msg4 = {payload:{\"idx\": 21, \"nvalue\": 0, \"svalue\": String(ReturnTemperature)}};\nvar msg5 = {payload:{\"idx\": 22, \"nvalue\": 0, \"svalue\": String(DiffTemperature)}};\nvar msg6 = {payload:{\"idx\": 23, \"nvalue\": 0, \"svalue\": String(FlowInstValue)}};\n\nreturn [ msg1, msg2, msg3, msg4, msg5, msg6 ];","outputs":7,"noerr":0,"x":550,"y":620,"wires":[["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"],["aef13098.8c946","8b2d7a92.ad7868"]]},{"id":"8b2d7a92.ad7868","type":"mqtt out","z":"20ec336f.eb7ccc","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"72fd3356.362c4c","x":890,"y":600,"wires":[]},{"id":"aef13098.8c946","type":"debug","z":"20ec336f.eb7ccc","name":"","active":false,"console":false,"complete":"false","x":890,"y":660,"wires":[]},{"id":"a7c0dd04.914ab","type":"comment","z":"20ec336f.eb7ccc","name":"Change to your own","info":"","x":890,"y":560,"wires":[]},{"id":"6c94fecb.dd9ac","type":"comment","z":"20ec336f.eb7ccc","name":"Change the device ID number","info":"","x":540,"y":540,"wires":[]},{"id":"86de123c.3289c","type":"json","z":"20ec336f.eb7ccc","name":"","property":"payload","action":"obj","pretty":false,"x":430,"y":740,"wires":[["972cc8ad.74a8b8"]]},{"id":"c3874b6f.9b8a08","type":"debug","z":"20ec336f.eb7ccc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":890,"y":760,"wires":[]},{"id":"972cc8ad.74a8b8","type":"function","z":"20ec336f.eb7ccc","name":"Extract + Format Kamstrup 302","func":"\nnode.log (\"Power and Energy to Domoticz HTTP\");\nvar power = JSON.parse(msg.payload.devices[\"67362961\"].DataRecord[11].Value)*100;\nvar energy = JSON.parse(msg.payload.devices[\"67362961\"].DataRecord[1].Value)*1000;\nmsg.url = \"192.168.0.148:8095/json.htm?type=command¶m=udevice&idx=24&nvalue=0&svalue=\"+power +\";\"+energy ;\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":740,"wires":[["c3874b6f.9b8a08","fb7f35ae.497638"]]},{"id":"fb7f35ae.497638","type":"http request","z":"20ec336f.eb7ccc","name":"Domoticz","method":"use","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":880,"y":720,"wires":[[]]},{"id":"b73343ba.166db","type":"mbus-client","z":"","name":"","clienttype":"serial","tcpHost":"127.0.0.1","tcpPort":"10001","tcpTimeout":"4000","serialPort":"/dev/ttyUSB-KAMSTRUP","serialBaudrate":"2400","reconnectTimeout":"10000","autoScan":true,"storeDevices":true,"disableLogs":true},{"id":"6e8f4f35.a9295","type":"ui_group","z":"","name":"M-Bus Devices","tab":"5d7bc91.8186538","order":3,"disp":true,"width":"14"},{"id":"1e129f49.cc9c31","type":"ui_group","z":"","name":"Data","tab":"5d7bc91.8186538","order":4,"disp":true,"width":"14"},{"id":"9389bdc6.95222","type":"ui_group","z":"","name":"Commands","tab":"5d7bc91.8186538","order":2,"disp":true,"width":"14"},{"id":"de1d88a7.2fbbf8","type":"ui_group","z":"","name":"Status","tab":"5d7bc91.8186538","order":1,"disp":true,"width":"14"},{"id":"e923a526.ab9e78","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"telegraf","name":"","usetls":false,"tls":""},{"id":"72fd3356.362c4c","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5d7bc91.8186538","type":"ui_tab","z":"","name":"M-Bus","icon":"plug","order":1}]