hhpack 发表于 2023-11-6 13:56:52

初识noed-red遇到个小问题大家帮忙看下,谢谢!

我有一个环境是这样的,我怎样在执行长按后把后面跟着的一次短按过滤掉呢,不然我每次开灯它自动执行一次调节灯光,路过的大神请指教,感谢!

hhpack 发表于 2023-11-6 17:25:29

顶上去,大家帮忙看看

demacia 发表于 2023-11-6 18:07:33

提供个我的类似场景的思路:
长按事件-> 触发设置(流程)变量 (a=true)-> 2s后设置变量(a=false)
短按事件->判断(a=false)->触发事件

hhpack 发表于 2023-11-7 12:40:37

demacia 发表于 2023-11-6 18:07
提供个我的类似场景的思路:
长按事件-> 触发设置(流程)变量 (a=true)-> 2s后设置变量(a=false)
短按 ...

您好,您能把您的配置导出一份给我吗

demacia 发表于 2023-11-7 14:15:28

hhpack 发表于 2023-11-7 12:40
您好,您能把您的配置导出一份给我吗

[
    {
      "id": "f6f2187d.f17ca8",
      "type": "tab",
      "label": "Flow 1",
      "disabled": false,
      "info": ""
    },
    {
      "id": "3cc11d24.ff01a2",
      "type": "comment",
      "z": "f6f2187d.f17ca8",
      "name": "WARNING: please check you have started this container with a volume that is mounted to /data\\n otherwise any flow changes are lost when you redeploy or upgrade the container\\n (e.g. upgrade to a more recent node-red docker image).\\nIf you are using named volumes you can ignore this warning.\\n Double click or see info side panel to learn how to start Node-RED in Docker to save your work",
      "info": "\nTo start docker with a bind mount volume (-v option), for example:\n\n```\ndocker run -it -p 1880:1880 -v /home/user/node_red_data:/data --name mynodered nodered/node-red\n```\n\nwhere `/home/user/node_red_data` is a directory on your host machine where you want to store your flows.\n\nIf you do not do this then you can experiment and redploy flows, but if you restart or upgrade the container the flows will be disconnected and lost. \n\nThey will still exist in a hidden data volume, which can be recovered using standard docker techniques, but that is much more complex than just starting with a named volume as described above.",
      "x": 350,
      "y": 80,
      "wires": []
    },
    {
      "id": "b8226fa74b51b805",
      "type": "inject",
      "z": "f6f2187d.f17ca8",
      "name": "长按事件",
      "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
      ],
      "repeat": "",
      "crontab": "",
      "once": false,
      "onceDelay": 0.1,
      "topic": "",
      "payload": "{\"action\":\"长按\"}",
      "payloadType": "json",
      "x": 160,
      "y": 260,
      "wires": [
            [
                "4625ef356421614f"
            ]
      ]
    },
    {
      "id": "5860f1f8a03068da",
      "type": "inject",
      "z": "f6f2187d.f17ca8",
      "name": "短按事件",
      "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
      ],
      "repeat": "",
      "crontab": "",
      "once": false,
      "onceDelay": 0.1,
      "topic": "",
      "payload": "{\"action\":\"短按\"}",
      "payloadType": "json",
      "x": 160,
      "y": 360,
      "wires": [
            [
                "4625ef356421614f"
            ]
      ]
    },
    {
      "id": "4625ef356421614f",
      "type": "switch",
      "z": "f6f2187d.f17ca8",
      "name": "",
      "property": "payload.action",
      "propertyType": "msg",
      "rules": [
            {
                "t": "eq",
                "v": "长按",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "短按",
                "vt": "str"
            }
      ],
      "checkall": "true",
      "repair": false,
      "outputs": 2,
      "x": 350,
      "y": 300,
      "wires": [
            [
                "bf5e1173c9daae01",
                "cadf44ac989d0d62"
            ],
            [
                "b7b3cb2b3e2c3ab6"
            ]
      ]
    },
    {
      "id": "bf5e1173c9daae01",
      "type": "function",
      "z": "f6f2187d.f17ca8",
      "name": "设置阀",
      "func": "flow.set(\"a\", true)\nreturn msg;",
      "outputs": 1,
      "timeout": 0,
      "noerr": 0,
      "initialize": "",
      "finalize": "",
      "libs": [],
      "x": 490,
      "y": 240,
      "wires": [
            [
                "b0f3dd1585350d2f"
            ]
      ]
    },
    {
      "id": "b0f3dd1585350d2f",
      "type": "delay",
      "z": "f6f2187d.f17ca8",
      "name": "",
      "pauseType": "delay",
      "timeout": "2",
      "timeoutUnits": "seconds",
      "rate": "1",
      "nbRateUnits": "1",
      "rateUnits": "second",
      "randomFirst": "1",
      "randomLast": "5",
      "randomUnits": "seconds",
      "drop": false,
      "allowrate": false,
      "outputs": 1,
      "x": 640,
      "y": 240,
      "wires": [
            [
                "5d291038e05825c5"
            ]
      ]
    },
    {
      "id": "5d291038e05825c5",
      "type": "function",
      "z": "f6f2187d.f17ca8",
      "name": "设置阀",
      "func": "\nflow.set(\"a\", false)\nreturn msg;",
      "outputs": 1,
      "timeout": 0,
      "noerr": 0,
      "initialize": "",
      "finalize": "",
      "libs": [],
      "x": 770,
      "y": 240,
      "wires": [
            []
      ]
    },
    {
      "id": "cadf44ac989d0d62",
      "type": "debug",
      "z": "f6f2187d.f17ca8",
      "name": "开灯",
      "active": true,
      "tosidebar": true,
      "console": false,
      "tostatus": false,
      "complete": "payload",
      "targetType": "msg",
      "statusVal": "",
      "statusType": "auto",
      "x": 610,
      "y": 280,
      "wires": []
    },
    {
      "id": "f89df6f5f5b112c5",
      "type": "debug",
      "z": "f6f2187d.f17ca8",
      "name": "调节亮度",
      "active": true,
      "tosidebar": true,
      "console": false,
      "tostatus": false,
      "complete": "payload",
      "targetType": "msg",
      "statusVal": "",
      "statusType": "auto",
      "x": 620,
      "y": 360,
      "wires": []
    },
    {
      "id": "b7b3cb2b3e2c3ab6",
      "type": "switch",
      "z": "f6f2187d.f17ca8",
      "name": "",
      "property": "a",
      "propertyType": "flow",
      "rules": [
            {
                "t": "eq",
                "v": "false",
                "vt": "jsonata"
            }
      ],
      "checkall": "true",
      "repair": false,
      "outputs": 1,
      "x": 490,
      "y": 360,
      "wires": [
            [
                "f89df6f5f5b112c5"
            ]
      ]
    }
]

demacia 发表于 2023-11-7 14:21:45

demacia 发表于 2023-11-7 14:15


这个有个问题就是连续长按后面的长按事件会被前面的覆盖掉。

要是严格要求可以长按后记录长按的时间点。然后短按事件是switch在判断上一次长按时间和当前做比较来决策。

hhpack 发表于 2023-11-7 17:17:30

demacia 发表于 2023-11-7 14:15


非常感谢!

hhpack 发表于 2023-11-8 02:14:11

已完美解决,上图给同样需要的朋友
页: [1]
查看完整版本: 初识noed-red遇到个小问题大家帮忙看下,谢谢!