Advertisement
csongorvarga

Input counter

Nov 23rd, 2023 (edited)
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.79 KB | None | 0 0
  1. [
  2.     {
  3.         "id": "521c610a20a966a4",
  4.         "type": "function",
  5.         "z": "f6b1667f7ee0d1b0",
  6.         "name": "Gombnyomást számol",
  7.         "func": "var buttonPressCount = flow.get(\"buttonPressCount\") || 0;\nvar lastPressTime = context.get(\"lastPressTime\") || 0;\nvar threshold = 1500;\nvar currentTime = new Date().getTime();\n\n\nvar elapsedTime = currentTime - lastPressTime;\n\n// Ellenőrzi a gomb állapotát és számolja a lenyomásokat\nif (msg.payload.buttonevent === 4002) {\n    buttonPressCount++;\n    // Frissíti a flow változót az utolsó gombnyomás időpontjával\n    context.set(\"lastPressTime\", currentTime);\n    flow.set(\"buttonPressCount\", buttonPressCount);\n    node.status({ fill: \"grey\", shape: \"ring\", text: buttonPressCount });\n    return;\n} else {\n    // Ellenőrzi, hogy az eltelt idő kevesebb-e, mint a küszöbérték\n    if (lastPressTime === 0) {\n        return;\n    }\n    if (elapsedTime > threshold) {\n        msg.payload = buttonPressCount;\n        msg.press = \"press\";\n        buttonPressCount = 0;\n        context.set(\"lastPressTime\",0);\n        flow.set(\"buttonPressCount\", buttonPressCount);\n        node.status({ fill: \"grey\", shape: \"ring\", text: buttonPressCount });\n        return msg;\n    } \n}\n\n",
  8.         "outputs": 1,
  9.         "noerr": 0,
  10.         "initialize": "",
  11.         "finalize": "",
  12.         "libs": [],
  13.         "x": 540,
  14.         "y": 4560,
  15.         "wires": [
  16.             [
  17.                 "fcf604040abf79f3"
  18.             ]
  19.         ]
  20.     },
  21.     {
  22.         "id": "fcf604040abf79f3",
  23.         "type": "debug",
  24.         "z": "f6b1667f7ee0d1b0",
  25.         "name": "debug 67",
  26.         "active": true,
  27.         "tosidebar": true,
  28.         "console": false,
  29.         "tostatus": false,
  30.         "complete": "false",
  31.         "statusVal": "",
  32.         "statusType": "auto",
  33.         "x": 760,
  34.         "y": 4560,
  35.         "wires": []
  36.     },
  37.     {
  38.         "id": "fe8c05c93a1a7f43",
  39.         "type": "inject",
  40.         "z": "f6b1667f7ee0d1b0",
  41.         "name": "",
  42.         "props": [
  43.             {
  44.                 "p": "payload"
  45.             },
  46.             {
  47.                 "p": "topic",
  48.                 "vt": "str"
  49.             }
  50.         ],
  51.         "repeat": "",
  52.         "crontab": "",
  53.         "once": false,
  54.         "onceDelay": 0.1,
  55.         "topic": "",
  56.         "payload": "{\"buttonevent\" : 4002}",
  57.         "payloadType": "json",
  58.         "x": 240,
  59.         "y": 4560,
  60.         "wires": [
  61.             [
  62.                 "521c610a20a966a4",
  63.                 "3e9a208e53950bcb"
  64.             ]
  65.         ]
  66.     },
  67.     {
  68.         "id": "09654d19da0190da",
  69.         "type": "change",
  70.         "z": "f6b1667f7ee0d1b0",
  71.         "name": "",
  72.         "rules": [
  73.             {
  74.                 "t": "set",
  75.                 "p": "payload",
  76.                 "pt": "msg",
  77.                 "to": "{\"buttonevent\" : 0}",
  78.                 "tot": "json"
  79.             }
  80.         ],
  81.         "action": "",
  82.         "property": "",
  83.         "from": "",
  84.         "to": "",
  85.         "reg": false,
  86.         "x": 520,
  87.         "y": 4660,
  88.         "wires": [
  89.             [
  90.                 "521c610a20a966a4"
  91.             ]
  92.         ]
  93.     },
  94.     {
  95.         "id": "3e9a208e53950bcb",
  96.         "type": "delay",
  97.         "z": "f6b1667f7ee0d1b0",
  98.         "name": "",
  99.         "pauseType": "delay",
  100.         "timeout": "1600",
  101.         "timeoutUnits": "milliseconds",
  102.         "rate": "1",
  103.         "nbRateUnits": "1",
  104.         "rateUnits": "second",
  105.         "randomFirst": "1",
  106.         "randomLast": "5",
  107.         "randomUnits": "seconds",
  108.         "drop": false,
  109.         "allowrate": false,
  110.         "outputs": 1,
  111.         "x": 320,
  112.         "y": 4660,
  113.         "wires": [
  114.             [
  115.                 "09654d19da0190da"
  116.             ]
  117.         ]
  118.     }
  119. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement