『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1322|回复: 7

[流程系列] 初识noed-red遇到个小问题大家帮忙看下,谢谢!

[复制链接]

30

主题

180

帖子

742

积分

高级会员

Rank: 4

积分
742
金钱
562
HASS币
0
发表于 2023-11-6 13:56:52 | 显示全部楼层 |阅读模式
我有一个环境是这样的,我怎样在执行长按后把后面跟着的一次短按过滤掉呢,不然我每次开灯它自动执行一次调节灯光,路过的大神请指教,感谢!
1.jpg
回复

使用道具 举报

30

主题

180

帖子

742

积分

高级会员

Rank: 4

积分
742
金钱
562
HASS币
0
 楼主| 发表于 2023-11-6 17:25:29 | 显示全部楼层
顶上去,大家帮忙看看
回复

使用道具 举报

25

主题

224

帖子

1032

积分

金牌会员

007潜水了

Rank: 6Rank: 6

积分
1032
金钱
808
HASS币
0
发表于 2023-11-6 18:07:33 | 显示全部楼层
提供个我的类似场景的思路:
长按事件-> 触发设置(流程)变量 (a=true)-> 2s后设置变量(a=false)
短按事件->判断(a=false)->触发事件
回复

使用道具 举报

30

主题

180

帖子

742

积分

高级会员

Rank: 4

积分
742
金钱
562
HASS币
0
 楼主| 发表于 2023-11-7 12:40:37 | 显示全部楼层
demacia 发表于 2023-11-6 18:07
提供个我的类似场景的思路:
长按事件-> 触发设置(流程)变量 (a=true)-> 2s后设置变量(a=false)
短按 ...

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

使用道具 举报

25

主题

224

帖子

1032

积分

金牌会员

007潜水了

Rank: 6Rank: 6

积分
1032
金钱
808
HASS币
0
发表于 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).\\n  If 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"
            ]
        ]
    }
]
回复

使用道具 举报

25

主题

224

帖子

1032

积分

金牌会员

007潜水了

Rank: 6Rank: 6

积分
1032
金钱
808
HASS币
0
发表于 2023-11-7 14:21:45 | 显示全部楼层

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

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

使用道具 举报

30

主题

180

帖子

742

积分

高级会员

Rank: 4

积分
742
金钱
562
HASS币
0
 楼主| 发表于 2023-11-7 17:17:30 | 显示全部楼层
回复

使用道具 举报

30

主题

180

帖子

742

积分

高级会员

Rank: 4

积分
742
金钱
562
HASS币
0
 楼主| 发表于 2023-11-8 02:14:11 | 显示全部楼层
已完美解决,上图给同样需要的朋友
QQ截图20231108021305.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 11:17 , Processed in 0.147662 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表