[
    {
        "id": "be73bf4f07831cb5",
        "type": "tab",
        "label": "userflow_GKO2",
        "disabled": false,
        "info": ""
    },
    {
        "id": "24697701250aa8bc",
        "type": "ui_dropdown",
        "z": "be73bf4f07831cb5",
        "name": "",
        "label": "GOK Senso4s (Waage 2)",
        "tooltip": "",
        "place": "Select option",
        "group": "79036640c7152101",
        "order": 8,
        "width": 0,
        "height": 0,
        "passthru": false,
        "multiple": false,
        "options": [],
        "payload": "",
        "topic": "topic",
        "topicType": "msg",
        "className": "",
        "x": 330,
        "y": 220,
        "wires": [
            [
                "4dcf1dd0d41ba60d"
            ]
        ]
    },
    {
        "id": "4dcf1dd0d41ba60d",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "select mac (Waage 2)",
        "func": "if (msg.payload == \"\" || msg.payload == \"no bt scale\") {\n    global.set(\"scalemac2\", 0)\n    msg.payload = 0\n    return [msg, null];\n}\nelse if (msg.payload == \"insert manually\") {\n    msg.payload = \"Please enter the MAC adddress (Waage 2):\"\n    return [null, msg]\n}\nelse {\n    msg.scalemac = msg.payload.substring(0,17);\n    global.set(\"scalemac2\", msg.scalemac)\n    msg.payload = msg.scalemac\n    return [msg, null];\n}\n",
        "outputs": 2,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 220,
        "wires": [
            [
                "1a69b4d851e57bc3",
                "029c3b5bbd7c32bc"
            ],
            [
                "882b08b754e896c7"
            ]
        ]
    },
    {
        "id": "882b08b754e896c7",
        "type": "ui_toast",
        "z": "be73bf4f07831cb5",
        "position": "prompt",
        "displayTime": "3",
        "highlight": "",
        "sendall": false,
        "outputs": 1,
        "ok": "OK",
        "cancel": "Cancel",
        "raw": false,
        "className": "",
        "topic": "",
        "name": "Prompt MAC (Waage 2)",
        "x": 1030,
        "y": 220,
        "wires": [
            [
                "d3b1db491a31c231"
            ]
        ]
    },
    {
        "id": "d3b1db491a31c231",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "manual mac (Waage 2)",
        "func": "if (msg.payload == \"Cancel\") {\n    global.set(\"scalemac2\", 0)\n    return null\n}\nelse {\n    global.set(\"scalemac2\", msg.payload.trim())\n    msg.payload = global.get(\"scalemac2\");\n    return msg\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1300,
        "y": 220,
        "wires": [
            [
                "1a69b4d851e57bc3",
                "029c3b5bbd7c32bc"
            ]
        ]
    },
    {
        "id": "1a69b4d851e57bc3",
        "type": "file",
        "z": "be73bf4f07831cb5",
        "name": "save MAC (Waage 2)",
        "filename": "pekaway/MACbtscale_2",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 1580,
        "y": 220,
        "wires": [
            [
                "8011603f6e3f5268"
            ]
        ]
    },
    {
        "id": "e79e7be5d469333d",
        "type": "file in",
        "z": "be73bf4f07831cb5",
        "name": "load MAC (Waage 2)",
        "filename": "pekaway/MACbtscale_2",
        "filenameType": "str",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 320,
        "y": 80,
        "wires": [
            [
                "8011603f6e3f5268"
            ]
        ]
    },
    {
        "id": "8011603f6e3f5268",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "apply MAC (Waage 2)",
        "func": "if (msg.payload == 0) {\n    msg.payload = \"turned off\"\n    node.send([null, msg])\n    global.set(\"scalemac2\", msg.payload)\n}\nelse if (msg.payload == \"Scan Bluetooth first\") {\n    var scanfirst = msg.payload\n    msg.payload = \"turned off\"\n    node.send([null, msg])\n    global.set(\"scalemac2\", msg.payload)\n    msg.payload = scanfirst\n}\nelse {\n    global.set(\"scalemac2\", msg.payload)\n}\nreturn [msg, null];",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 80,
        "wires": [
            [
                "ab3a89b9a9b505a1"
            ],
            [
                "5a07105a416366af"
            ]
        ]
    },
    {
        "id": "ab3a89b9a9b505a1",
        "type": "ui_text",
        "z": "be73bf4f07831cb5",
        "group": "79036640c7152101",
        "order": 9,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Currently set (Waage 2):",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": "",
        "color": "#000000",
        "x": 1750,
        "y": 80,
        "wires": []
    },
    {
        "id": "fd75757bc83de0f1",
        "type": "inject",
        "z": "be73bf4f07831cb5",
        "name": "3h Intervall (Waage 2)",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "5400",
        "crontab": "",
        "once": true,
        "onceDelay": "120",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 340,
        "y": 320,
        "wires": [
            [
                "029c3b5bbd7c32bc"
            ]
        ]
    },
    {
        "id": "029c3b5bbd7c32bc",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "build cmd (Waage 2)",
        "func": "if (flow.get(\"ble_scan\") == true) { return null }\n\nmsg.payload = global.get(\"scalemac2\");\nif(msg.payload == undefined || msg.payload == \"turn off\" || msg.payload == 0 || msg.payload == \"turned off\" || msg.payload == \"Scan Bluetooth first\") {\n    return null;\n}\nelse {\n    msg.payload = \"python3 pekaway/ble_py/goksenso4.py -d \" + global.get(\"scalemac2\");\n    return msg;\n}",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 680,
        "y": 320,
        "wires": [
            [
                "7c7a2966be7c7b1d"
            ]
        ]
    },
    {
        "id": "7c7a2966be7c7b1d",
        "type": "exec",
        "z": "be73bf4f07831cb5",
        "command": "",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "exec python (Waage 2)",
        "x": 1020,
        "y": 320,
        "wires": [
            [
                "9de54d1b118216d2"
            ],
            [],
            []
        ]
    },
    {
        "id": "9de54d1b118216d2",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "parse value (Waage 2)",
        "func": "if (msg.payload.includes(\"timed out\")) {\n    return msg\n}\nelse {\n    msg.payload = msg.payload.substring(2,msg.payload.length-2);\n    msg.payload = parseInt(msg.payload,16)+ \"%\";\n    global.set(\"gokvalue2\",msg.payload);\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1300,
        "y": 320,
        "wires": [
            [
                "5a07105a416366af"
            ]
        ]
    },
    {
        "id": "5a07105a416366af",
        "type": "ui_text",
        "z": "be73bf4f07831cb5",
        "group": "79036640c7152101",
        "order": 10,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "GOK Senso4s (Waage 2):",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": "",
        "color": "#000000",
        "x": 1750,
        "y": 300,
        "wires": []
    },
    {
        "id": "f9fb83af335b5efe",
        "type": "link in",
        "z": "be73bf4f07831cb5",
        "name": "link in 2",
        "links": [
            "8e3719a4e81ac70b"
        ],
        "x": 135,
        "y": 60,
        "wires": [
            [
                "24697701250aa8bc",
                "e79e7be5d469333d"
            ]
        ]
    },
    {
        "id": "a8b89a1e7b1f3c22",
        "type": "inject",
        "z": "be73bf4f07831cb5",
        "name": "Update Gas alle 10s",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "180",
        "crontab": "",
        "once": true,
        "onceDelay": "2",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 340,
        "y": 440,
        "wires": [
            [
                "c1b2f9b7b5d74a33"
            ]
        ]
    },
    {
        "id": "c1b2f9b7b5d74a33",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "Set global Gas_re / Gas_li",
        "func": "function toPct(v) {\n  if (v === undefined || v === null) return null;\n  let s = String(v).trim().replace('%', '').trim();\n  let n = Number(s);\n  if (!isFinite(n)) return null;\n  if (n > 100) n = 100;\n  if (n < 0) n = 0;\n  return Math.round(n);\n}\n\n// Waagenwerte lesen\nconst w_re = toPct(global.get('gokvalue'));   // Waage 1 -> rechts (anpassen falls vertauscht)\nconst w_li = toPct(global.get('gokvalue2'));  // Waage 2 -> links\n\n// Intern: sprechende Namen\nif (w_re !== null) global.set('Gas_re', w_re);\nif (w_li !== null) global.set('Gas_li', w_li);\n\n// Für externes Display (fixes Layout): Level3/4 + Namen\nglobal.set('NLevel3', 'Gas_li');\nglobal.set('NLevel4', 'Gas_re');\n\nif (w_li !== null) global.set('Level3', w_li); // Level3 = Gas_li\nif (w_re !== null) global.set('Level4', w_re); // Level4 = Gas_re\n\n// Debug-Ausgabe\nmsg.payload = { Gas_re: global.get('Gas_re'), Gas_li: global.get('Gas_li') };\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 440,
        "wires": [
            [
                "2ec112141ebee1b4",
                "ad5f5a2f2c9b4f44"
            ]
        ]
    },
    {
        "id": "2ec112141ebee1b4",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "Map Gas -> Level3/4 + Namen",
        "func": "// Erwartet: msg.payload = { Gas_re: <0-100>, Gas_li: <0-100> }\n\n// 1) Labels fürs Display setzen\nglobal.set(\"NLevel3\", \"Gas_li\");\nglobal.set(\"NLevel4\", \"Gas_re\");\n\n// optional: wenn Level1/2 Namen NICHT gesetzt sind, lasse sie wie sie sind\n// global.set(\"NLevel1\", global.get(\"NLevel1\") || \"Level1\");\n// global.set(\"NLevel2\", global.get(\"NLevel2\") || \"Level2\");\n\n// 2) Werte fürs Display setzen (Layout fix: Level3/4)\nconst gas_li = Number(msg.payload?.Gas_li);\nconst gas_re = Number(msg.payload?.Gas_re);\n\nif (!isNaN(gas_li)) global.set(\"Level3\", gas_li);\nif (!isNaN(gas_re)) global.set(\"Level4\", gas_re);\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1050,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "ad5f5a2f2c9b4f44",
        "type": "debug",
        "z": "be73bf4f07831cb5",
        "name": "Debug Gas Werte",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1010,
        "y": 520,
        "wires": []
    },
    {
        "id": "8159e2b07fb5a311",
        "type": "inject",
        "z": "be73bf4f07831cb5",
        "name": "check Namen",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "5",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 860,
        "y": 620,
        "wires": [
            [
                "aefd234e18feb74f"
            ]
        ]
    },
    {
        "id": "aefd234e18feb74f",
        "type": "function",
        "z": "be73bf4f07831cb5",
        "name": "function 16",
        "func": "msg.payload = {\n    NLevel3: global.get(\"NLevel3\"),\n    NLevel4: global.get(\"NLevel4\"),\n    Level3: global.get(\"Level3\"),\n    Level4: global.get(\"Level4\")\n};\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 620,
        "wires": [
            [
                "82f7415277be3163"
            ]
        ]
    },
    {
        "id": "82f7415277be3163",
        "type": "debug",
        "z": "be73bf4f07831cb5",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1200,
        "y": 620,
        "wires": []
    },
    {
        "id": "79036640c7152101",
        "type": "ui_group",
        "name": "BMS",
        "tab": "12cb65b3e6f05eef",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "12cb65b3e6f05eef",
        "type": "ui_tab",
        "name": "BMS",
        "icon": "dashboard",
        "order": 24,
        "disabled": false,
        "hidden": true
    }
]