[
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "0be32359c079a1e8",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Turn Relay ON",
        "props": [
            {
                "p": "desired_relay_state",
                "v": "on",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 290,
        "y": 900,
        "wires": [
            [
                "b675d32820af3caa"
            ]
        ]
    },
    {
        "id": "b79b54baca3fadcd",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Turn Relay OFF",
        "props": [
            {
                "p": "desired_relay_state",
                "v": "off",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 300,
        "y": 1060,
        "wires": [
            [
                "b675d32820af3caa"
            ]
        ]
    },
    {
        "id": "b675d32820af3caa",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Prepare Request",
        "func": "msg.rejectUnauthorized = false;\n\nmsg.url = 'https://' + flow.get('ip_address') + ':443/api/v0/devices/' + flow.get('device_guid') + '/functions/relay';\n\nmsg.headers = {};\nmsg.headers['Authorization'] = flow.get('api_key');\n\n\nmsg.payload = { 'type': 'enumeration', \n                'identifier': 'relay',\n                'value': msg.desired_relay_state \n            };\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 900,
        "wires": [
            [
                "f4af20aae6b96148"
            ]
        ]
    },
    {
        "id": "f4af20aae6b96148",
        "type": "http request",
        "z": "f6f2187d.f17ca8",
        "name": "Control relay",
        "method": "PUT",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 890,
        "y": 900,
        "wires": [
            [
                "d4249c29eb0457d9"
            ]
        ]
    },
    {
        "id": "d4249c29eb0457d9",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "log response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1190,
        "y": 900,
        "wires": []
    },
    {
        "id": "85516dc926a08627",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Set IP Address",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 300,
        "y": 440,
        "wires": [
            [
                "f8ef2d61fa55c1b8"
            ]
        ]
    },
    {
        "id": "16273047b67c1c38",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Prepare Request",
        "func": "msg.rejectUnauthorized = false;\n\nmsg.url = 'https://' + flow.get('ip_address') + ':443/api/v0/login';\n\nmsg.headers = {};\n\nmsg.payload = { 'user': 'admin', \n                'password': flow.get('pop')\n            };\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 600,
        "wires": [
            [
                "1c7f3ae914375910"
            ]
        ]
    },
    {
        "id": "f8ef2d61fa55c1b8",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "ip_address",
                "pt": "flow",
                "to": "192.168.8.173",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "33725dfedb651f19",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Set proof of possesion (POP)",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 340,
        "y": 520,
        "wires": [
            [
                "6fa8930d6d2ea414"
            ]
        ]
    },
    {
        "id": "6fa8930d6d2ea414",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "pop",
                "pt": "flow",
                "to": "LZ6W0Y48",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 590,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "3a4e94566d7e3dce",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Get API Key",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 290,
        "y": 600,
        "wires": [
            [
                "16273047b67c1c38"
            ]
        ]
    },
    {
        "id": "b8f1b4bbcc47f6fb",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "api_key",
                "pt": "flow",
                "to": "payload.apiKey",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 980,
        "y": 600,
        "wires": [
            [
                "1c02aca5ac9c208e"
            ]
        ]
    },
    {
        "id": "1c7f3ae914375910",
        "type": "http request",
        "z": "f6f2187d.f17ca8",
        "name": "Log in",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 730,
        "y": 600,
        "wires": [
            [
                "b8f1b4bbcc47f6fb"
            ]
        ]
    },
    {
        "id": "1c02aca5ac9c208e",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "log response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload.apiKey",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1210,
        "y": 600,
        "wires": []
    },
    {
        "id": "9e479d3458f23736",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "Prepare Request",
        "func": "msg.rejectUnauthorized = false;\n\nmsg.url = 'https://' + flow.get('ip_address') + ':443/api/v0/devices';\n\nmsg.headers = {};\nmsg.headers['Authorization'] = flow.get('api_key');\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 720,
        "wires": [
            [
                "7b8627b24a29a469"
            ]
        ]
    },
    {
        "id": "22a9b7c92cb9dae9",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "Get device GUID",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 300,
        "y": 720,
        "wires": [
            [
                "9e479d3458f23736"
            ]
        ]
    },
    {
        "id": "48bdf8315591aa49",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "device_guid",
                "pt": "flow",
                "to": "payload[0].deviceGuid",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1000,
        "y": 720,
        "wires": [
            [
                "ba17df49d47ade2f"
            ]
        ]
    },
    {
        "id": "7b8627b24a29a469",
        "type": "http request",
        "z": "f6f2187d.f17ca8",
        "name": "Get devices",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 750,
        "y": 720,
        "wires": [
            [
                "48bdf8315591aa49"
            ]
        ]
    },
    {
        "id": "ba17df49d47ade2f",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "log response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload[0].deviceGuid",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1210,
        "y": 720,
        "wires": []
    }
]