[
    {
        "id": "9a0f038b6c5e0822",
        "type": "inject",
        "z": "4555023a25c6bada",
        "name": "Inject every 30 secs",
        "props": [],
        "repeat": "10",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "x": 160,
        "y": 180,
        "wires": [
            [
                "84816eeb6163580d"
            ]
        ]
    },
    {
        "id": "1cfe91d1d7df72d9",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device1-ToYggio",
        "topic": "yggio/generic/v2/node-red-device-1",
        "qos": "",
        "retain": "true",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 180,
        "wires": []
    },
    {
        "id": "84816eeb6163580d",
        "type": "function",
        "z": "4555023a25c6bada",
        "name": "Simulate values",
        "func": "var count = context.get('count')||0;\nvar countPre = context.get('countPre')||0;\nvar cos = context.get('cos')||0;\n// Saw tooth\nif (count<11){\n    countPre = count;\n    count += 0.5;\n} else if (count>24){\n    countPre = count;\n    count -=0.5;\n} else if (count > countPre){\n    countPre = count;\n    count += 0.5;\n} else {\n    countPre = count;\n    count -= 0.5;\n}  \n\n// Cosinus\ncos += 0.05;\nif (cos > (Math.PI * 2)) \n{\n    cos = 0;\n}\nlet temp = {\n    \"log\" : {\n        \"alarmText\" : \"Intrusion detected\",\n        \"priority\" : \"1\",\n        \"severity\" : \"2\"\n    },\n    \"dsmr\": {\n        \"reading\": {\n            \"electricity_currently_delivered\": 9\n        }\n    },\n\n    \"tempSaw\": count + (Math.round(Math.random() * 200)/100),\n    \"tempCosinus\": (Math.round(Math.cos(cos) * 100)/10+14),\n    \"temperature\": (Math.round(Math.cos(cos) * 110)/10+15),\n    \"averageTemperature\": (Math.round(Math.cos(cos) * 120)/10 + 15),\n    \"humidity\": (Math.round(Math.random() * 8990)/100+10),\n    \"relativeHumidity\": (Math.round(Math.random() * 8990)/100+10),\n    \"alarmFlood\": count % 2 === 0 ? true : false,\n    \"floodAlarm\": count % 2 === 0 ? true : false,\n    \"presence\": count % 3 === 0 ? 1 : 0,  \n    \"analog1\": (Math.round(Math.cos(cos) * 100) / 10 + 14)\n};\ncontext.set('count', count);\ncontext.set('countPre', countPre);\ncontext.set('cos', cos);\nmsg.payload = temp;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is star",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 180,
        "wires": [
            [
                "1cfe91d1d7df72d9"
            ]
        ]
    },
    {
        "id": "2687e87e5a8f1bdf",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 360,
        "y": 240,
        "wires": [
            [
                "d3ab8361896e556b"
            ]
        ]
    },
    {
        "id": "d3ab8361896e556b",
        "type": "function",
        "z": "4555023a25c6bada",
        "name": "Offset values",
        "func": "//let payload = JSON.parse(msg.payload);\nlet payload = msg.payload;\nlet temp = {\n    \"tempSaw\": payload.iotnode.tempSaw + 4,\n    \"tempCosinus\": payload.iotnode.tempCosinus + 5,\n    \"temperature\": payload.iotnode.temperature + 3,\n    \"humidity\": payload.iotnode.humidity - 5,\n    \"relativeHumidity\": payload.iotnode.relativeHumidity - 6,\n    \"averageTemperature\": payload.iotnode.averageTemperature - 3.5,\n    \"alarmFlood\": payload.iotnode.alarmFlood,\n    \"floodAlarm\": payload.iotnode.floodAlarm,\n    \"presence\": payload.iotnode.presence  \n};\nmsg.payload = temp;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 240,
        "wires": [
            [
                "42c5e871ae0e6954",
                "20e869f1cb887080"
            ]
        ]
    },
    {
        "id": "42c5e871ae0e6954",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device2-ToYggio2",
        "topic": "yggio/generic/v2/node-red-device-2",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 240,
        "wires": []
    },
    {
        "id": "8eece396fc44b8df",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device3-ToYggio",
        "topic": "yggio/generic/v2/node-red-device-3",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 300,
        "wires": []
    },
    {
        "id": "e4b767315f9b0b22",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device4-ToYggio",
        "topic": "yggio/generic/v2/node-red-device-4",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 360,
        "wires": []
    },
    {
        "id": "037a3ed4c55f45c3",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device5-ToYggio",
        "topic": "yggio/generic/v2/node-red-device-5",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 420,
        "wires": []
    },
    {
        "id": "20e869f1cb887080",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 740,
        "y": 300,
        "wires": [
            [
                "06ca62c8da6a6d6d",
                "8eece396fc44b8df"
            ]
        ]
    },
    {
        "id": "06ca62c8da6a6d6d",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 740,
        "y": 360,
        "wires": [
            [
                "9851a27f3ea35148",
                "e4b767315f9b0b22"
            ]
        ]
    },
    {
        "id": "9851a27f3ea35148",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 740,
        "y": 420,
        "wires": [
            [
                "037a3ed4c55f45c3",
                "0ead6768b42c7e0d"
            ]
        ]
    },
    {
        "id": "00052be4e9333417",
        "type": "http request",
        "z": "4555023a25c6bada",
        "name": "Login to Yggio",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "staging.yggio.net/api/auth/local",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 540,
        "y": 40,
        "wires": [
            [
                "21b3ab9a9edac6c4"
            ]
        ]
    },
    {
        "id": "36fd047e7a9527a9",
        "type": "http request",
        "z": "4555023a25c6bada",
        "name": "GET /iotnodes",
        "method": "use",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 740,
        "y": 80,
        "wires": [
            [
                "d23d86b313cfa672"
            ]
        ]
    },
    {
        "id": "21b3ab9a9edac6c4",
        "type": "function",
        "z": "4555023a25c6bada",
        "name": "Save token",
        "func": "var token = JSON.parse(msg.payload).token // global.get(\"token\")\nglobal.set(\"token\", token);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 40,
        "wires": [
            [
                "d23d86b313cfa672"
            ]
        ]
    },
    {
        "id": "08d3f0b9804ced3b",
        "type": "inject",
        "z": "4555023a25c6bada",
        "name": "Inject every 30 secs",
        "props": [],
        "repeat": "600",
        "crontab": "",
        "once": true,
        "onceDelay": "10",
        "topic": "",
        "x": 160,
        "y": 80,
        "wires": [
            [
                "e315c9f006274f3d",
                "33dd47c6df27d687"
            ]
        ]
    },
    {
        "id": "1f707954f60bd05e",
        "type": "inject",
        "z": "4555023a25c6bada",
        "name": "Start",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"username\":\"myaccount\",\"password\":\"mypassword\"}",
        "payloadType": "json",
        "x": 110,
        "y": 40,
        "wires": [
            [
                "00052be4e9333417"
            ]
        ]
    },
    {
        "id": "9d89f0ec1e12109d",
        "type": "function",
        "z": "4555023a25c6bada",
        "name": "Prepare API call",
        "func": "let token = global.get(\"token\");\nlet currentTime = Date.now() - 3600 * 1000 - 48;\nlet baseURL = \"https://staging.yggio.net/api\"\nmsg.payload = null;\nmsg.method ='GET';\nmsg.url = baseURL + \"/iotnodes/62c2f4360e40a40009351013/stats?measurement=value_temperature&start=\" + currentTime.toString();\nmsg.headers = {};\nmsg.headers['Authorization'] = 'Bearer '+ token\nmsg.headers['accept'] = 'application/json'\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 540,
        "y": 120,
        "wires": [
            [
                "afe88dd89836c6cd"
            ]
        ]
    },
    {
        "id": "afe88dd89836c6cd",
        "type": "http request",
        "z": "4555023a25c6bada",
        "name": "GET /iotnodes/stats",
        "method": "use",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 750,
        "y": 120,
        "wires": [
            [
                "d23d86b313cfa672"
            ]
        ]
    },
    {
        "id": "d23d86b313cfa672",
        "type": "debug",
        "z": "4555023a25c6bada",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 990,
        "y": 40,
        "wires": []
    },
    {
        "id": "e315c9f006274f3d",
        "type": "function",
        "z": "4555023a25c6bada",
        "name": "Prepare API call",
        "func": "let token = global.get(\"token\");\nmsg.payload = null\nmsg.method ='GET'\nmsg.url = \"https://staging.yggio.net/api/iotnodes\"\nmsg.headers = {}\nmsg.headers['Authorization'] = 'Bearer '+ token\nmsg.headers['accept'] = 'application/json'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 540,
        "y": 80,
        "wires": [
            [
                "36fd047e7a9527a9"
            ]
        ]
    },
    {
        "id": "33dd47c6df27d687",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 380,
        "y": 120,
        "wires": [
            [
                "9d89f0ec1e12109d"
            ]
        ]
    },
    {
        "id": "264184b23bc94316",
        "type": "mqtt out",
        "z": "4555023a25c6bada",
        "name": "Device6-ToYggio",
        "topic": "yggio/generic/v2/node-red-device-6",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a326f47a38bcd1",
        "x": 990,
        "y": 480,
        "wires": []
    },
    {
        "id": "0ead6768b42c7e0d",
        "type": "delay",
        "z": "4555023a25c6bada",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 740,
        "y": 480,
        "wires": [
            [
                "264184b23bc94316"
            ]
        ]
    },
    {
        "id": "34e9a4ec2011ad89",
        "type": "mqtt in",
        "z": "4555023a25c6bada",
        "name": "Device1-FromYggio",
        "topic": "yggio/output/v2/62c2e8d4035d7600097e02ef/iotnode/63ff86f7888908a081f0abfd",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "23a326f47a38bcd1",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 170,
        "y": 240,
        "wires": [
            [
                "2687e87e5a8f1bdf"
            ]
        ]
    },
    {
        "id": "23a326f47a38bcd1",
        "type": "mqtt-broker",
        "name": "Staging - Node Red",
        "broker": "mqtt.staging.yggio.net",
        "port": "1883",
        "tls": "",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]