[
    {
        "id": "backup_timer_inject",
        "type": "inject", 
        "z": "75e812ac222e6536",
        "name": "🔄 Backup Timer (55min)",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "3300",
        "crontab": "",
        "once": true,
        "onceDelay": 10,
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "x": 190,
        "y": 320,
        "wires": [
            [
                "backup_timer_check"
            ]
        ]
    },
    {
        "id": "backup_timer_check",
        "type": "function",
        "z": "75e812ac222e6536", 
        "name": "🕐 Backup Timer Check",
        "func": "// BACKUP TIMER - KONTROLA A REFRESH\nvar token_data = global.get('tuya_token') || {};\nvar now = Date.now();\n\nif (token_data.access_token && token_data.expires_at) {\n    var time_until_expiry = token_data.expires_at - now;\n    var minutes_until_expiry = Math.floor(time_until_expiry / 60000);\n    \n    // Pokud zbývá méně než 10 minut, spusť refresh\n    if (minutes_until_expiry < 10) {\n        node.warn('🔄 BACKUP TIMER: Spouštím refresh, zbývá ' + minutes_until_expiry + ' minut');\n        return msg;\n    } else {\n        node.warn('🔄 BACKUP TIMER: Token OK, zbývá ' + minutes_until_expiry + ' minut');\n        return null;\n    }\n} else {\n    // Žádný token - spusť refresh\n    node.warn('🔄 BACKUP TIMER: Žádný token, spouštím refresh');\n    return msg;\n}\n\nreturn null;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 320,
        "wires": [
            [
                "a44c9431cd86ddf2"
            ]
        ]
    }
]