Pass msg only if another arrive

Hi there, I'm having trouble to put my flow to work.
I have two messages coming from different sensors. Sometimes, sensor 1 gives a false alarm (can't fix it using hardware). So I decided to only pass the message to the user (in this case its me) if another sensor trigger too.

First message (msg.payload) --->Pass first message if second arrive (msg.payload) ---> msg.payload
Second message (whatever) -----^

If I understand correctly try a batch node with a trigger node

[{"id":"3e89f279.e1b5fe","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"str","x":90,"y":4380,"wires":[["f1fd6501.ca314"]]},{"id":"f1fd6501.ca314","type":"batch","z":"c74669a0.6a34f8","name":"","mode":"count","count":"2","overlap":"1","interval":10,"allowEmptySequence":true,"topics":[],"x":260,"y":4400,"wires":[["eb130ab.9cce6f8"]]},{"id":"a8b836c2.280f78","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"str","x":90,"y":4420,"wires":[["f1fd6501.ca314"]]},{"id":"eb130ab.9cce6f8","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"250","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":4400,"wires":[["c57b5533.ce2c2"]]},{"id":"c57b5533.ce2c2","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":4400,"wires":[]}]

Thanks @E1cid, but not exactly.

The way it is, It lets the message pass even if 20 doesn't arrive.

The way I need, It must only allow 10 to pass if 20 arrive as well. Otherwise it must stop the flow.

If you send 10 nothing is passed.
If you then send 20, 10 is passed.
If you then send 30 (or any value) 20 is passed.

If that's not what you want, please explain more clearly.

Hi @E1cid, my problem is only with sensor 1 as I stated. I wanna handle only that specific message.

I'm sorry my flow is not clear enough. Notice that I only wanna handle "Pass first message".
Let me clarify:

Sensor 1 (msg.payload) ---> if (sensor 2 != null) {msg = Sensor 1;} else {msg = null;}
Sensor 2 (whatever) -----^

You never mentioned sensor 2, you did say payloads.

How is sensor 1 distinguished from sensor 2.

More info is required, i.e an example of the incoming messages.

[edit
Try some thing like this you will need to give your sensors a topic or use a message property to distinguish

[{"id":"3e89f279.e1b5fe","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor1","payload":"10","payloadType":"str","x":110,"y":4380,"wires":[["a3d6b52b.7a83e8"]]},{"id":"a3d6b52b.7a83e8","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":250,"y":4400,"wires":[["48476a0e.c3b83c"]]},{"id":"a8b836c2.280f78","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor2","payload":"20","payloadType":"str","x":110,"y":4440,"wires":[["a3d6b52b.7a83e8","c57b5533.ce2c2"]]},{"id":"48476a0e.c3b83c","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.sensor1","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"sensor1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":4380,"wires":[["c57b5533.ce2c2"]]},{"id":"c57b5533.ce2c2","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":4380,"wires":[]}]

And this one will make sure sensor 1 arrives before sensor 2

[{"id":"3e89f279.e1b5fe","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor1","payload":"10","payloadType":"str","x":110,"y":4380,"wires":[["a3d6b52b.7a83e8"]]},{"id":"a3d6b52b.7a83e8","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":250,"y":4400,"wires":[["6df8c23e.1673fc"]]},{"id":"a8b836c2.280f78","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor2","payload":"20","payloadType":"str","x":110,"y":4440,"wires":[["c57b5533.ce2c2","a3d6b52b.7a83e8"]]},{"id":"6df8c23e.1673fc","type":"switch","z":"c74669a0.6a34f8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"sensor2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":4400,"wires":[["48476a0e.c3b83c"]]},{"id":"c57b5533.ce2c2","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":4480,"wires":[]},{"id":"48476a0e.c3b83c","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.sensor1","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"sensor1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":4400,"wires":[["c57b5533.ce2c2"]]}]

]

1 Like

Again, I'm sorry if I did not make myself clear.

Answering your question, here is an example:

image

I have a door that can be opened from 2 RFID readers. First node (portao/social/rfid) receive the location of the reader and second node (portao/social/id) receive the tag code.

Sometimes, people that are not allowed try to open the door. It reads the tag but blocks the message flow. However, first node pass since it only indicate the place someone is trying to access.

I'm receiving alerts that rfid tag has been activated. Since I know who is doing, just wanna disable those messages. Thus, I only wanna let (portao/social/rfid) pass if there is a valid (portao/social/id) passing.

I know it is a bit confusing. I've been trying to do that, but all my attempts failed.

[EDIT] I tried your new suggested flow, it almost worked.

The closest node that can help me is https://flows.nodered.org/node/node-red-contrib-join-wait. However, it unite messages, just wanna let message from (portao/social/rfid) pass. Since I'm learning, I just thought that maybe I'm doing something wrong and the solution is simpler than I thought.

That is an image not an example, please supply a working example with inject nodes to simulate incoming data, I can not help from images and no example of the data.

Hi @E1cid , I really appreciate your help. I figure it out with your help. Thanks.

[{"id":"65639c4d.501ec4","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"c03b2fd.15f705","type":"trigger","z":"65639c4d.501ec4","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"6","extend":false,"overrideDelay":false,"units":"s","reset":"not ok","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":340,"wires":[["4e26251a.790264"]]},{"id":"420e6123.df6d7","type":"delay","z":"65639c4d.501ec4","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":680,"y":380,"wires":[["c03b2fd.15f705"]]},{"id":"3e2b7ece.5aebe2","type":"change","z":"65639c4d.501ec4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"message that I wanna pass","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":340,"wires":[["c03b2fd.15f705"]]},{"id":"1874d4ca.6194c3","type":"inject","z":"65639c4d.501ec4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":270,"y":340,"wires":[["3e2b7ece.5aebe2","e8949247.bc7b28"]]},{"id":"e8949247.bc7b28","type":"change","z":"65639c4d.501ec4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":380,"wires":[["420e6123.df6d7"]]},{"id":"97208f3e.3d6078","type":"inject","z":"65639c4d.501ec4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":270,"y":460,"wires":[["3e2b7ece.5aebe2","9d2e056b.3da4a"]]},{"id":"9d2e056b.3da4a","type":"change","z":"65639c4d.501ec4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"not ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":460,"wires":[["420e6123.df6d7"]]},{"id":"4e26251a.790264","type":"debug","z":"65639c4d.501ec4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":340,"wires":[]}]

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