I've been experimenting with detection, and am trying to weed out false negatives and positives. Essentially, I want a message saying a state has changed when it has been different for the past n messages.
Using counters and switches, I've done this:
[
{
"id": "a48fa9.dd5a7058",
"type": "tab",
"label": "Test-flow",
"disabled": false,
"info": ""
},
{
"id": "e255e559.b5b308",
"type": "switch",
"z": "a48fa9.dd5a7058",
"name": "",
"property": "count",
"propertyType": "msg",
"rules": [
{
"t": "gt",
"v": "5",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 790,
"y": 320,
"wires": [
[
"ebba2a29.f9d2a8"
]
]
},
{
"id": "d4daa5e7.259228",
"type": "counter",
"z": "a48fa9.dd5a7058",
"name": "",
"init": "0",
"step": "1",
"lower": "",
"upper": "5",
"mode": "increment",
"outputs": "1",
"x": 660,
"y": 320,
"wires": [
[
"e255e559.b5b308"
]
]
},
{
"id": "3ed91eba.0d9ad2",
"type": "counter",
"z": "a48fa9.dd5a7058",
"name": "",
"init": "0",
"step": "1",
"lower": "",
"upper": "5",
"mode": "increment",
"outputs": "1",
"x": 660,
"y": 240,
"wires": [
[
"7cddf176.694cf"
]
]
},
{
"id": "3e89afb5.27b6b",
"type": "switch",
"z": "a48fa9.dd5a7058",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 450,
"y": 280,
"wires": [
[
"3ed91eba.0d9ad2",
"5e184d7e.582074"
],
[
"d4daa5e7.259228",
"c306f940.066d38"
]
]
},
{
"id": "c306f940.066d38",
"type": "change",
"z": "a48fa9.dd5a7058",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 480,
"y": 340,
"wires": [
[
"3ed91eba.0d9ad2"
]
]
},
{
"id": "5e184d7e.582074",
"type": "change",
"z": "a48fa9.dd5a7058",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 480,
"y": 220,
"wires": [
[
"d4daa5e7.259228"
]
]
},
{
"id": "7cddf176.694cf",
"type": "switch",
"z": "a48fa9.dd5a7058",
"name": "",
"property": "count",
"propertyType": "msg",
"rules": [
{
"t": "gte",
"v": "5",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 790,
"y": 240,
"wires": [
[
"ebba2a29.f9d2a8"
]
]
},
{
"id": "468821a5.6febc",
"type": "inject",
"z": "a48fa9.dd5a7058",
"name": "",
"topic": "",
"payload": "false",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 290,
"y": 300,
"wires": [
[
"3e89afb5.27b6b"
]
]
},
{
"id": "ebba2a29.f9d2a8",
"type": "debug",
"z": "a48fa9.dd5a7058",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 990,
"y": 280,
"wires": []
},
{
"id": "91c8db87.d30ca8",
"type": "inject",
"z": "a48fa9.dd5a7058",
"name": "",
"topic": "",
"payload": "true",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 290,
"y": 260,
"wires": [
[
"3e89afb5.27b6b"
]
]
}
]
I'm still a bit new to Node Red, and I think I'm missing something very simple.