我目前在events和geofence节点之间,插入了一个function和switch节点,通过时间戳判断来过滤高频的msg,效果比之前重启NR的方法要好
[
{
"id": "cc92412db43fd15d",
"type": "function",
"z": "1627a6b11e62863b",
"name": "触发过滤器",
"func": "/*离家状态下,HA地理围栏和NR有冲突,为防止高频触发,设置该过滤器*/\n\n//初始化last_time\nglobal.set("last_time", global.get("last_time")||msg.payload.time_fired);\n//last_time读入变量\nvar last_time = (new Date(global.get("last_time"))).getTime();\nvar now_time = Date.now();\n\n//15秒放行一次\nif (now_time - last_time >= 15*1000){\n global.set("last_time", msg.payload.time_fired);\n msg.info_pass = true;\n}else{\n msg.info_pass = false;\n}\n\n//msg.last_time = last_time;\n//msg.now_time = now_time;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 290,
"y": 100,
"wires": [
[
"680ebc930df0f8ec",
"64b8dc682ee3ae20"
]
]
},
{
"id": "680ebc930df0f8ec",
"type": "switch",
"z": "1627a6b11e62863b",
"name": "",
"property": "info_pass",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 290,
"y": 180,
"wires": [
[
"72439c6676e0d140",
"3373e674564f8986"
],
[]
]
}
]
|