[
{
"id": "6e802f1553b18149",
"type": "subflow",
"name": "JSON or Obj to IOBroker",
"info": "# Creates an IOBroker tree\n\nThis node creates an IOBroker tree out of an Java-Object or JSON String.\n\nThe object tree will be created under 0_userdata.0\nIn addition to the JSON-String or Java Object as `msg.payload` it is necessary to specify a `msg.top` properity in addition to the msg-Object.\n\nThe object tree will be created under 0_userdata.0\n\nExisting `msg.topic` entries will be deleted.\nAn iobroker-out node has to be appended to this subflow node. It is not part of the subflow itself. No topic should be specified in the iobroker out node.\n\nIs `msg.top` property isn't defined, the top-value of the node (environment variable top) is used. \n\n**Attention:**\nIf msg.top and top is empty, all msg.topics (msg.topic) will be directly prefixed with 0_userdata.0. . \n\n# Erstellt einen Objektbaum im ioBroker\n\nDiese Node erstellt einen Objektbaum im ioBroker aus einem JAVA Objekt bzw. einem JSON String. \n\nDer Baum wird in jedem Fall unter 0_userdata.0 erstellt und zwar unter dem Topic der in` msg.top` mitgegeben wurde. In der `msg.payload` befindet sich dann der JSON String oder das entsprechende Objekt.\n\nExistierende `msg.topic `Einträge werden gelöscht.\nEin entsprechende iobroker-out Node muss an den Flow angehängt werden. Sie ist nicht Bestandteil des Subflows. In dieser iobroker-out Node darf kein Topic angegeben werden. \n\nFalls msg.top nicht definiert wurde, wird der top-Wert (Umgebungsvariable top) der Node verwendet. <br>\n\n**Achtung:**\nWenn top und msg.top leer ist, werden alle msg.topics (msg.topic) direkt unter dem Präfix 0_userdata.0., angelegt bzw. ausgegeben. ",
"category": "",
"in": [
{
"x": 60,
"y": 160,
"wires": [
{
"id": "e023fe88445ce43e"
}
]
}
],
"out": [
{
"x": 2120,
"y": 280,
"wires": [
{
"id": "f5d52c6a57d08904",
"port": 0
},
{
"id": "74c895ce724750de",
"port": 0
}
]
}
],
"env": [
{
"name": "top",
"type": "str",
"value": "objRoot"
}
],
"meta": {},
"color": "#E2D96E",
"icon": "node-red/batch.svg"
},
{
"id": "3e11e8338f694832",
"type": "split",
"z": "6e802f1553b18149",
"name": "split object",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "key",
"x": 1170,
"y": 160,
"wires": [
[
"0562a4249c8b856b"
]
]
},
{
"id": "0562a4249c8b856b",
"type": "change",
"z": "6e802f1553b18149",
"name": "add key to topic",
"rules": [
{
"t": "set",
"p": "stateName",
"pt": "msg",
"to": "key",
"tot": "msg"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "topic & '.' & key",
"tot": "jsonata"
},
{
"t": "change",
"p": "topic",
"pt": "msg",
"from": " ",
"fromt": "str",
"to": "_",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1360,
"y": 160,
"wires": [
[
"ddc90985bef0fafa"
]
]
},
{
"id": "ddc90985bef0fafa",
"type": "switch",
"z": "6e802f1553b18149",
"name": "is type?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "istype",
"v": "array",
"vt": "array"
},
{
"t": "istype",
"v": "object",
"vt": "object"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 1540,
"y": 160,
"wires": [
[
"bfce19b206660fbe"
],
[
"3e11e8338f694832"
],
[
"1a8c03d866b85b12"
]
]
},
{
"id": "bfce19b206660fbe",
"type": "split",
"z": "6e802f1553b18149",
"name": "split array",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 580,
"y": 280,
"wires": [
[
"e89927810c6d75ec"
]
]
},
{
"id": "e89927810c6d75ec",
"type": "change",
"z": "6e802f1553b18149",
"name": "add index to topic",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "topic & '.' & parts.index",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 770,
"y": 280,
"wires": [
[
"a4d1a5d04564dc77"
]
]
},
{
"id": "f5d52c6a57d08904",
"type": "change",
"z": "6e802f1553b18149",
"name": "finalize msg.topic",
"rules": [
{
"t": "set",
"p": "top",
"pt": "msg",
"to": "'0_userdata.0.' & top",
"tot": "jsonata"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "top & topic",
"tot": "jsonata"
},
{
"t": "change",
"p": "topic",
"pt": "msg",
"from": "..",
"fromt": "str",
"to": ".",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1970,
"y": 240,
"wires": [
[]
]
},
{
"id": "c863dd7d651b2272",
"type": "switch",
"z": "6e802f1553b18149",
"name": "is type?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "istype",
"v": "json",
"vt": "json"
},
{
"t": "istype",
"v": "object",
"vt": "object"
},
{
"t": "istype",
"v": "array",
"vt": "array"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 4,
"x": 400,
"y": 160,
"wires": [
[
"158930afddd0780b"
],
[
"3e11e8338f694832"
],
[
"bfce19b206660fbe"
],
[
"a4d1a5d04564dc77"
]
]
},
{
"id": "158930afddd0780b",
"type": "json",
"z": "6e802f1553b18149",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 570,
"y": 120,
"wires": [
[
"3649300b4c233b10"
]
]
},
{
"id": "1a8c03d866b85b12",
"type": "switch",
"z": "6e802f1553b18149",
"name": "is msg.top != null",
"property": "top",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
},
{
"t": "null"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1750,
"y": 280,
"wires": [
[
"f5d52c6a57d08904"
],
[
"74c895ce724750de"
]
]
},
{
"id": "e023fe88445ce43e",
"type": "change",
"z": "6e802f1553b18149",
"name": "",
"rules": [
{
"t": "delete",
"p": "topic",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 210,
"y": 160,
"wires": [
[
"c863dd7d651b2272"
]
]
},
{
"id": "3649300b4c233b10",
"type": "switch",
"z": "6e802f1553b18149",
"name": "is array?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "istype",
"v": "array",
"vt": "array"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 700,
"y": 120,
"wires": [
[
"bfce19b206660fbe"
],
[
"3e11e8338f694832"
]
]
},
{
"id": "1b8480cd2df7ba3f",
"type": "comment",
"z": "6e802f1553b18149",
"name": "Array",
"info": "",
"x": 400,
"y": 280,
"wires": []
},
{
"id": "b3541807672be040",
"type": "comment",
"z": "6e802f1553b18149",
"name": "object",
"info": "",
"x": 1140,
"y": 100,
"wires": []
},
{
"id": "a4d1a5d04564dc77",
"type": "switch",
"z": "6e802f1553b18149",
"name": "is type?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "istype",
"v": "object",
"vt": "object"
},
{
"t": "istype",
"v": "array",
"vt": "array"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 960,
"y": 280,
"wires": [
[
"3e11e8338f694832"
],
[
"bfce19b206660fbe"
],
[
"1a8c03d866b85b12"
]
]
},
{
"id": "74c895ce724750de",
"type": "change",
"z": "6e802f1553b18149",
"name": "finalize msg.topic",
"rules": [
{
"t": "set",
"p": "top",
"pt": "msg",
"to": "top",
"tot": "env"
},
{
"t": "set",
"p": "top",
"pt": "msg",
"to": "'0_userdata.0.' & top",
"tot": "jsonata"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "top & topic",
"tot": "jsonata"
},
{
"t": "change",
"p": "topic",
"pt": "msg",
"from": "..",
"fromt": "str",
"to": ".",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1970,
"y": 320,
"wires": [
[]
]
},
{
"id": "c9b74b75fb88fae5",
"type": "comment",
"z": "2140b385.78fb7c",
"name": "Speedtest Internet",
"info": "",
"x": 190,
"y": 3600,
"wires": []
},
{
"id": "ca0931a9b59c5c60",
"type": "function",
"z": "2140b385.78fb7c",
"name": "Speedtest",
"func": "msg = {};\n\n(async () => {\n try {\n await speedTest({acceptLicense: true, acceptGdpr: true}).then(output => {\n msg.payload = output;\n// clearTimeout(myTimeout);\n node.send(msg);\n node.done();\n }).catch(err => {\n // An error has been returned by the Promise.\n // Do something with it...\n msg.error = {name: err.name, \n message:err.message};\n node.error(\"Error in try\",msg);\n node.done();\n});\n } catch (err) {\n node.error(\"Error in async\",{error: {name: err.name, message:err.message}});\n } \n})();\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "speedTest",
"module": "speedtest-net"
}
],
"x": 320,
"y": 3720,
"wires": [
[
"c05dc2ab8d6c3bf2"
]
]
},
{
"id": "96b2931dd2362824",
"type": "inject",
"z": "2140b385.78fb7c",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 170,
"y": 3720,
"wires": [
[
"ca0931a9b59c5c60"
]
]
},
{
"id": "c05dc2ab8d6c3bf2",
"type": "change",
"z": "2140b385.78fb7c",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.timestamp",
"pt": "msg",
"to": "$moment(payload.timestamp).format('DD.MM.YYYY HH:mm:ss')\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 3720,
"wires": [
[
"fcf68520386d279a"
]
]
},
{
"id": "fcf68520386d279a",
"type": "subflow:6e802f1553b18149",
"z": "2140b385.78fb7c",
"name": "",
"env": [
{
"name": "top",
"value": "speedTest",
"type": "str"
}
],
"x": 830,
"y": 3720,
"wires": [
[
"5df05b2321564d35"
]
]
},
{
"id": "5df05b2321564d35",
"type": "ioBroker out",
"z": "2140b385.78fb7c",
"name": "",
"topic": "",
"ack": "true",
"autoCreate": "true",
"stateName": "",
"role": "",
"payloadType": "",
"readonly": "true",
"stateUnit": "",
"stateMin": "",
"stateMax": "",
"x": 1060,
"y": 3720,
"wires": []
},
{
"id": "194a0d9b8bff3a64",
"type": "catch",
"z": "2140b385.78fb7c",
"name": "",
"scope": [
"ca0931a9b59c5c60"
],
"uncaught": false,
"x": 270,
"y": 3800,
"wires": [
[
"5f88c6f34f800ee0"
]
]
},
{
"id": "5f88c6f34f800ee0",
"type": "debug",
"z": "2140b385.78fb7c",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 430,
"y": 3800,
"wires": []
}
]