Node That only sends when 3 Payloads come in the right Order

Hi guys iam Trying to make somethig that when i send 3 Different Payloads in a Node it should send something.

For Example first Payload : "up" second Payload: "down" third Payload: "left"

So and only when these 3 Payloads Match in that Order it should send something. When they dont Match it should Resett after 3 Seconds

I wanne make something like a Code for Different Light Scenes and i got an Gesture Sensor.

So for Example up down left should be Scene 1 ; left rigt down Scene 2

Thx for your Help in Advance

Nice use case. As usual there are many ways to achieve your goal. My approach would be to concatenate the payloads in groups of three. A switch node at the end of the flow would allow only the matched string to pass.

Something like this:

The rule in the swtich node is set to "upupdown", so only this sequence would be a match.

Testing flow:

[{"id":"a3b92cc4.e3cb","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"fe98a93d.9ad0f8","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"up","payloadType":"str","x":170,"y":160,"wires":[["fb39f8f9.173538"]]},{"id":"ce95dd27.9a57","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"down","payloadType":"str","x":170,"y":220,"wires":[["fb39f8f9.173538"]]},{"id":"59491ed3.2f9cd","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"left","payloadType":"str","x":170,"y":280,"wires":[["fb39f8f9.173538"]]},{"id":"84f1ec26.d5d66","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"right","payloadType":"str","x":170,"y":340,"wires":[["fb39f8f9.173538"]]},{"id":"fb39f8f9.173538","type":"batch","z":"a3b92cc4.e3cb","name":"","mode":"count","count":"3","overlap":"2","interval":10,"allowEmptySequence":false,"topics":[],"x":370,"y":260,"wires":[["438f7b96.777dc4"]]},{"id":"8028bfa1.dc15c","type":"debug","z":"a3b92cc4.e3cb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":260,"wires":[]},{"id":"1c72b271.79fe0e","type":"switch","z":"a3b92cc4.e3cb","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"upupdown","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":260,"wires":[["8028bfa1.dc15c"]]},{"id":"438f7b96.777dc4","type":"join","z":"a3b92cc4.e3cb","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":260,"wires":[["1c72b271.79fe0e","87e02340.b97f7"]]},{"id":"87e02340.b97f7","type":"debug","z":"a3b92cc4.e3cb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":340,"wires":[]}]
1 Like

If the first three don't match anything are those three to be discarded, or should the second, third, fourth be tested?

This is exactly what i was looking for, i only would like to reset it , for example an delay node that deletes all input that comes and when there wasnt a new input it should send one message after 3 seconds.

Just add a 3 second time out in the join node.

1 Like

I overlooked that timing requirement. It could be lime @E1cid suggested, just setup the 3 seconds delay in the configuration of the join node, in which case it will count the delay from the first message. The batch node could be dismissed.

[{"id":"a3b92cc4.e3cb","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"fe98a93d.9ad0f8","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"up","payloadType":"str","x":270,"y":160,"wires":[["438f7b96.777dc4"]]},{"id":"ce95dd27.9a57","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"down","payloadType":"str","x":270,"y":220,"wires":[["438f7b96.777dc4"]]},{"id":"59491ed3.2f9cd","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"left","payloadType":"str","x":270,"y":280,"wires":[["438f7b96.777dc4"]]},{"id":"84f1ec26.d5d66","type":"inject","z":"a3b92cc4.e3cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"right","payloadType":"str","x":270,"y":340,"wires":[["438f7b96.777dc4"]]},{"id":"8028bfa1.dc15c","type":"debug","z":"a3b92cc4.e3cb","name":"Scene 1 = updownleft","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":760,"y":220,"wires":[]},{"id":"1c72b271.79fe0e","type":"switch","z":"a3b92cc4.e3cb","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"updownleft","vt":"str"},{"t":"eq","v":"leftrightdown","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":550,"y":280,"wires":[["8028bfa1.dc15c"],["ae3a89bc.cdb818"],["df6f89cd.0060f8"]]},{"id":"438f7b96.777dc4","type":"join","z":"a3b92cc4.e3cb","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":280,"wires":[["1c72b271.79fe0e"]]},{"id":"ae3a89bc.cdb818","type":"debug","z":"a3b92cc4.e3cb","name":"Scene 2 = leftrightdown","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":260,"wires":[]},{"id":"df6f89cd.0060f8","type":"change","z":"a3b92cc4.e3cb","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"no match after 3 seconds","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":300,"wires":[["f5e2dbbf.6a53b8"]]},{"id":"f5e2dbbf.6a53b8","type":"debug","z":"a3b92cc4.e3cb","name":"no match after 3 seconds","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":300,"wires":[]}]
1 Like

Thx a lot guys for the Help it works Great like that .

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.