diff --git a/flows.json b/flows.json index 190dee4..e84ed0b 100644 --- a/flows.json +++ b/flows.json @@ -1109,8 +1109,8 @@ "f67a857ae75d906f", "a8dc4fab59fdefb4" ], - "x": 48, - "y": 4733, + "x": 68, + "y": 5153, "w": 1094, "h": 134, "info": "this is a fake device for kernel boot (ensure that one device is registered)" @@ -1131,8 +1131,8 @@ "1b98c37b3b7502e4", "f02b4584af0d800c" ], - "x": 654, - "y": 4759, + "x": 674, + "y": 5179, "w": 462, "h": 82 }, @@ -1152,11 +1152,246 @@ "eed8990163b1ca81", "7f76434616f622dc" ], - "x": 74, - "y": 4759, + "x": 94, + "y": 5179, "w": 542, "h": 82 }, + { + "id": "3a98a00afc60d7cd", + "type": "group", + "z": "ab51b1e8cad7b700", + "name": "auto - device", + "style": { + "fill": "#777777", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "63149b5b57a97c5b", + "3110fe9246e63b1e", + "5a56612ef35c5fd3" + ], + "x": 42, + "y": 4707, + "w": 6886, + "h": 366 + }, + { + "id": "63149b5b57a97c5b", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "3a98a00afc60d7cd", + "name": "", + "style": { + "fill": "#ffffff", + "label": true, + "stroke": "#ffC000", + "fill-opacity": "0.5" + }, + "nodes": [ + "bd21a8b1786d3ed2", + "4937527cddd45b61" + ], + "x": 68, + "y": 4733, + "w": 1664, + "h": 314 + }, + { + "id": "3110fe9246e63b1e", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "3a98a00afc60d7cd", + "name": "", + "style": { + "fill": "#ffffff", + "label": true, + "stroke": "#0070c0", + "fill-opacity": "0.5" + }, + "nodes": [ + "3be00f677c6457bd", + "266f4436dc45ce89" + ], + "x": 1768, + "y": 4793, + "w": 3294, + "h": 254 + }, + { + "id": "5a56612ef35c5fd3", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "3a98a00afc60d7cd", + "name": "", + "style": { + "fill": "#ffffff", + "label": true, + "stroke": "#92d04f", + "fill-opacity": "0.5" + }, + "nodes": [ + "874075d44d19869a", + "d9548e9b1a2e6f36" + ], + "x": 5108, + "y": 4793, + "w": 1794, + "h": 254 + }, + { + "id": "bd21a8b1786d3ed2", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "63149b5b57a97c5b", + "name": "auto - device - in", + "style": { + "fill": "#ffC000", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "d85fe6335a6eae7b", + "c3d88e1872a9789b", + "7f1a03ba2d4eb5d1", + "546f190f3ec0c90d" + ], + "x": 94, + "y": 4819, + "w": 612, + "h": 142 + }, + { + "id": "4937527cddd45b61", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "63149b5b57a97c5b", + "name": "auto - device - out", + "style": { + "fill": "#ffC000", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "3e1b4213132404be", + "80459ca7317cce90", + "e6d11d0438e20b80", + "0ff47b07b863d0ae", + "561aaceffe076a5d", + "8f4503a19f2f639e", + "b08802b0dbd9a58b" + ], + "x": 734, + "y": 4759, + "w": 972, + "h": 262 + }, + { + "id": "3be00f677c6457bd", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "3110fe9246e63b1e", + "name": "auto - source - in", + "style": { + "label": true, + "fill": "#0070c0", + "fill-opacity": "0.05" + }, + "nodes": [ + "ba77500cd9f7f6da", + "30220f4fe07e35a4", + "ac4653be6ea01477", + "1ceced58d0c32e85", + "24058eec92534b27", + "5460a158225a328b", + "d34f38f155583ff7", + "aa275d99ba85bee2", + "5891781e4a61525a", + "4908c2284e498338", + "411b13dfb3e989f0" + ], + "x": 1794, + "y": 4819, + "w": 1502, + "h": 202 + }, + { + "id": "266f4436dc45ce89", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "3110fe9246e63b1e", + "name": "auto - source - out", + "style": { + "fill": "#0070c0", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "14a0a0839924964f", + "06581753b7673f83", + "5e3cb9bb3266089b", + "0b32686fe74c253f", + "51b002c497ad57cd", + "83e8a9fa324dd4b9", + "bb1e8e34559c5a7f", + "6140ca98749acd85", + "70ae9d85820c14fb" + ], + "x": 3394, + "y": 4819, + "w": 1642, + "h": 202 + }, + { + "id": "874075d44d19869a", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "5a56612ef35c5fd3", + "name": "auto - metric - in", + "style": { + "fill": "#92d04f", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "7d45ca7ad7f363fe", + "a4e3db9cc35fc9eb", + "a2d25db2ace537ae", + "282bb73eb4892ab9", + "637b84024e725f38", + "f61f5fe80ddf6ff1" + ], + "x": 5134, + "y": 4819, + "w": 882, + "h": 82 + }, + { + "id": "d9548e9b1a2e6f36", + "type": "group", + "z": "ab51b1e8cad7b700", + "g": "5a56612ef35c5fd3", + "name": "auto - metric - out", + "style": { + "fill": "#92d04f", + "fill-opacity": "0.05", + "label": true + }, + "nodes": [ + "e93e8daa30075ae6", + "89d2eebcaafb5013", + "9c89a41128573752", + "b2ccb6a2a248015d", + "d318afa2a81e4ff9", + "9262e99e20e0e654", + "69041daa92bc0a8b" + ], + "x": 6114, + "y": 4819, + "w": 762, + "h": 202 + }, { "id": "22dd0707e6d3a364", "type": "Stackhero-InfluxDB-v2-Server", @@ -1980,7 +2215,8 @@ "g": "bbf7bb18989048e1", "name": "kernel - device", "links": [ - "7f76434616f622dc" + "7f76434616f622dc", + "80459ca7317cce90" ], "x": 135, "y": 780, @@ -2883,7 +3119,8 @@ "links": [ "8fdb5986494986cc", "e12bb3f8258f4439", - "f02b4584af0d800c" + "f02b4584af0d800c", + "06581753b7673f83" ], "x": 135, "y": 1260, @@ -2900,7 +3137,9 @@ "g": "20b116b788ef3f27", "name": "kernel - metric - loop", "mode": "link", - "links": [], + "links": [ + "7d45ca7ad7f363fe" + ], "x": 5195, "y": 1260, "wires": [] @@ -5910,8 +6149,8 @@ "links": [ "94c79b8f52f0b6ba" ], - "x": 695, - "y": 4800, + "x": 715, + "y": 5220, "wires": [ [ "1b98c37b3b7502e4" @@ -5964,8 +6203,8 @@ "from": "", "to": "", "reg": false, - "x": 890, - "y": 4800, + "x": 910, + "y": 5220, "wires": [ [ "f02b4584af0d800c" @@ -5982,8 +6221,8 @@ "links": [ "206c1fb4a48067df" ], - "x": 1075, - "y": 4800, + "x": 1095, + "y": 5220, "wires": [] }, { @@ -6034,8 +6273,8 @@ "from": "", "to": "", "reg": false, - "x": 350, - "y": 4800, + "x": 370, + "y": 5220, "wires": [ [ "7f76434616f622dc" @@ -6051,8 +6290,8 @@ "links": [ "25445f5a9b787a0a" ], - "x": 115, - "y": 4800, + "x": 135, + "y": 5220, "wires": [ [ "840c05ce502e7fdd" @@ -6069,8 +6308,8 @@ "links": [ "bfa594bf1f876c92" ], - "x": 575, - "y": 4800, + "x": 595, + "y": 5220, "wires": [] }, { @@ -6101,13 +6340,1269 @@ "z": "ab51b1e8cad7b700", "name": "", "incFlows": "Kernel,K.Routine", - "incSubflows": "", + "incSubflows": "*", "srcFolder": "src", "chkAutoFlow2Src": true, "x": 1220, "y": 60, "wires": [] }, + { + "id": "d85fe6335a6eae7b", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "bd21a8b1786d3ed2", + "name": "auto - device - in", + "links": [], + "x": 135, + "y": 4920, + "wires": [ + [ + "c3d88e1872a9789b" + ] + ] + }, + { + "id": "c3d88e1872a9789b", + "type": "function", + "z": "ab51b1e8cad7b700", + "g": "bd21a8b1786d3ed2", + "name": "check device", + "func": "// output 1 : error message\n// output 2 : device registration\n\n// script var\nvar msg = msg;\nvar newmsg = {};\n\nif (typeof msg === 'undefined'){\n return [null,null];\n}\n\n// check var existence\nif (typeof msg.bucket === 'undefined' ||\n typeof msg.model === 'undefined' ||\n typeof msg.id === 'undefined'\n) {\n node.status({\n fill: \"red\", shape: \"ring\", text: 'undefined device'});\n return [msg,null];\n}\n\n// recreate msg\nnewmsg = {\n 'bucket': msg.bucket,\n 'measurement': typeof msg.measurement === 'undefined' ? '' : msg.measurement,\n 'field': typeof msg.field === 'undefined' ? '' : msg.field,\n 'model': msg.model,\n 'option': typeof msg.option === 'undefined' ? 0 : msg.option,\n 'id': msg.id,\n 'payload':''\n};\n\nnode.status({ fill: 'green', shape: \"ring\", text: newmsg.model + ' / ' + newmsg.id });\nreturn [null,newmsg];", + "outputs": 2, + "timeout": "", + "noerr": 0, + "initialize": "\n", + "finalize": "\n", + "libs": [], + "x": 290, + "y": 4920, + "wires": [ + [ + "7f1a03ba2d4eb5d1" + ], + [ + "546f190f3ec0c90d" + ] + ] + }, + { + "id": "7f1a03ba2d4eb5d1", + "type": "debug", + "z": "ab51b1e8cad7b700", + "g": "bd21a8b1786d3ed2", + "name": "auto - device - uncomplete", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "true", + "targetType": "full", + "statusVal": "", + "statusType": "auto", + "x": 540, + "y": 4860, + "wires": [] + }, + { + "id": "546f190f3ec0c90d", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "bd21a8b1786d3ed2", + "name": "auto - device - in", + "mode": "link", + "links": [], + "x": 435, + "y": 4920, + "wires": [] + }, + { + "id": "3e1b4213132404be", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "auto - device - out", + "links": [], + "x": 775, + "y": 4980, + "wires": [ + [ + "0ff47b07b863d0ae" + ] + ] + }, + { + "id": "80459ca7317cce90", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "auto - device - out", + "mode": "link", + "links": [ + "bfa594bf1f876c92" + ], + "x": 1315, + "y": 4980, + "wires": [] + }, + { + "id": "e6d11d0438e20b80", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "register by protocols", + "rules": [ + { + "t": "set", + "p": "protocols[msg.protocol][msg.id]", + "pt": "global", + "to": "{\t 'bucket':msg.bucket,\t 'measurement':msg.measurement,\t 'field':msg.field,\t 'brand':msg.brand,\t 'model':msg.model,\t 'option':msg.option\t}", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 1580, + "y": 4860, + "wires": [ + [] + ] + }, + { + "id": "0ff47b07b863d0ae", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "brand exists", + "property": "brand", + "propertyType": "msg", + "rules": [ + { + "t": "istype", + "v": "string", + "vt": "string" + }, + { + "t": "else" + } + ], + "checkall": "false", + "repair": false, + "outputs": 2, + "x": 930, + "y": 4980, + "wires": [ + [ + "561aaceffe076a5d", + "8f4503a19f2f639e" + ], + [ + "80459ca7317cce90" + ] + ] + }, + { + "id": "561aaceffe076a5d", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "seen / xxx / number", + "rules": [ + { + "t": "set", + "p": "measurement", + "pt": "msg", + "to": "seen", + "tot": "str" + }, + { + "t": "set", + "p": "format", + "pt": "msg", + "to": "number", + "tot": "str" + }, + { + "t": "set", + "p": "default", + "pt": "msg", + "to": "", + "tot": "date" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 1150, + "y": 4920, + "wires": [ + [ + "80459ca7317cce90" + ] + ] + }, + { + "id": "8f4503a19f2f639e", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "subid exists", + "property": "subid", + "propertyType": "msg", + "rules": [ + { + "t": "istype", + "v": "string", + "vt": "string" + }, + { + "t": "else" + } + ], + "checkall": "false", + "repair": false, + "outputs": 2, + "x": 1130, + "y": 4860, + "wires": [ + [ + "b08802b0dbd9a58b" + ], + [ + "e6d11d0438e20b80" + ] + ] + }, + { + "id": "b08802b0dbd9a58b", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "4937527cddd45b61", + "name": "add subid to id", + "rules": [ + { + "t": "set", + "p": "id", + "pt": "msg", + "to": "msg.id&'.'&msg.subid", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 1340, + "y": 4800, + "wires": [ + [ + "e6d11d0438e20b80" + ] + ] + }, + { + "id": "ba77500cd9f7f6da", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "auto - source - in", + "links": [ + "a3594a90f69fe537", + "ebdbee7baef678a6", + "ed6bcbd32e72afe1" + ], + "x": 1835, + "y": 4920, + "wires": [ + [ + "30220f4fe07e35a4" + ] + ] + }, + { + "id": "30220f4fe07e35a4", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "split topic", + "rules": [ + { + "t": "set", + "p": "input", + "pt": "msg", + "to": "$split(msg.topic,'/')", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 1980, + "y": 4920, + "wires": [ + [ + "ac4653be6ea01477" + ] + ] + }, + { + "id": "ac4653be6ea01477", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "select protocol", + "property": "input[0]", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "zwave", + "vt": "str" + }, + { + "t": "eq", + "v": "zigbee", + "vt": "str" + }, + { + "t": "eq", + "v": "rfxcom2mqtt", + "vt": "str" + } + ], + "checkall": "false", + "repair": false, + "outputs": 3, + "x": 2180, + "y": 4920, + "wires": [ + [ + "1ceced58d0c32e85" + ], + [ + "5460a158225a328b" + ], + [ + "aa275d99ba85bee2" + ] + ] + }, + { + "id": "1ceced58d0c32e85", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "extract protocol values", + "rules": [ + { + "t": "set", + "p": "protocol", + "pt": "msg", + "to": "zwave", + "tot": "str" + }, + { + "t": "set", + "p": "id", + "pt": "msg", + "to": "input[1]", + "tot": "msg" + }, + { + "t": "set", + "p": "subid", + "pt": "msg", + "to": "input[3]", + "tot": "msg" + }, + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'zwave/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 2420, + "y": 4860, + "wires": [ + [ + "5891781e4a61525a" + ] + ] + }, + { + "id": "24058eec92534b27", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "auto - source - in", + "mode": "link", + "links": [], + "x": 3255, + "y": 4920, + "wires": [] + }, + { + "id": "5460a158225a328b", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "extract protocol values", + "rules": [ + { + "t": "set", + "p": "protocol", + "pt": "msg", + "to": "zigbee", + "tot": "str" + }, + { + "t": "set", + "p": "id", + "pt": "msg", + "to": "input[1]", + "tot": "msg" + }, + { + "t": "set", + "p": "subid", + "pt": "msg", + "to": "0", + "tot": "str" + }, + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'zigbee/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 2420, + "y": 4920, + "wires": [ + [ + "5891781e4a61525a" + ] + ] + }, + { + "id": "d34f38f155583ff7", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "device", + "rules": [ + { + "t": "set", + "p": "model", + "pt": "msg", + "to": "device.model", + "tot": "msg" + }, + { + "t": "set", + "p": "option", + "pt": "msg", + "to": "device.option", + "tot": "msg" + }, + { + "t": "set", + "p": "bucket", + "pt": "msg", + "to": "device.bucket", + "tot": "msg" + }, + { + "t": "set", + "p": "measurement", + "pt": "msg", + "to": "device.measurement", + "tot": "msg" + }, + { + "t": "set", + "p": "field", + "pt": "msg", + "to": "device.field", + "tot": "msg" + }, + { + "t": "set", + "p": "repeat", + "pt": "msg", + "to": "false", + "tot": "bool" + }, + { + "t": "delete", + "p": "device", + "pt": "msg" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 3130, + "y": 4920, + "wires": [ + [ + "24058eec92534b27" + ] + ] + }, + { + "id": "aa275d99ba85bee2", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "extract protocol values", + "rules": [ + { + "t": "set", + "p": "protocol", + "pt": "msg", + "to": "rfxcom", + "tot": "str" + }, + { + "t": "set", + "p": "id", + "pt": "msg", + "to": "input[2]", + "tot": "msg" + }, + { + "t": "set", + "p": "subid", + "pt": "msg", + "to": "input[3]", + "tot": "msg" + }, + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'rfxcom2mqtt/devices/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 2420, + "y": 4980, + "wires": [ + [ + "5891781e4a61525a" + ] + ] + }, + { + "id": "5891781e4a61525a", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "by full id", + "rules": [ + { + "t": "set", + "p": "full_id", + "pt": "msg", + "to": "msg.id&'.'&msg.subid", + "tot": "jsonata" + }, + { + "t": "set", + "p": "device", + "pt": "msg", + "to": "protocols[msg.protocol][msg.full_id]", + "tot": "global" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 2640, + "y": 4920, + "wires": [ + [ + "4908c2284e498338" + ] + ] + }, + { + "id": "4908c2284e498338", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "exists", + "property": "device", + "propertyType": "msg", + "rules": [ + { + "t": "istype", + "v": "object", + "vt": "object" + }, + { + "t": "else" + } + ], + "checkall": "false", + "repair": false, + "outputs": 2, + "x": 2810, + "y": 4920, + "wires": [ + [ + "d34f38f155583ff7" + ], + [ + "411b13dfb3e989f0" + ] + ] + }, + { + "id": "411b13dfb3e989f0", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "3be00f677c6457bd", + "name": "by _id", + "rules": [ + { + "t": "set", + "p": "device", + "pt": "msg", + "to": "protocols[msg.protocol][msg.id]", + "tot": "global" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 2970, + "y": 4960, + "wires": [ + [ + "d34f38f155583ff7" + ] + ] + }, + { + "id": "14a0a0839924964f", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "auto - source - out", + "links": [], + "x": 3435, + "y": 4860, + "wires": [ + [ + "06581753b7673f83", + "6140ca98749acd85" + ] + ] + }, + { + "id": "06581753b7673f83", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "auto - source - out", + "mode": "link", + "links": [ + "206c1fb4a48067df" + ], + "x": 4995, + "y": 4860, + "wires": [] + }, + { + "id": "5e3cb9bb3266089b", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "set measurement", + "rules": [ + { + "t": "set", + "p": "measurement", + "pt": "msg", + "to": "seen", + "tot": "str" + }, + { + "t": "set", + "p": "path", + "pt": "msg", + "to": "msg.bucket & '/' & msg.measurement & '/' & msg.field", + "tot": "jsonata" + }, + { + "t": "set", + "p": "payload", + "pt": "msg", + "to": "", + "tot": "date" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 3950, + "y": 4980, + "wires": [ + [ + "bb1e8e34559c5a7f" + ] + ] + }, + { + "id": "0b32686fe74c253f", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "limit to 15 min", + "property": "seen[msg.path]", + "propertyType": "msg", + "rules": [ + { + "t": "null" + }, + { + "t": "lt", + "v": "$number(msg.payload) - 900000", + "vt": "jsonata" + } + ], + "checkall": "false", + "repair": false, + "outputs": 2, + "x": 4620, + "y": 4980, + "wires": [ + [ + "51b002c497ad57cd" + ], + [ + "51b002c497ad57cd" + ] + ] + }, + { + "id": "51b002c497ad57cd", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "set flow stack", + "rules": [ + { + "t": "set", + "p": "#:(memoryOnly)::seen[msg.path]", + "pt": "flow", + "to": "", + "tot": "date" + }, + { + "t": "delete", + "p": "seen", + "pt": "msg" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 4840, + "y": 4980, + "wires": [ + [ + "06581753b7673f83" + ] + ] + }, + { + "id": "83e8a9fa324dd4b9", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "get flow stack", + "rules": [ + { + "t": "set", + "p": "seen", + "pt": "msg", + "to": "#:(memoryOnly)::seen", + "tot": "flow" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 4400, + "y": 4980, + "wires": [ + [ + "0b32686fe74c253f" + ] + ] + }, + { + "id": "bb1e8e34559c5a7f", + "type": "trigger", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "250 ms by path", + "op1": "", + "op2": "", + "op1type": "pay", + "op2type": "nul", + "duration": "250", + "extend": true, + "overrideDelay": false, + "units": "ms", + "reset": "", + "bytopic": "topic", + "topic": "path", + "outputs": 1, + "x": 4180, + "y": 4980, + "wires": [ + [ + "83e8a9fa324dd4b9" + ] + ] + }, + { + "id": "6140ca98749acd85", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "seen", + "property": "seen", + "propertyType": "msg", + "rules": [ + { + "t": "istype", + "v": "string", + "vt": "string" + }, + { + "t": "else" + } + ], + "checkall": "false", + "repair": false, + "outputs": 2, + "x": 3570, + "y": 4980, + "wires": [ + [ + "70ae9d85820c14fb" + ], + [ + "5e3cb9bb3266089b" + ] + ] + }, + { + "id": "70ae9d85820c14fb", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "266f4436dc45ce89", + "name": "set field", + "rules": [ + { + "t": "set", + "p": "field", + "pt": "msg", + "to": "seen", + "tot": "msg" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 3740, + "y": 4920, + "wires": [ + [ + "5e3cb9bb3266089b" + ] + ] + }, + { + "id": "7d45ca7ad7f363fe", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "auto - metric - in", + "links": [ + "031a6afd8300356a" + ], + "x": 5175, + "y": 4860, + "wires": [ + [ + "a4e3db9cc35fc9eb" + ] + ] + }, + { + "id": "a4e3db9cc35fc9eb", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "from device", + "rules": [ + { + "t": "set", + "p": "protocol", + "pt": "msg", + "to": "devices[msg.bucket][msg.measurement][msg.field]protocol", + "tot": "global" + }, + { + "t": "set", + "p": "model", + "pt": "msg", + "to": "devices[msg.bucket][msg.measurement][msg.field]model", + "tot": "global" + }, + { + "t": "set", + "p": "id", + "pt": "msg", + "to": "devices[msg.bucket][msg.measurement][msg.field]id", + "tot": "global" + }, + { + "t": "set", + "p": "option", + "pt": "msg", + "to": "devices[msg.bucket][msg.measurement][msg.field]option", + "tot": "global" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 5330, + "y": 4860, + "wires": [ + [ + "f61f5fe80ddf6ff1" + ] + ] + }, + { + "id": "a2d25db2ace537ae", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "model", + "property": "model", + "propertyType": "msg", + "rules": [ + { + "t": "nempty" + } + ], + "checkall": "false", + "repair": false, + "outputs": 1, + "x": 5690, + "y": 4860, + "wires": [ + [ + "282bb73eb4892ab9" + ] + ] + }, + { + "id": "282bb73eb4892ab9", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "id", + "property": "id", + "propertyType": "msg", + "rules": [ + { + "t": "nempty" + } + ], + "checkall": "false", + "repair": false, + "outputs": 1, + "x": 5850, + "y": 4860, + "wires": [ + [ + "637b84024e725f38" + ] + ] + }, + { + "id": "637b84024e725f38", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "auto - metric - in", + "mode": "link", + "links": [], + "x": 5975, + "y": 4860, + "wires": [] + }, + { + "id": "f61f5fe80ddf6ff1", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "874075d44d19869a", + "name": "protocol", + "property": "protocol", + "propertyType": "msg", + "rules": [ + { + "t": "nempty" + } + ], + "checkall": "false", + "repair": false, + "outputs": 1, + "x": 5520, + "y": 4860, + "wires": [ + [ + "a2d25db2ace537ae" + ] + ] + }, + { + "id": "e93e8daa30075ae6", + "type": "link in", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "auto - metric - out", + "links": [], + "x": 6155, + "y": 4920, + "wires": [ + [ + "9c89a41128573752" + ] + ] + }, + { + "id": "89d2eebcaafb5013", + "type": "link out", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "auto - metric - out", + "mode": "link", + "links": [ + "62dd3e8d6c87a0f9", + "6c324b24ca028984", + "de0c34e8104574b0" + ], + "x": 6835, + "y": 4920, + "wires": [] + }, + { + "id": "9c89a41128573752", + "type": "switch", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "select protocol", + "property": "protocol", + "propertyType": "msg", + "rules": [ + { + "t": "eq", + "v": "zwave", + "vt": "str" + }, + { + "t": "eq", + "v": "zigbee", + "vt": "str" + }, + { + "t": "eq", + "v": "rfxcom", + "vt": "str" + } + ], + "checkall": "false", + "repair": false, + "outputs": 3, + "x": 6320, + "y": 4920, + "wires": [ + [ + "d318afa2a81e4ff9" + ], + [ + "9262e99e20e0e654" + ], + [ + "69041daa92bc0a8b" + ] + ] + }, + { + "id": "b2ccb6a2a248015d", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "set topic", + "rules": [ + { + "t": "set", + "p": "topic", + "pt": "msg", + "to": "msg.prefix&'/'&msg.topic", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 6700, + "y": 4920, + "wires": [ + [ + "89d2eebcaafb5013" + ] + ] + }, + { + "id": "d318afa2a81e4ff9", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "set prefix", + "rules": [ + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'zwave/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 6520, + "y": 4860, + "wires": [ + [ + "b2ccb6a2a248015d" + ] + ] + }, + { + "id": "9262e99e20e0e654", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "set prefix", + "rules": [ + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'zigbee/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 6520, + "y": 4920, + "wires": [ + [ + "b2ccb6a2a248015d" + ] + ] + }, + { + "id": "69041daa92bc0a8b", + "type": "change", + "z": "ab51b1e8cad7b700", + "g": "d9548e9b1a2e6f36", + "name": "set prefix", + "rules": [ + { + "t": "set", + "p": "prefix", + "pt": "msg", + "to": "'rfxcom2mqtt/devices/'&msg.id", + "tot": "jsonata" + } + ], + "action": "", + "property": "", + "from": "", + "to": "", + "reg": false, + "x": 6520, + "y": 4980, + "wires": [ + [ + "b2ccb6a2a248015d" + ] + ] + }, { "id": "2623529da72f4fab", "type": "catch", diff --git a/src/Kernel/check_device2.js b/src/Kernel/check_device2.js new file mode 100644 index 0000000..f82dfee --- /dev/null +++ b/src/Kernel/check_device2.js @@ -0,0 +1,34 @@ +// output 1 : error message +// output 2 : device registration + +// script var +var msg = msg; +var newmsg = {}; + +if (typeof msg === 'undefined'){ + return [null,null]; +} + +// check var existence +if (typeof msg.bucket === 'undefined' || + typeof msg.model === 'undefined' || + typeof msg.id === 'undefined' +) { + node.status({ + fill: "red", shape: "ring", text: 'undefined device'}); + return [msg,null]; +} + +// recreate msg +newmsg = { + 'bucket': msg.bucket, + 'measurement': typeof msg.measurement === 'undefined' ? '' : msg.measurement, + 'field': typeof msg.field === 'undefined' ? '' : msg.field, + 'model': msg.model, + 'option': typeof msg.option === 'undefined' ? 0 : msg.option, + 'id': msg.id, + 'payload':'' +}; + +node.status({ fill: 'green', shape: "ring", text: newmsg.model + ' / ' + newmsg.id }); +return [null,newmsg]; \ No newline at end of file diff --git a/src/Kernel/check_device2_finalizejs b/src/Kernel/check_device2_finalizejs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/Kernel/check_device2_finalizejs @@ -0,0 +1 @@ + diff --git a/src/Kernel/check_device2_initializejs b/src/Kernel/check_device2_initializejs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/Kernel/check_device2_initializejs @@ -0,0 +1 @@ + diff --git a/src/manifest.json b/src/manifest.json index fb5fabd..d9c8d08 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -49,6 +49,21 @@ "property": "finalize", "file": "Kernel/set_gate_message2_finalizejs" }, + { + "id": "c3d88e1872a9789b", + "property": "func", + "file": "Kernel/check_device2.js" + }, + { + "id": "c3d88e1872a9789b", + "property": "initialize", + "file": "Kernel/check_device2_initializejs" + }, + { + "id": "c3d88e1872a9789b", + "property": "finalize", + "file": "Kernel/check_device2_finalizejs" + }, { "id": "0385dd3208b83d41", "property": "func",