[
 {
  "id": "46a53aae.a18f74",
  "type": "server",
  "name": "Home Assistant"
 },
 {
  "id": "6ac5a410.6dcd3c",
  "type": "server",
  "name": "Home Assistant",
  "version": 6,
  "rejectUnauthorizedCerts": true,
  "ha_boolean": [
   "y",
   "yes",
   "true",
   "on",
   "home",
   "open"
  ],
  "connectionDelay": false,
  "cacheJson": true,
  "heartbeat": false,
  "heartbeatInterval": "30",
  "areaSelector": "friendlyName",
  "deviceSelector": "friendlyName",
  "entitySelector": "friendlyName",
  "statusSeparator": "at: ",
  "statusYear": "hidden",
  "statusMonth": "short",
  "statusDay": "numeric",
  "statusHourCycle": "h23",
  "statusTimeFormat": "h:m",
  "enableGlobalContextStore": true
 },
 {
  "id": "a5d7b21f983f0d93",
  "type": "tab",
  "label": "Bakalari - NR",
  "disabled": false,
  "info": "",
  "env": []
 },
 {
  "id": "ef711a8231882e3f",
  "type": "inject",
  "z": "a5d7b21f983f0d93",
  "name": "",
  "props": [
   {
    "p": "payload"
   },
   {
    "p": "topic",
    "vt": "str"
   }
  ],
  "repeat": "",
  "crontab": "",
  "once": false,
  "onceDelay": 0.1,
  "topic": "",
  "payload": "",
  "payloadType": "date",
  "x": 120,
  "y": 380,
  "wires": [
   [
    "bf013990d71432a5"
   ]
  ]
 },
 {
  "id": "4f0684086d5c7f06",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Login",
  "method": "POST",
  "ret": "obj",
  "paytoqs": "ignore",
  "url": "https://vase-skola.bakalari.cz/api/login",
  "tls": "",
  "persist": false,
  "proxy": "",
  "insecureHTTPParser": false,
  "authType": "",
  "senderr": false,
  "headers": [
   {
    "keyType": "Content-Type",
    "keyValue": "",
    "valueType": "other",
    "valueValue": "application/x-www-form-urlencoded"
   }
  ],
  "x": 430,
  "y": 300,
  "wires": [
   [
    "135a56e57d8b623b"
   ]
  ]
 },
 {
  "id": "fe17db301b5b220f",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Majda",
  "func": "msg['payload'] = \"client_id=ANDR&grant_type=password&username=VAS_LOGIN&password=VASE_HESLO\"\nreturn msg;",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 310,
  "y": 300,
  "wires": [
   [
    "4f0684086d5c7f06"
   ]
  ]
 },
 {
  "id": "135a56e57d8b623b",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Majda",
  "func": "msg.headers = {};\nmsg.headers['Content-Type'] = 'application/x-www-form-urlencoded';\nmsg.headers['Authorization'] = 'Bearer ' + msg.payload.access_token;\nmsg.method = 'GET'\n\nreturn msg;",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 550,
  "y": 300,
  "wires": [
   [
    "96db99ce482ae3f3"
   ]
  ]
 },
 {
  "id": "96db99ce482ae3f3",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Marks",
  "method": "use",
  "ret": "obj",
  "paytoqs": "body",
  "url": "https://vase-skola.bakalari.cz/api/3/marks",
  "tls": "",
  "persist": false,
  "proxy": "",
  "insecureHTTPParser": false,
  "authType": "",
  "senderr": false,
  "headers": [],
  "x": 670,
  "y": 300,
  "wires": [
   [
    "27fd53ed42eacb6a"
   ]
  ]
 },
 {
  "id": "27fd53ed42eacb6a",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Majda",
  "func": "global.set('Barva', \"\");\nmsg.Znamky = msg.payload\nlet cislo = 1\nfor (let index = 0; index < msg.Znamky.Subjects.length; index++) {\n    for (let index1 = 0; index1 < msg.Znamky.Subjects[index].Marks.length; index1++) {\n        if (msg.Znamky.Subjects[index].Marks[index1].IsNew === true){\n//            node.warn(\"TRUE \"+index+\"-\"+index1);\n//            node.warn(\">>>\" + msg.Znamky.Subjects[index].Subject.Abbrev);\n            if (msg['Znamky'].Subjects[index].Marks[index1].MarkText == \"1\"){\n                global.set('Barva', \"<ha-alert alert-type=\\\"success\\\">\")\n                } else if (msg['Znamky'].Subjects[index].Marks[index1].MarkText == \"2\") {\n                    global.set('Barva', \"<ha-alert alert-type='success'>\")\n                    } else if (msg['Znamky'].Subjects[index].Marks[index1].MarkText == \"3\") {\n                        global.set('Barva', \"<ha-alert alert-type=\\\"warning\\\">\")\n                        } else if (msg['Znamky'].Subjects[index].Marks[index1].MarkText == \"4\") {\n                            global.set('Barva', \"<ha-alert alert-type='error'>\")\n                            } else if (msg['Znamky'].Subjects[index].Marks[index1].MarkText == \"5\") {\n                                global.set('Barva', \"<ha-alert alert-type='error'>\")\n                                }\nmsg.payload = global.get('Barva') + msg.Znamky.Subjects[index].Subject.Abbrev + \"- \" + msg.Znamky.Subjects[index].Marks[index1].MarkText + \" [\" + msg.Znamky.Subjects[index].Marks[index1].Weight + \"] (\" + msg.Znamky.Subjects[index].Marks[index1].Caption + \")</ha-alert>\"\nmsg.cislo = cislo\nnode.send(msg);\ncislo++;\n}\n}\n}\n\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 790,
  "y": 300,
  "wires": [
   [
    "4b3f0e3c4ce65968"
   ]
  ]
 },
 {
  "id": "4b3f0e3c4ce65968",
  "type": "switch",
  "z": "a5d7b21f983f0d93",
  "name": "",
  "property": "cislo",
  "propertyType": "msg",
  "rules": [
   {
    "t": "eq",
    "v": "1",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "2",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "3",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "4",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "5",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "6",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "7",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "8",
    "vt": "str"
   },
   {
    "t": "eq",
    "v": "9",
    "vt": "str"
   }
  ],
  "checkall": "true",
  "repair": false,
  "outputs": 9,
  "x": 830,
  "y": 160,
  "wires": [
   [
    "5d552ab53dc49a48"
   ],
   [
    "7eb3af41dacbc8e6"
   ],
   [
    "55965c9a35f1d9ca"
   ],
   [
    "61325b7294f6e30e"
   ],
   [
    "0a75641119dda67e"
   ],
   [
    "5a37a39142df5aea"
   ],
   [
    "d57243f0e51ba438"
   ],
   [
    "d28e6af8709a63b7"
   ],
   [
    "7f51c46adff886d2"
   ]
  ]
 },
 {
  "id": "5d552ab53dc49a48",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 1",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_1"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 100,
  "wires": [
   []
  ]
 },
 {
  "id": "7eb3af41dacbc8e6",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 2",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_2"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 140,
  "wires": [
   []
  ]
 },
 {
  "id": "55965c9a35f1d9ca",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 3",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_3"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 180,
  "wires": [
   []
  ]
 },
 {
  "id": "61325b7294f6e30e",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 4",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_4"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 220,
  "wires": [
   []
  ]
 },
 {
  "id": "0a75641119dda67e",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 5",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_5"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 260,
  "wires": [
   []
  ]
 },
 {
  "id": "5a37a39142df5aea",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 6",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_6"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 300,
  "wires": [
   []
  ]
 },
 {
  "id": "d57243f0e51ba438",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 7",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_7"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 340,
  "wires": [
   []
  ]
 },
 {
  "id": "d28e6af8709a63b7",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 8",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_8"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 380,
  "wires": [
   []
  ]
 },
 {
  "id": "7f51c46adff886d2",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda 9",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_9"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 1020,
  "y": 420,
  "wires": [
   []
  ]
 },
 {
  "id": "bf013990d71432a5",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Majda null",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_text.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_text.majda_1",
   "input_text.majda_2",
   "input_text.majda_3",
   "input_text.majda_4",
   "input_text.majda_5",
   "input_text.majda_6",
   "input_text.majda_7",
   "input_text.majda_8",
   "input_text.majda_9"
  ],
  "labelId": [],
  "data": "{\"value\":\"\"}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_text",
  "service": "set_value",
  "x": 170,
  "y": 300,
  "wires": [
   [
    "fe17db301b5b220f"
   ]
  ]
 },
 {
  "id": "d9a16f91b8c141ff",
  "type": "inject",
  "z": "a5d7b21f983f0d93",
  "name": "Start (ručně nebo plánovač)",
  "props": [
   {
    "p": "payload"
   }
  ],
  "repeat": "1200",
  "crontab": "",
  "once": false,
  "onceDelay": "",
  "topic": "",
  "payload": "",
  "payloadType": "date",
  "x": 200,
  "y": 760,
  "wires": [
   [
    "e2eeab6ae2579bbe"
   ]
  ]
 },
 {
  "id": "4daac2e4f2f66e3a",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Login",
  "method": "use",
  "ret": "obj",
  "paytoqs": "ignore",
  "url": "",
  "x": 530,
  "y": 700,
  "wires": [
   [
    "c9eda8e4cded5b88"
   ]
  ]
 },
 {
  "id": "c9eda8e4cded5b88",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Parse Login",
  "func": "if (!msg.payload || !msg.payload.access_token) {\n    node.error('Login failed', msg);\n    return null;\n}\nmsg.access_token = msg.payload.access_token;\nreturn msg;",
  "outputs": 1,
  "x": 490,
  "y": 760,
  "wires": [
   [
    "0279c58c0a962219",
    "990e7ba23d0af42f",
    "8d8d302e71a04b1c"
   ]
  ]
 },
 {
  "id": "0279c58c0a962219",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Prepare Komens Request",
  "func": "msg.method = \"POST\";\nmsg.url = \"https://vase-skola.bakalari.cz/api/3/komens/messages/received\";\nmsg.headers = {\n    \"Authorization\": \"Bearer \" + msg.access_token,\n    \"Content-Type\": \"application/x-www-form-urlencoded\"\n};\nmsg.payload = {}; // prázdný POST\nreturn msg;\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 770,
  "y": 720,
  "wires": [
   [
    "877f6ccb50511e66"
   ]
  ]
 },
 {
  "id": "877f6ccb50511e66",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Get Komens Messages (raw)",
  "method": "use",
  "ret": "txt",
  "paytoqs": "ignore",
  "url": "",
  "x": 1080,
  "y": 720,
  "wires": [
   [
    "a5d444aeabdab7ee"
   ]
  ]
 },
 {
  "id": "a5d444aeabdab7ee",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Parse Komens Response (safe)",
  "func": "// msg.payload is raw text here, msg.statusCode available\nif (typeof msg.statusCode !== 'undefined' && msg.statusCode !== 200) {\n    node.error('Komens HTTP error: ' + msg.statusCode, msg);\n    node.status({fill:'red',shape:'dot',text:'HTTP ' + msg.statusCode});\n    // keep raw payload for inspection in debug\n    return msg;\n}\nlet raw = (typeof msg.payload === 'string') ? msg.payload : JSON.stringify(msg.payload);\ntry {\n    let data = JSON.parse(raw);\n    let msgs = data.Messages || [];\n    let total = msgs.length;\n    let unread = msgs.filter(m => !m.Read).length;\n    msg.payload = { total: total, unread: unread };\n    node.status({fill:'green',shape:'dot',text:'OK ' + unread});\n    return msg;\n} catch (e) {\n    node.error('JSON parse error: ' + e.message, {raw: raw});\n    node.status({fill:'yellow',shape:'ring',text:'parse error'});\n    return msg;\n}\n",
  "outputs": 1,
  "x": 1390,
  "y": 720,
  "wires": [
   [
    "0ab2765ddd2f927b",
    "c4c98d741d2da789"
   ]
  ]
 },
 {
  "id": "e2eeab6ae2579bbe",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Prepare Login Payload",
  "func": "msg.payload = \"client_id=ANDR&grant_type=password&username=VAS_LOGIN&password=VASE_HESLO\";\nmsg.headers = {\"Content-Type\":\"application/x-www-form-urlencoded\"};\nmsg.method = 'POST';\nmsg.url = 'https://vase-skola.bakalari.cz/api/login';\nreturn msg;",
  "outputs": 1,
  "x": 340,
  "y": 700,
  "wires": [
   [
    "4daac2e4f2f66e3a"
   ]
  ]
 },
 {
  "id": "21b09911dda0e000",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Upozornění Míra telefon",
  "server": "46a53aae.a18f74",
  "version": 7,
  "debugenabled": false,
  "action": "notify.mobile_app_VAS_TELEFON",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [],
  "labelId": [],
  "data": "{\"title\":\"👩‍🎓 Zpráva ze školy\",\"message\":\"📝 Majda - nová zpráva ze školy\",\"data\":{\"color\":\"#FFA500\",\"priority\":\"high\",\"ttl\":0}}",
  "dataType": "json",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "notify",
  "service": "mobile_app_VAS_TELEFON",
  "x": 2350,
  "y": 720,
  "wires": [
   []
  ]
 },
 {
  "id": "4b6fc3192ee846e7",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Upozornění Verča telefon",
  "server": "46a53aae.a18f74",
  "version": 7,
  "debugenabled": false,
  "action": "notify.mobile_app_DRUHY_TELEFON",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [],
  "labelId": [],
  "data": "{\"title\":\"👩‍🎓 Zpráva ze školy\",\"message\":\"📝 Majda - nová zpráva ze školy\",\"data\":{\"color\":\"#FFA500\",\"priority\":\"high\",\"ttl\":0}}",
  "dataType": "json",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "notify",
  "service": "mobile_app_DRUHY_TELEFON",
  "x": 2350,
  "y": 680,
  "wires": [
   []
  ]
 },
 {
  "id": "5dae5832088e6f94",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet nepřečtených zpráv",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_neprectene_zpravy"
  ],
  "labelId": [],
  "data": "{\"value\":payload.unread}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 2380,
  "y": 780,
  "wires": [
   []
  ]
 },
 {
  "id": "0ab2765ddd2f927b",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet všech zpráv",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_celkem_zprav"
  ],
  "labelId": [],
  "data": "{\"value\":payload.total}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 1690,
  "y": 780,
  "wires": [
   []
  ]
 },
 {
  "id": "990e7ba23d0af42f",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Prepare Homeworks Request",
  "func": "msg.method = \"GET\";  // tady GET funguje\nmsg.url = \"https://vase-skola.bakalari.cz/api/3/homeworks/count-actual\";\nmsg.headers = {\n    \"Authorization\": \"Bearer \" + msg.access_token,\n    \"Content-Type\": \"application/x-www-form-urlencoded\"\n};\nreturn msg;\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 790,
  "y": 860,
  "wires": [
   [
    "14716841c3a753ee"
   ]
  ]
 },
 {
  "id": "2a7595b2eb2fa721",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Parse node",
  "func": "try {\n    msg.payload = JSON.parse(msg.payload);\n    return msg;\n} catch(err) {\n    node.error(\"Homeworks HTTP error\", msg);\n    return null;\n}\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 1310,
  "y": 860,
  "wires": [
   [
    "f7fcb22d39f3dfcf"
   ]
  ]
 },
 {
  "id": "14716841c3a753ee",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Get Homework",
  "method": "use",
  "ret": "txt",
  "paytoqs": "ignore",
  "url": "",
  "tls": "",
  "persist": false,
  "proxy": "",
  "insecureHTTPParser": false,
  "authType": "",
  "senderr": false,
  "headers": [],
  "x": 1100,
  "y": 860,
  "wires": [
   [
    "2a7595b2eb2fa721"
   ]
  ]
 },
 {
  "id": "f7fcb22d39f3dfcf",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet nových úkolů",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_nove_ukoly"
  ],
  "labelId": [],
  "data": "{\"value\":payload}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 1700,
  "y": 860,
  "wires": [
   []
  ]
 },
 {
  "id": "ca55e9b487b9e6b2",
  "type": "inject",
  "z": "a5d7b21f983f0d93",
  "name": "",
  "props": [
   {
    "p": "payload"
   },
   {
    "p": "topic",
    "vt": "str"
   }
  ],
  "repeat": "",
  "crontab": "",
  "once": false,
  "onceDelay": 0.1,
  "topic": "",
  "payload": "",
  "payloadType": "date",
  "x": 300,
  "y": 880,
  "wires": [
   [
    "e2eeab6ae2579bbe"
   ]
  ]
 },
 {
  "id": "8d8d302e71a04b1c",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Prepare Nastenka Request",
  "func": "msg.method = \"POST\";  // tady je potřeba POST\nmsg.url = \"https://vase-skola.bakalari.cz/api/3/komens/messages/noticeboard\";\nmsg.headers = {\n    \"Authorization\": \"Bearer \" + msg.access_token,\n    \"Content-Type\": \"application/x-www-form-urlencoded\"\n};\nreturn msg;\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 780,
  "y": 1020,
  "wires": [
   [
    "998e3f5af653d632"
   ]
  ]
 },
 {
  "id": "998e3f5af653d632",
  "type": "http request",
  "z": "a5d7b21f983f0d93",
  "name": "Get Nastenka",
  "method": "use",
  "ret": "txt",
  "paytoqs": "ignore",
  "url": "",
  "tls": "",
  "persist": false,
  "proxy": "",
  "insecureHTTPParser": false,
  "authType": "",
  "senderr": false,
  "headers": [],
  "x": 1100,
  "y": 1020,
  "wires": [
   [
    "f74045c1ad3b78d9"
   ]
  ]
 },
 {
  "id": "f74045c1ad3b78d9",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Parse node",
  "func": "try {\n    msg.payload = JSON.parse(msg.payload);\n    return msg;\n} catch (err) {\n    node.error(\"Noticeboard HTTP error\", msg);\n    return null;\n}\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 1310,
  "y": 1020,
  "wires": [
   [
    "9217a1720ae1d344"
   ]
  ]
 },
 {
  "id": "9217a1720ae1d344",
  "type": "function",
  "z": "a5d7b21f983f0d93",
  "name": "Přečtené / nepřečtené",
  "func": "let msgs = msg.payload.Messages || [];\nlet total = msgs.length;\nlet unread = msgs.filter(m => m.Read === false).length;\n\nmsg.payload = {\n    total: total,\n    unread: unread\n};\nreturn msg;\n",
  "outputs": 1,
  "timeout": "",
  "noerr": 0,
  "initialize": "",
  "finalize": "",
  "libs": [],
  "x": 1400,
  "y": 1080,
  "wires": [
   [
    "8608470f394e6154",
    "04d7a44e4c876c4e"
   ]
  ]
 },
 {
  "id": "8608470f394e6154",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet všech zpráv nástěnka",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_celkem_zprav_nastenka"
  ],
  "labelId": [],
  "data": "{\"value\":payload.total}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 1720,
  "y": 1040,
  "wires": [
   []
  ]
 },
 {
  "id": "04d7a44e4c876c4e",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet nepřečtených zpráv nástěnka",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_neprectene_zpravy_nastenka"
  ],
  "labelId": [],
  "data": "{\"value\":payload.unread}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 1750,
  "y": 1100,
  "wires": [
   []
  ]
 },
 {
  "id": "c4c98d741d2da789",
  "type": "api-current-state",
  "z": "a5d7b21f983f0d93",
  "name": "Nepřečtené zprávy stav",
  "server": "46a53aae.a18f74",
  "version": 3,
  "outputs": 1,
  "halt_if": "",
  "halt_if_type": "str",
  "halt_if_compare": "is",
  "entity_id": "input_number.helper_skola_majda_neprectene_zpravy",
  "state_type": "str",
  "blockInputOverrides": true,
  "outputProperties": [
   {
    "property": "unread",
    "propertyType": "msg",
    "value": "",
    "valueType": "entityState"
   },
   {
    "property": "data",
    "propertyType": "msg",
    "value": "",
    "valueType": "entity"
   }
  ],
  "for": "0",
  "forType": "num",
  "forUnits": "minutes",
  "override_topic": false,
  "state_location": "payload",
  "override_payload": "msg",
  "entity_location": "data",
  "override_data": "msg",
  "x": 1690,
  "y": 720,
  "wires": [
   [
    "455b4a272d9d074a"
   ]
  ]
 },
 {
  "id": "f3c5af274ecc15e4",
  "type": "switch",
  "z": "a5d7b21f983f0d93",
  "name": "Test na nové",
  "property": "payload.unread",
  "propertyType": "msg",
  "rules": [
   {
    "t": "eq",
    "v": "unread",
    "vt": "msg"
   },
   {
    "t": "else"
   }
  ],
  "checkall": "true",
  "repair": false,
  "outputs": 2,
  "x": 2110,
  "y": 720,
  "wires": [
   [],
   [
    "5dae5832088e6f94",
    "21b09911dda0e000",
    "4b6fc3192ee846e7"
   ]
  ]
 },
 {
  "id": "455b4a272d9d074a",
  "type": "switch",
  "z": "a5d7b21f983f0d93",
  "name": "Více než 0?",
  "property": "payload.unread",
  "propertyType": "msg",
  "rules": [
   {
    "t": "eq",
    "v": "0",
    "vt": "num"
   },
   {
    "t": "else"
   }
  ],
  "checkall": "true",
  "repair": false,
  "outputs": 2,
  "x": 1910,
  "y": 720,
  "wires": [
   [
    "0e99d1b407a10bdc"
   ],
   [
    "f3c5af274ecc15e4"
   ]
  ]
 },
 {
  "id": "0e99d1b407a10bdc",
  "type": "api-call-service",
  "z": "a5d7b21f983f0d93",
  "name": "Nastav počet nepřečtených zpráv",
  "server": "6ac5a410.6dcd3c",
  "version": 7,
  "debugenabled": false,
  "action": "input_number.set_value",
  "floorId": [],
  "areaId": [],
  "deviceId": [],
  "entityId": [
   "input_number.helper_skola_majda_neprectene_zpravy"
  ],
  "labelId": [],
  "data": "{\"value\":payload.unread}",
  "dataType": "jsonata",
  "mergeContext": "",
  "mustacheAltTags": false,
  "outputProperties": [],
  "queue": "none",
  "blockInputOverrides": false,
  "domain": "input_number",
  "service": "set_value",
  "x": 2000,
  "y": 600,
  "wires": [
   []
  ]
 }
]