[{"id":"a4d1e87c.7813c8","type":"tab","label":"Kamstup Mbus","disabled":false,"info":""},{"id":"ad6e84cc.601248","type":"mbus-controller","z":"a4d1e87c.7813c8","name":"M-Bus Controller","client":"cf258c74.2b793","x":450,"y":260,"wires":[["e34cc17e.24b7b","f1266995.091838","b002634f.1d14d"]]},{"id":"f1266995.091838","type":"debug","z":"a4d1e87c.7813c8","name":"","active":false,"console":false,"complete":"false","x":1009,"y":297,"wires":[]},{"id":"e34cc17e.24b7b","type":"ui_template","z":"a4d1e87c.7813c8","group":"ba35fc26.07964","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":809,"y":257,"wires":[["ac9fdd7e.3e595"]]},{"id":"ac9fdd7e.3e595","type":"ui_template","z":"a4d1e87c.7813c8","group":"447b5e0.211efa4","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":999,"y":257,"wires":[[]]},{"id":"19ace9d.924fe16","type":"ui_button","z":"a4d1e87c.7813c8","name":"Scan","group":"61c985c0.155d6c","order":3,"width":"2","height":"1","passthru":false,"label":"Scan","color":"","bgcolor":"","icon":"location_searching","payload":"","payloadType":"str","topic":"scan","x":76,"y":324,"wires":[["ad6e84cc.601248"]]},{"id":"6118cd98.d9f924","type":"ui_button","z":"a4d1e87c.7813c8","name":"Restart","group":"61c985c0.155d6c","order":4,"width":"3","height":"1","passthru":false,"label":"Restart","color":"","bgcolor":"","icon":"refresh","payload":"","payloadType":"str","topic":"restart","x":86,"y":361,"wires":[["ad6e84cc.601248"]]},{"id":"7a304035.eab69","type":"ui_button","z":"a4d1e87c.7813c8","name":"GetDevices","group":"61c985c0.155d6c","order":5,"width":"3","height":"1","passthru":false,"label":"Update Devices","color":"","bgcolor":"","icon":"refresh","payload":"","payloadType":"str","topic":"getDevices","x":94,"y":398,"wires":[["ad6e84cc.601248"]]},{"id":"30437a57.a7b166","type":"ui_button","z":"a4d1e87c.7813c8","name":"readAddress","group":"61c985c0.155d6c","order":2,"width":"3","height":"1","passthru":false,"label":"Read Device","color":"","bgcolor":"","icon":"","payload":"deviceID","payloadType":"flow","topic":"getDevice","x":91,"y":437,"wires":[["58baf1c9.96bd3"]]},{"id":"d6f6c8f.2b78438","type":"ui_text_input","z":"a4d1e87c.7813c8","name":"Device_ID","label":"ID: ","group":"61c985c0.155d6c","order":1,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":89,"y":598,"wires":[["b1a27f19.6b4c2"]]},{"id":"b1a27f19.6b4c2","type":"function","z":"a4d1e87c.7813c8","name":"storeID","func":"\nflow.set('deviceID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":265,"y":598,"wires":[]},{"id":"58baf1c9.96bd3","type":"function","z":"a4d1e87c.7813c8","name":"readAddr","func":"var data = {address: msg.payload}\n\nmsg.payload = data;\n\nreturn msg;","outputs":1,"noerr":0,"x":249,"y":437,"wires":[["ad6e84cc.601248"]]},{"id":"4937ddc.127ba24","type":"ui_text_input","z":"a4d1e87c.7813c8","name":"Old_ID","label":"Old ID","group":"61c985c0.155d6c","order":6,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":96,"y":638,"wires":[["81f277bc.35b8f8"]]},{"id":"81f277bc.35b8f8","type":"function","z":"a4d1e87c.7813c8","name":"storeID","func":"\nflow.set('oldID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":263,"y":638,"wires":[]},{"id":"9f68a834.7458d8","type":"ui_text_input","z":"a4d1e87c.7813c8","name":"New_ID","label":"New ID","group":"61c985c0.155d6c","order":7,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":93,"y":678,"wires":[["f17e49df.d7b428"]]},{"id":"f17e49df.d7b428","type":"function","z":"a4d1e87c.7813c8","name":"storeID","func":"\nflow.set('newID', msg.payload);\n\nreturn msg;","outputs":0,"noerr":0,"x":261,"y":678,"wires":[]},{"id":"ff06d122.21092","type":"ui_button","z":"a4d1e87c.7813c8","name":"SetPrimary","group":"61c985c0.155d6c","order":8,"width":"3","height":"1","passthru":false,"label":"Set Primary ID","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"setPrimary","x":90,"y":478,"wires":[["4d8f6488.a2678c"]]},{"id":"4d8f6488.a2678c","type":"function","z":"a4d1e87c.7813c8","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":259,"y":478,"wires":[["ad6e84cc.601248"]]},{"id":"8b324073.ec26c","type":"inject","z":"a4d1e87c.7813c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":"","topic":"getDevice","payload":"counter","payloadType":"flow","x":109,"y":538,"wires":[["e75c7a43.db1f18"]]},{"id":"e75c7a43.db1f18","type":"function","z":"a4d1e87c.7813c8","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":289,"y":538,"wires":[[]]},{"id":"bee81da5.4d3b1","type":"function","z":"a4d1e87c.7813c8","name":"Extract + Format Finder","func":"let Volt = msg.payload.devices[\"67362961\"].DataRecord[0].Value; \nlet Ampere = msg.payload.devices[\"67362961\"].DataRecord[1].Value;\nlet Power = msg.payload.devices[\"67362961\"].DataRecord[3].Value /1000;\nlet Energy = msg.payload.devices[\"67362961\"].DataRecord[5].Value /1000;\n\nlet _msg = {\n payload: []\n};\n\n_msg.payload=\n {\n measurement: \"HeatEnergy\",\n\t\tfields: {\n\t\t\tvolt: Volt,\t\t\t\n\t\t\tampere: Ampere,\t\n\t\t\tpower: Power,\t\n\t\t energy: Energy,\t\n\t\t},\n\t\ttags:{\n\t\t device: \"Finder\",\n\t\t},\n\t\ttimestamp: flow.get('timestamp')\n\t}\n\n\nreturn _msg;","outputs":1,"noerr":0,"x":370,"y":1040,"wires":[["5f3c8353.b9ceac"]]},{"id":"48586024.8ffe","type":"debug","z":"a4d1e87c.7813c8","name":"","active":false,"console":false,"complete":"false","x":770,"y":1040,"wires":[]},{"id":"5f3c8353.b9ceac","type":"join","z":"a4d1e87c.7813c8","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":590,"y":1040,"wires":[[]]},{"id":"b002634f.1d14d","type":"function","z":"a4d1e87c.7813c8","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 = Math.abs(msg.payload.devices[\"67362961\"].DataRecord[10].Value /100);\nvar PowerInstValue = Math.abs(msg.payload.devices[\"67362961\"].DataRecord[11].Value *100);\nvar FlowValue = msg.payload.devices[\"67362961\"].DataRecord[13].Value;\nvar FlowValuelm = Number((FlowValue/60).toFixed(2));\n\nlet _msg = {\n payload: []\n};\n\n_msg.payload=\n {\n measurement: \"kamstrup\",\n\t\tfields: {\n totalheatenergy : TotalHeatEnergy, \n totalcoolenergy : TotalCoolEnergy,\n flowtemperature : FlowTemperature, \n returntemperature : ReturnTemperature,\n difftemperature : DiffTemperature,\n powerinstvalue : PowerInstValue,\n flowvalue : FlowValue, \n flowvaluelm : FlowValuelm, \n\n\t\t },\n\t\ttags:{\n\t\t device: \"heatmeter\",\n\t\t },\n\t\ttimestamp: flow.get('timestamp')\n\t}\n\nreturn _msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":360,"wires":[["cfb18a5f.298128","3b81b908.fdd3b6"]]},{"id":"dd403e65.20135","type":"comment","z":"a4d1e87c.7813c8","name":"Change the device ID number","info":"","x":580,"y":400,"wires":[]},{"id":"f77f6134.8295b","type":"json","z":"a4d1e87c.7813c8","name":"","property":"payload","action":"obj","pretty":false,"x":309,"y":898,"wires":[["f7d473fc.864ae"]]},{"id":"fe9419a9.581398","type":"debug","z":"a4d1e87c.7813c8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":769,"y":918,"wires":[]},{"id":"f7d473fc.864ae","type":"function","z":"a4d1e87c.7813c8","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":529,"y":898,"wires":[["fe9419a9.581398"]]},{"id":"77db8efd.bfe4d","type":"influxdb batch","z":"a4d1e87c.7813c8","influxdb":"5d5dceb8.bef8","precision":"","retentionPolicy":"","name":"","x":1060,"y":360,"wires":[]},{"id":"41106582.fea0cc","type":"mbus-out","z":"a4d1e87c.7813c8","name":"","client":"cf258c74.2b793","x":410,"y":200,"wires":[["6b7e06bc.006f58"]]},{"id":"6b7e06bc.006f58","type":"debug","z":"a4d1e87c.7813c8","name":"","active":false,"console":false,"complete":"false","x":629,"y":200,"wires":[]},{"id":"c9da9dc7.9ffd","type":"inject","z":"a4d1e87c.7813c8","name":"scan","repeat":"","crontab":"","once":false,"topic":"scan","payload":"","payloadType":"str","x":101,"y":70,"wires":[["ad6e84cc.601248"]]},{"id":"43eb83c3.5aa82c","type":"inject","z":"a4d1e87c.7813c8","name":"Read ID 1","repeat":"","crontab":"","once":false,"topic":"getDevice","payload":"{\"address\": 1}","payloadType":"json","x":108,"y":144,"wires":[["ad6e84cc.601248"]]},{"id":"8267ca11.2aba68","type":"inject","z":"a4d1e87c.7813c8","name":"Get Devices","props":[{"p":"payload","v":"","vt":"str"},{"p":"topic","v":"getDevices","vt":"string"}],"repeat":"60","crontab":"","once":true,"onceDelay":"","topic":"getDevices","payload":"","payloadType":"str","x":124,"y":218,"wires":[["ad6e84cc.601248"]]},{"id":"cc3859b.9295ca8","type":"inject","z":"a4d1e87c.7813c8","name":"restart","repeat":"","crontab":"","once":false,"topic":"restart","payload":"","payloadType":"num","x":98,"y":106,"wires":[["ad6e84cc.601248"]]},{"id":"3c6331b.c0b14ce","type":"inject","z":"a4d1e87c.7813c8","name":"Read ID 2","repeat":"","crontab":"","once":false,"topic":"getDevice","payload":"{\"address\": 2}","payloadType":"json","x":109,"y":182,"wires":[["ad6e84cc.601248"]]},{"id":"46252092.fafe","type":"inject","z":"a4d1e87c.7813c8","name":"setPrimary","repeat":"","crontab":"","once":false,"topic":"setPrimary","payload":"{\"newAddr\":3,\"oldAddr\":2}","payloadType":"json","x":100,"y":33,"wires":[["ad6e84cc.601248"]]},{"id":"c2e0a50e.444818","type":"inject","z":"a4d1e87c.7813c8","name":"setDevices","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"setDevices","vt":"string"}],"repeat":"","crontab":"","once":false,"topic":"setDevices","payload":"","payloadType":"date","x":99,"y":258,"wires":[["bc3a51f.0101fb"]]},{"id":"bc3a51f.0101fb","type":"function","z":"a4d1e87c.7813c8","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":237,"y":258,"wires":[["ad6e84cc.601248"]]},{"id":"eb0ec644.7036b8","type":"comment","z":"a4d1e87c.7813c8","name":"Change the USB-port","info":"","x":460,"y":160,"wires":[]},{"id":"cfb18a5f.298128","type":"join","z":"a4d1e87c.7813c8","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":811,"y":362,"wires":[["77db8efd.bfe4d"]]},{"id":"a9fec91a.d93008","type":"mqtt out","z":"a4d1e87c.7813c8","name":"","topic":"","qos":"","retain":"","broker":"f935c11c.41462","x":1110,"y":400,"wires":[]},{"id":"fecbb531.0abf38","type":"mqtt in","z":"a4d1e87c.7813c8","name":"kamstrup","topic":"kamstrup","qos":"2","datatype":"json","broker":"f935c11c.41462","x":960,"y":520,"wires":[["1b76d099.6b974f"]]},{"id":"1b76d099.6b974f","type":"debug","z":"a4d1e87c.7813c8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1100,"y":520,"wires":[]},{"id":"b4afa47.7a36858","type":"join","z":"a4d1e87c.7813c8","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"8","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":970,"y":400,"wires":[["a9fec91a.d93008"]]},{"id":"3b81b908.fdd3b6","type":"change","z":"a4d1e87c.7813c8","name":"move to msg","rules":[{"t":"move","p":"payload.fields","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"kamstrup","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":400,"wires":[["b4afa47.7a36858"]]},{"id":"cf258c74.2b793","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":"ba35fc26.07964","type":"ui_group","z":"","name":"M-Bus Devices","tab":"97113de5.a76d7","order":3,"disp":true,"width":"14"},{"id":"447b5e0.211efa4","type":"ui_group","z":"","name":"Data","tab":"97113de5.a76d7","order":4,"disp":true,"width":"14"},{"id":"61c985c0.155d6c","type":"ui_group","z":"","name":"Commands","tab":"97113de5.a76d7","order":2,"disp":true,"width":"14"},{"id":"5d5dceb8.bef8","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"energy","name":"","usetls":false,"tls":""},{"id":"f935c11c.41462","type":"mqtt-broker","z":"","name":"MQTT","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"97113de5.a76d7","type":"ui_tab","z":"","name":"M-Bus","icon":"plug","order":1}]