[
    {
        "id": "d4e8c2f1.2b173",
        "type": "tab",
        "label": "🔄 Bily Primotop AUTO TOKEN + CONTROL",
        "disabled": false,
        "info": "AUTO TOKEN REFRESH PRO BILY PRIMOTOP D1 1,5kW\nDatacenter: US West (openapi.tuyaus.com)\nDevice: ebafafd9cd55a9bc02994x\nSAFETY BUFFER: 45 minut\nRefresh interval: 75 minut",
        "env": []
    },
    {
        "id": "7ec88ab29e6f2672",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🔧 PRIMOTOP TOKEN STORE",
        "func": "// GLOBÁLNÍ STORAGE PRO PRIMOTOP ACCESS TOKEN\n// Inicializace při startu Node-RED\n\nif (!global.get('primotop_token')) {\n    global.set('primotop_token', {\n        access_token: null,\n        expires_at: 0,\n        last_refresh: 0\n    });\n    node.warn('🔄 Primotop token storage inicializován');\n} else {\n    var token_data = global.get('primotop_token');\n    node.warn('📊 Primotop token status: ' + JSON.stringify(token_data));\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 160,
        "y": 60,
        "wires": [
            []
        ]
    },
    {
        "id": "f6f295a2553c838e",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "⏰ Primotop Auto Refresh (75min)",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "4500",
        "crontab": "",
        "once": true,
        "onceDelay": 5,
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "x": 200,
        "y": 140,
        "wires": [
            [
                "db98989ce683d43a"
            ]
        ]
    },
    {
        "id": "67b391a5dff8ded1",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "🔄 Manual Primotop Token",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "db98989ce683d43a"
            ]
        ]
    },
    {
        "id": "db98989ce683d43a",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "📝 Primotop Token Request",
        "func": "// PRIMOTOP TOKEN REQUEST PŘÍPRAVA - EU DATACENTER\nvar access_id = \"xmjrf7s594ek7ngm9sm3\";\nvar access_secret = \"ba95b549499349a688397f84cbb096fa\";\n\nvar timestamp = Date.now().toString();\nvar method = \"GET\";\nvar url_path = \"/v1.0/token?grant_type=1\";\n\n// Pro GET token request je content hash vždy prázdný string hash\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\nvar string_to_sign = method + \"\\n\" + content_hash + \"\\n\" + \"\\n\" + url_path;\n\n// Pro token request NEPOUŽÍVÁME access_token (nemáme ho ještě)\nvar sign_str = access_id + timestamp + string_to_sign;\n\n// Příprava pro HMAC node\nmsg.payload = sign_str;\nmsg.key = access_secret;\n\n// Uložíme data pro další použití\nmsg.tuya_data = {\n    access_id: access_id,\n    timestamp: timestamp\n};\n\nnode.warn(\"🔄 REQUESTING PRIMOTOP TOKEN (75min refresh)\");\nnode.warn(\"⏰ Timestamp: \" + timestamp);\nnode.warn(\"🔧 Sign string: \" + sign_str.substring(0, 50) + \"...\");\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 200,
        "y": 280,
        "wires": [
            [
                "f4453d0ccf622258"
            ]
        ]
    },
    {
        "id": "f4453d0ccf622258",
        "type": "hmac",
        "z": "d4e8c2f1.2b173",
        "name": "🔐 Primotop Token HMAC",
        "algorithm": "HmacSHA256",
        "key": "key",
        "value": "payload",
        "x": 420,
        "y": 280,
        "wires": [
            [
                "233b3764b460f600"
            ]
        ]
    },
    {
        "id": "233b3764b460f600",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🌐 Primotop Token HTTP",
        "func": "// SESTAVENÍ HTTP REQUEST PRO PRIMOTOP TOKEN\nvar signature = msg.payload.toUpperCase();\nvar data = msg.tuya_data;\n\nmsg.headers = {\n    \"Content-Type\": \"application/json\",\n    \"client_id\": data.access_id,\n    \"sign\": signature,\n    \"t\": data.timestamp,\n    \"sign_method\": \"HMAC-SHA256\"\n};\n\nmsg.payload = \"\"; // Prázdný payload pro GET\n\nnode.warn(\"✅ PRIMOTOP TOKEN SIGNATURE: \" + signature);\nnode.warn(\"🌐 REQUESTING TOKEN FROM US WEST\");\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 640,
        "y": 280,
        "wires": [
            [
                "90bfc977dff727d5"
            ]
        ]
    },
    {
        "id": "90bfc977dff727d5",
        "type": "http request",
        "z": "d4e8c2f1.2b173",
        "name": "🔑 Primotop Token API",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "https://openapi.tuyaus.com/v1.0/token?grant_type=1",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 860,
        "y": 280,
        "wires": [
            [
                "bd6212365d158a03"
            ]
        ]
    },
    {
        "id": "bd6212365d158a03",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "💾 Primotop Token Storage",
        "func": "// ULOŽENÍ NOVÉHO PRIMOTOP TOKENU DO GLOBAL STORAGE\nvar response = msg.payload;\n\nif (response.success && response.result && response.result.access_token) {\n    var access_token = response.result.access_token;\n    var expire_time = response.result.expire_time || 7200; // default 2h\n    var now = Date.now();\n    \n    // Uložíme token do global storage\n    global.set('primotop_token', {\n        access_token: access_token,\n        expires_at: now + (expire_time * 1000),\n        last_refresh: now\n    });\n    \n    node.warn(\"✅ PRIMOTOP TOKEN ULOŽEN ÚSPĚŠNĚ!\");\n    node.warn(\"🔑 Token: \" + access_token.substring(0, 20) + \"...\");\n    node.warn(\"⏰ Expires in: \" + expire_time + \" seconds (45min safety buffer)\");\n    \n    // Pošleme potvrzení\n    msg.payload = {\n        success: true,\n        token: access_token,\n        expires_in: expire_time\n    };\n} else {\n    node.error(\"❌ PRIMOTOP TOKEN REQUEST FAILED!\");\n    node.error(\"Response: \" + JSON.stringify(response));\n    \n    msg.payload = {\n        success: false,\n        error: response\n    };\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1100,
        "y": 280,
        "wires": [
            [
                "bb1f38db51f01991"
            ]
        ]
    },
    {
        "id": "bb1f38db51f01991",
        "type": "debug",
        "z": "d4e8c2f1.2b173",
        "name": "🔑 Primotop Token Response",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1340,
        "y": 280,
        "wires": []
    },
    {
        "id": "cbe8584fbef52aa8",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "🕐 Primotop Timer (10s)",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "10",
        "crontab": "",
        "once": true,
        "onceDelay": 2,
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "x": 180,
        "y": 380,
        "wires": [
            [
                "40c92a60b0aca106"
            ]
        ]
    },
    {
        "id": "40c92a60b0aca106",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🕐 Primotop Timer Status",
        "func": "// PRIMOTOP TIMER STATUS UPDATE\nvar token_data = global.get('primotop_token') || {};\nvar now = Date.now();\n\nif (token_data.access_token) {\n    var expires_at = token_data.expires_at || 0;\n    var last_refresh = token_data.last_refresh || 0;\n    \n    // Výpočet zbývajícího času\n    var time_until_expiry = expires_at - now;\n    var time_since_refresh = now - last_refresh;\n    \n    // Převod na minuty\n    var minutes_until_expiry = Math.floor(time_until_expiry / 60000);\n    var minutes_since_refresh = Math.floor(time_since_refresh / 60000);\n    \n    var status_text = \"\";\n    var status_fill = \"green\";\n    \n    if (time_until_expiry <= 0) {\n        status_text = \"❌ PRIMOTOP TOKEN EXPIRED!\";\n        status_fill = \"red\";\n    } else if (minutes_until_expiry < 5) {\n        status_text = \"🚨 \" + minutes_until_expiry + \"min KRITICKÉ!\";\n        status_fill = \"red\";\n    } else if (minutes_until_expiry < 15) {\n        status_text = \"⚠️ \" + minutes_until_expiry + \"min do expirace\";\n        status_fill = \"yellow\";\n    } else if (minutes_until_expiry < 30) {\n        status_text = \"🔄 \" + minutes_until_expiry + \"min (OK)\";\n        status_fill = \"blue\";\n    } else {\n        status_text = \"✅ \" + minutes_until_expiry + \"min (SAFE)\";\n        status_fill = \"green\";\n    }\n    \n    // Zobrazení v node status\n    node.status({\n        fill: status_fill,\n        shape: \"dot\",\n        text: status_text\n    });\n    \n    // PRE-EMPTIVE REFRESH při < 10 minutách\n    if (minutes_until_expiry < 10 && minutes_until_expiry > 0) {\n        node.warn(\"🚨 PRIMOTOP PRE-EMPTIVE REFRESH at \" + minutes_until_expiry + \" minutes!\");\n        \n        var last_preemptive = global.get('primotop_last_preemptive_refresh') || 0;\n        if (now - last_preemptive > 300000) { // Aspoň 5 minut od posledního\n            global.set('primotop_last_preemptive_refresh', now);\n            node.warn(\"🔄 EXECUTING PRIMOTOP PRE-EMPTIVE TOKEN REFRESH!\");\n            \n            var refreshMsg = { payload: {}, preemptive: true };\n            return [msg, refreshMsg];\n        }\n    }\n    \n    msg.payload = {\n        token_present: true,\n        token_preview: token_data.access_token.substring(0, 20) + \"...\",\n        expires_in_minutes: minutes_until_expiry,\n        refreshed_ago_minutes: minutes_since_refresh,\n        status: status_text,\n        safety_buffer: minutes_until_expiry > 30 ? \"SAFE\" : \"LOW\"\n    };\n    \n} else {\n    node.status({\n        fill: \"red\",\n        shape: \"dot\",\n        text: \"❌ Žádný primotop token!\"\n    });\n    \n    msg.payload = {\n        token_present: false,\n        status: \"No primotop token available\"\n    };\n}\n\nreturn [msg, null];",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 380,
        "wires": [
            [
                "7bfe4f0fbd7867ec"
            ],
            [
                "db98989ce683d43a"
            ]
        ]
    },
    {
        "id": "7bfe4f0fbd7867ec",
        "type": "debug",
        "z": "d4e8c2f1.2b173",
        "name": "🕐 Primotop Timer Info",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 380,
        "wires": []
    },
    {
        "id": "31f73c91719206f2",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "🟢 PRIMOTOP ON",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"command\": \"on\"}",
        "payloadType": "json",
        "x": 140,
        "y": 500,
        "wires": [
            [
                "9b42bcf518bc7c2a"
            ]
        ]
    },
    {
        "id": "ae033bf7a5ae1b42",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "🔴 PRIMOTOP OFF",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"command\": \"off\"}",
        "payloadType": "json",
        "x": 150,
        "y": 560,
        "wires": [
            [
                "9b42bcf518bc7c2a"
            ]
        ]
    },
    {
        "id": "151f0181f992471d",
        "type": "inject",
        "z": "d4e8c2f1.2b173",
        "name": "❓ PRIMOTOP STATUS",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"command\": \"status\"}",
        "payloadType": "json",
        "x": 150,
        "y": 620,
        "wires": [
            [
                "9b42bcf518bc7c2a"
            ]
        ]
    },
    {
        "id": "9b42bcf518bc7c2a",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🎯 Primotop Command Prepare",
        "func": "// PRIMOTOP COMMAND PŘÍPRAVA S AUTO TOKEN\nvar access_id = \"xmjrf7s594ek7ngm9sm3\";\nvar access_secret = \"ba95b549499349a688397f84cbb096fa\";\nvar device_id = \"ebafafd9cd55a9bc02994x\";\n\n// Získání aktuálního tokenu z global storage\nvar token_data = global.get('primotop_token');\nif (!token_data || !token_data.access_token) {\n    node.error(\"❌ ŽÁDNÝ PRIMOTOP TOKEN! Spusť token refresh.\");\n    node.status({\n        fill: \"red\",\n        shape: \"dot\",\n        text: \"❌ Žádný token!\"\n    });\n    return null;\n}\n\n// Kontrola expirační doby\nvar now = Date.now();\nvar time_until_expiry = token_data.expires_at - now;\nvar minutes_until_expiry = Math.floor(time_until_expiry / 60000);\n\nif (time_until_expiry <= 0) {\n    node.error(\"❌ PRIMOTOP TOKEN EXPIRED! Spusť token refresh.\");\n    node.status({\n        fill: \"red\",\n        shape: \"dot\",\n        text: \"❌ Token expired!\"\n    });\n    return null;\n} else if (minutes_until_expiry < 5) {\n    node.warn(\"⚠️ PRIMOTOP TOKEN EXPIRING SOON: \" + minutes_until_expiry + \" minutes!\");\n}\n\nvar access_token = token_data.access_token;\nvar command = msg.payload.command || \"on\";\n\n// Status update\nnode.status({\n    fill: \"blue\",\n    shape: \"dot\",\n    text: \"🔄 \" + command.toUpperCase() + \" (\" + minutes_until_expiry + \"min)\"\n});\n\n// Rozhodnutí mezi GET (status) a POST (ovládání)\nif (command === \"status\") {\n    // GET request pro status\n    var timestamp = Date.now().toString();\n    var method = \"GET\";\n    var url_path = \"/v1.0/devices/\" + device_id;\n    var content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n    var string_to_sign = method + \"\\n\" + content_hash + \"\\n\" + \"\\n\" + url_path;\n    \n    msg.tuya_data = {\n        access_id: access_id,\n        access_token: access_token,\n        timestamp: timestamp,\n        device_id: device_id,\n        method: method,\n        url_path: url_path,\n        command_name: command\n    };\n    \n    var sign_str = access_id + access_token + timestamp + string_to_sign;\n    msg.payload = sign_str;\n    msg.key = access_secret;\n    \n    node.warn(\"❓ PŘÍPRAVA GET PRIMOTOP STATUS REQUEST\");\n} else {\n    // POST request pro switch control\n    var switch_value = (command === \"on\") ? true : false;\n    var commands = [{\"code\": \"switch_1\", \"value\": switch_value}];\n    var body = JSON.stringify({\"commands\": commands});\n    \n    msg.tuya_data = {\n        access_id: access_id,\n        access_secret: access_secret,\n        access_token: access_token,\n        device_id: device_id,\n        commands: commands,\n        body: body,\n        command_name: command,\n        method: \"POST\"\n    };\n    \n    // Připravíme body pro digest node\n    msg.payload = body;\n    \n    node.warn(\"🎯 PŘÍPRAVA PRIMOTOP \" + command.toUpperCase() + \" COMMAND\");\n    node.warn(\"📍 Switch value: \" + switch_value);\n}\n\nnode.warn(\"🔑 Primotop token: \" + access_token.substring(0, 20) + \"... (expires in \" + minutes_until_expiry + \"min)\");\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 560,
        "wires": [
            [
                "dab584153c0c75eb"
            ]
        ]
    },
    {
        "id": "dab584153c0c75eb",
        "type": "switch",
        "z": "d4e8c2f1.2b173",
        "name": "🔀 Primotop Method Router",
        "property": "tuya_data.method",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "GET",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "POST",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 680,
        "y": 560,
        "wires": [
            [
                "efbbc6b65c8a0b25"
            ],
            [
                "d842fc3d367df2b1"
            ]
        ]
    },
    {
        "id": "efbbc6b65c8a0b25",
        "type": "hmac",
        "z": "d4e8c2f1.2b173",
        "name": "🔐 GET Primotop Status HMAC",
        "algorithm": "HmacSHA256",
        "key": "key",
        "value": "payload",
        "x": 900,
        "y": 500,
        "wires": [
            [
                "ee35982515987c5e"
            ]
        ]
    },
    {
        "id": "ee35982515987c5e",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🌐 GET Primotop Status HTTP",
        "func": "// GET PRIMOTOP STATUS HTTP REQUEST\nvar signature = msg.payload.toUpperCase();\nvar data = msg.tuya_data;\n\nmsg.headers = {\n    \"Content-Type\": \"application/json\",\n    \"client_id\": data.access_id,\n    \"access_token\": data.access_token,\n    \"sign\": signature,\n    \"t\": data.timestamp,\n    \"sign_method\": \"HMAC-SHA256\"\n};\n\nmsg.url = \"https://openapi.tuyaus.com\" + data.url_path;\nmsg.method = \"GET\";\nmsg.payload = \"\";\n\nnode.warn(\"❓ ODESÍLÁM GET PRIMOTOP STATUS REQUEST\");\nnode.warn(\"🔗 URL: \" + msg.url);\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1160,
        "y": 500,
        "wires": [
            [
                "9da66193fb776d39"
            ]
        ]
    },
    {
        "id": "d842fc3d367df2b1",
        "type": "digest",
        "z": "d4e8c2f1.2b173",
        "name": "📝 POST Primotop Body Digest",
        "algorithm": "SHA256",
        "x": 920,
        "y": 620,
        "wires": [
            [
                "3c132132833ee88c"
            ]
        ]
    },
    {
        "id": "3c132132833ee88c",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🔧 POST Primotop HMAC Prepare",
        "func": "// POST PRIMOTOP COMMAND HMAC PŘÍPRAVA\nvar data = msg.tuya_data;\nvar body_hash = msg.payload; // Z digest node\n\nvar timestamp = Date.now().toString();\nvar method = \"POST\";\nvar url_path = \"/v1.0/devices/\" + data.device_id + \"/commands\";\nvar string_to_sign = method + \"\\n\" + body_hash + \"\\n\" + \"\\n\" + url_path;\n\n// KRITICKÉ: Signature s access_token!\nvar sign_str = data.access_id + data.access_token + timestamp + string_to_sign;\n\nmsg.payload = sign_str;\nmsg.key = data.access_secret;\nmsg.tuya_data.timestamp = timestamp;\nmsg.tuya_data.url_path = url_path;\n\nnode.warn(\"🔧 POST PRIMOTOP HMAC s ACCESS_TOKEN\");\nnode.warn(\"🔑 Body hash: \" + body_hash);\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1200,
        "y": 620,
        "wires": [
            [
                "3ccb2bd834fd65f6"
            ]
        ]
    },
    {
        "id": "3ccb2bd834fd65f6",
        "type": "hmac",
        "z": "d4e8c2f1.2b173",
        "name": "🔐 POST Primotop Command HMAC",
        "algorithm": "HmacSHA256",
        "key": "key",
        "value": "payload",
        "x": 1460,
        "y": 620,
        "wires": [
            [
                "e5535fd1900759de"
            ]
        ]
    },
    {
        "id": "e5535fd1900759de",
        "type": "function",
        "z": "d4e8c2f1.2b173",
        "name": "🌐 POST Primotop Command HTTP",
        "func": "// POST PRIMOTOP COMMAND HTTP REQUEST\nvar signature = msg.payload.toUpperCase();\nvar data = msg.tuya_data;\n\nmsg.headers = {\n    \"Content-Type\": \"application/json\",\n    \"client_id\": data.access_id,\n    \"access_token\": data.access_token,\n    \"sign\": signature,\n    \"t\": data.timestamp,\n    \"sign_method\": \"HMAC-SHA256\"\n};\n\nmsg.url = \"https://openapi.tuyaus.com\" + data.url_path;\nmsg.method = \"POST\";\nmsg.payload = {\"commands\": data.commands};\n\nnode.warn(\"🎯 ODESÍLÁM PRIMOTOP \" + data.command_name.toUpperCase() + \" COMMAND\");\nnode.warn(\"🔗 URL: \" + msg.url);\nnode.warn(\"📤 Commands: \" + JSON.stringify(data.commands));\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1220,
        "y": 680,
        "wires": [
            [
                "9da66193fb776d39"
            ]
        ]
    },
    {
        "id": "9da66193fb776d39",
        "type": "http request",
        "z": "d4e8c2f1.2b173",
        "name": "🔌 Primotop API Request",
        "method": "use",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1470,
        "y": 560,
        "wires": [
            [
                "039f56c61e3cff5e"
            ]
        ]
    },
    {
        "id": "039f56c61e3cff5e",
        "type": "debug",
        "z": "d4e8c2f1.2b173",
        "name": "🔌 Primotop Response",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1720,
        "y": 560,
        "wires": []
    },
    {
        "id": "895d1b4449191660",
        "type": "comment",
        "z": "d4e8c2f1.2b173",
        "name": "🔄 BILY PRIMOTOP D1 1,5kW - AUTO TOKEN + CONTROL (75min refresh)",
        "info": "KOMPLETNÍ FLOW PRO BILY PRIMOTOP D1 1,5kW\n\n📋 SPECIFIKACE:\n✅ Device: Bily primotop D1 1,5kW (ebafafd9cd55a9bc02994x)\n✅ Datacenter: US West (openapi.tuyaus.com)\n✅ Access ID: xmjrf7s594ek7ngm9sm3\n✅ Refresh interval: 75 minut (4500s)\n✅ Safety buffer: 45 minut\n✅ Auto-start: 5 sekund po deploy\n✅ Pre-emptive refresh: < 10 minut\n\n🔧 JAK POUŽÍVAT:\n1. Importuj a deploy tento flow\n2. Počkaj 5 sekund na první token refresh\n3. Sleduj Timer Status - měl by zobrazovat \"SAFE\" status\n4. Používej PRIMOTOP ON/OFF pro ovládání\n5. GET STATUS pro kontrolu stavu\n\n⚙️ FUNKCE:\n- Auto token refresh každých 75 minut\n- Pre-emptive refresh při < 10 minutách\n- Token status monitoring každých 10 sekund\n- Kompletní error handling\n- US West datacenter optimalizace\n- Unique storage keys (primotop_token)\n\n🛡️ SAFETY:\n- 45 minut safety buffer\n- Token expiry validation\n- Duplicate refresh protection\n- Enhanced status reporting\n- Pre-emptive warnings",
        "x": 360,
        "y": 20,
        "wires": []
    }
]