[
    {
        "id": "7b9a0807.ce73c8",
        "type": "subflow",
        "name": "Lấy dữ từ iNut (10)",
        "info": "",
        "in": [
            {
                "x": 50,
                "y": 30,
                "wires": [
                    {
                        "id": "87c91422.62a1b8"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1000,
                "y": 280,
                "wires": [
                    {
                        "id": "eea5251a.05e808",
                        "port": 0
                    }
                ]
            }
        ],
        "inputLabels": [
            "Nhận đầu vào MQTT IN từ iNut cảm biến"
        ],
        "outputLabels": [
            "Luồng cảm biến 1"
        ]
    },
    {
        "id": "87c91422.62a1b8",
        "type": "json",
        "z": "7b9a0807.ce73c8",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 165,
        "y": 84,
        "wires": [
            [
                "ad0dbf89.1666b"
            ]
        ]
    },
    {
        "id": "eea5251a.05e808",
        "type": "switch",
        "z": "7b9a0807.ce73c8",
        "name": "Phân luồn",
        "property": "relayId",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 825.9869575500488,
        "y": 288.1562738418579,
        "wires": [
            []
        ]
    },
    {
        "id": "ad0dbf89.1666b",
        "type": "function",
        "z": "7b9a0807.ce73c8",
        "name": "Lặp",
        "func": "if (!msg.states) {\n    msg.states = msg.payload\n    msg.i = 0\n    return msg;\n} else {\n    msg.i++\n    if (msg.states[msg.i])\n        return msg;\n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 327.89060974121094,
        "y": 83.33600330352783,
        "wires": [
            [
                "9ad5ebb3.5fcbc8"
            ]
        ]
    },
    {
        "id": "9ad5ebb3.5fcbc8",
        "type": "function",
        "z": "7b9a0807.ce73c8",
        "name": "Lấy trạng thái thiết bị",
        "func": "msg.relayId = msg.i\nmsg.payload = msg.states[msg.i].state\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 477.89060974121094,
        "y": 183.33600330352783,
        "wires": [
            [
                "ad0dbf89.1666b",
                "eea5251a.05e808"
            ]
        ]
    },
    {
        "id": "7ca3223e.632e0c",
        "type": "subflow:7b9a0807.ce73c8",
        "z": "a03f7e6d.55604",
        "name": "",
        "x": 430,
        "y": 260,
        "wires": [
            [
                "b990965d.4e3c38"
            ]
        ]
    },
    {
        "id": "6cb706fa.834538",
        "type": "function",
        "z": "a03f7e6d.55604",
        "name": "",
        "func": "var command = msg.topic + ' ';\nif (msg.payload == 1) {\n    command = command + '1 OFF';\n} else {\n    command = command + '0 ON';\n}\nmsg.payload = {\n    id: 0,\n    command: command\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1450,
        "y": 200,
        "wires": [
            [
                "3eeaa6ea.33deea"
            ]
        ]
    },
    {
        "id": "eaa12ff5.7f651",
        "type": "ui_button",
        "z": "a03f7e6d.55604",
        "name": "",
        "group": "72aa2c44.6511e4",
        "order": 3,
        "width": "2",
        "height": "2",
        "passthru": false,
        "label": "OFF",
        "tooltip": "",
        "color": "RED",
        "bgcolor": "yellow",
        "icon": "",
        "payload": "0",
        "payloadType": "num",
        "topic": "LOCK",
        "x": 1270,
        "y": 220,
        "wires": [
            [
                "6cb706fa.834538"
            ]
        ]
    },
    {
        "id": "46aabd82.3304b4",
        "type": "ui_button",
        "z": "a03f7e6d.55604",
        "name": "",
        "group": "72aa2c44.6511e4",
        "order": 1,
        "width": "2",
        "height": "2",
        "passthru": false,
        "label": "ON",
        "tooltip": "",
        "color": "RED",
        "bgcolor": "yellow",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "LOCK",
        "x": 1270,
        "y": 180,
        "wires": [
            [
                "6cb706fa.834538"
            ]
        ]
    },
    {
        "id": "1575f5b.b7df10a",
        "type": "ui_text",
        "z": "a03f7e6d.55604",
        "group": "c16842a5.e4714",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Status",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "x": 1110,
        "y": 160,
        "wires": []
    },
    {
        "id": "cd16af16.09c5b",
        "type": "change",
        "z": "a03f7e6d.55604",
        "name": "ONLINE",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "ONLINE",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 960,
        "y": 120,
        "wires": [
            [
                "1575f5b.b7df10a",
                "3d53a718.5b8b58"
            ]
        ]
    },
    {
        "id": "a61218d.370e7e8",
        "type": "switch",
        "z": "a03f7e6d.55604",
        "name": "Kiểm tra ONLINE",
        "property": "payload.status",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "-1",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 790,
        "y": 160,
        "wires": [
            [
                "cd16af16.09c5b"
            ],
            [
                "a0e398cf.880838"
            ]
        ]
    },
    {
        "id": "a0e398cf.880838",
        "type": "change",
        "z": "a03f7e6d.55604",
        "name": "OFFLINE",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "OFFLINE",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 960,
        "y": 180,
        "wires": [
            [
                "1575f5b.b7df10a"
            ]
        ]
    },
    {
        "id": "99cf9920.2b8c68",
        "type": "json",
        "z": "a03f7e6d.55604",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 630,
        "y": 160,
        "wires": [
            [
                "a61218d.370e7e8"
            ]
        ]
    },
    {
        "id": "d39c7e26.477bf",
        "type": "inject",
        "z": "a03f7e6d.55604",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "x": 110,
        "y": 120,
        "wires": [
            [
                "b55a77df.292828"
            ]
        ]
    },
    {
        "id": "3eeaa6ea.33deea",
        "type": "link out",
        "z": "a03f7e6d.55604",
        "name": "OUT_RES_PORT",
        "links": [
            "b6df0cb7.9c668"
        ],
        "x": 1555,
        "y": 200,
        "wires": []
    },
    {
        "id": "b6df0cb7.9c668",
        "type": "link in",
        "z": "a03f7e6d.55604",
        "name": "REST_POST",
        "links": [
            "3850f97b.cf5b76",
            "3eeaa6ea.33deea",
            "b3ced61c.061d58",
            "361dbb9e.e7b7e4"
        ],
        "x": 35,
        "y": 180,
        "wires": [
            [
                "5efd3dcc.07ddc4"
            ]
        ]
    },
    {
        "id": "5b61d3a7.4d19bc",
        "type": "ui_gauge",
        "z": "a03f7e6d.55604",
        "name": "",
        "group": "72aa2c44.6511e4",
        "order": 2,
        "width": "2",
        "height": "2",
        "gtype": "gage",
        "title": "LOCK",
        "label": "units",
        "format": "{{value}}",
        "min": 0,
        "max": "1",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 770,
        "y": 300,
        "wires": []
    },
    {
        "id": "b4943ab2.a09298",
        "type": "link out",
        "z": "a03f7e6d.55604",
        "name": "RELOAD",
        "links": [
            "1548c7f6.656998"
        ],
        "x": 1575,
        "y": 100,
        "wires": []
    },
    {
        "id": "1548c7f6.656998",
        "type": "link in",
        "z": "a03f7e6d.55604",
        "name": "RELOAD",
        "links": [
            "b4943ab2.a09298"
        ],
        "x": 95,
        "y": 40,
        "wires": [
            [
                "b55a77df.292828"
            ]
        ]
    },
    {
        "id": "a3d75404.741bf8",
        "type": "change",
        "z": "a03f7e6d.55604",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "POST",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 470,
        "y": 180,
        "wires": [
            [
                "99cf9920.2b8c68"
            ]
        ]
    },
    {
        "id": "3d53a718.5b8b58",
        "type": "switch",
        "z": "a03f7e6d.55604",
        "name": "",
        "property": "topic",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "POST",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1110,
        "y": 100,
        "wires": [
            [
                "4eec935.cffc06c",
                "411c08fb.7f07e8"
            ]
        ]
    },
    {
        "id": "4eec935.cffc06c",
        "type": "delay",
        "z": "a03f7e6d.55604",
        "name": "",
        "pauseType": "delay",
        "timeout": "50",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 1270,
        "y": 80,
        "wires": [
            [
                "3892ce03.26e722"
            ]
        ]
    },
    {
        "id": "3892ce03.26e722",
        "type": "change",
        "z": "a03f7e6d.55604",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "topic",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1440,
        "y": 100,
        "wires": [
            [
                "b4943ab2.a09298"
            ]
        ]
    },
    {
        "id": "411c08fb.7f07e8",
        "type": "delay",
        "z": "a03f7e6d.55604",
        "name": "",
        "pauseType": "delay",
        "timeout": "250",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 1270,
        "y": 120,
        "wires": [
            [
                "3892ce03.26e722"
            ]
        ]
    },
    {
        "id": "e147a1d.b7cbe6",
        "type": "mqtt in",
        "z": "a03f7e6d.55604",
        "name": "[MQTT-IN]iNut cảm biến - iNut M1",
        "topic": "request/dkjTobCPXidsp7X1NqzKFQbQ4z02/SyVEreTK4/ccff6a10caddfc13fee619eb7065f4cb302880090088",
        "qos": "2",
        "broker": "5421618d.ae96c",
        "x": 160,
        "y": 260,
        "wires": [
            [
                "7ca3223e.632e0c"
            ]
        ]
    },
    {
        "id": "b55a77df.292828",
        "type": "http request",
        "z": "a03f7e6d.55604",
        "name": "[REST][GET]iNut cảm biến - iNut M1",
        "method": "GET",
        "ret": "txt",
        "url": "https://c...content-available-to-author-only...e.vn/api/1.0/request/dkjTobCPXidsp7X1NqzKFQbQ4z02/SyVEreTK4/ccff6a10caddfc13fee619eb7065f4cb302880090088/req_device",
        "tls": "",
        "x": 370,
        "y": 120,
        "wires": [
            [
                "99cf9920.2b8c68"
            ]
        ]
    },
    {
        "id": "5efd3dcc.07ddc4",
        "type": "http request",
        "z": "a03f7e6d.55604",
        "name": "[REST][POST]iNut cảm biến - iNut M1",
        "method": "POST",
        "ret": "txt",
        "url": "https://c...content-available-to-author-only...e.vn/api/1.0/request/dkjTobCPXidsp7X1NqzKFQbQ4z02/SyVEreTK4/ccff6a10caddfc13fee619eb7065f4cb302880090088/req_device_toggle",
        "tls": "",
        "x": 210,
        "y": 180,
        "wires": [
            [
                "a3d75404.741bf8"
            ]
        ]
    },
    {
        "id": "b990965d.4e3c38",
        "type": "change",
        "z": "a03f7e6d.55604",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Trạng Thái",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 610,
        "y": 260,
        "wires": [
            [
                "5b63ccaf.7c4fe4",
                "5b61d3a7.4d19bc"
            ]
        ]
    },
    {
        "id": "5b63ccaf.7c4fe4",
        "type": "function",
        "z": "a03f7e6d.55604",
        "name": "",
        "func": "var trangthai;\nif (msg.payload == 0) {\n    trangthai = \"Đóng\";\n}\nelse if (msg.payload == 1) {\n    trangthai = \"Mở\";\n}\nmsg.payload = trangthai;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 770,
        "y": 240,
        "wires": [
            [
                "ccfdd94f.6e6228"
            ]
        ]
    },
    {
        "id": "ccfdd94f.6e6228",
        "type": "ui_text",
        "z": "a03f7e6d.55604",
        "group": "72aa2c44.6511e4",
        "order": 0,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Trạng Thái: ",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "x": 950,
        "y": 240,
        "wires": []
    },
    {
        "id": "72aa2c44.6511e4",
        "type": "ui_group",
        "z": "",
        "name": "Group 1",
        "tab": "e59646ac.c34d18",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c16842a5.e4714",
        "type": "ui_group",
        "z": "",
        "name": "Group 2",
        "tab": "e59646ac.c34d18",
        "order": 2,
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "5421618d.ae96c",
        "type": "mqtt-broker",
        "name": "",
        "broker": "mqtt.mysmarthome.vn",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": ""
    },
    {
        "id": "e59646ac.c34d18",
        "type": "ui_tab",
        "name": "Tab 1",
        "icon": "dashboard",
        "order": 1
    }
]