# Pass msg only if another arrive

**URL:** <https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402>\
**Category:** General\
**Created:** [28 May 2021 13:03 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402 "2021-05-28T13:03:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [28 May 2021 13:03 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/1 "2021-05-28T13:03:42Z")

</div>

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) -----^

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 May 2021 14:06 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/2 "2021-05-28T14:06:06Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [28 May 2021 14:12 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/3 "2021-05-28T14:12:26Z")

</div>

> [@E1cid](#):
>
> `[{"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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cfd84c045a593d037241f8d3ef181ed424b0cd19.png)

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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 May 2021 14:20 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/4 "2021-05-28T14:20:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [28 May 2021 14:26 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/5 "2021-05-28T14:26:01Z")

</div>

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

> [@thalesmaoa](#):
>
> First message (msg.payload) ---\>Pass first message if second arrive (msg.payload) ---\> msg.payload  
> Second message (whatever) -----^

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) -----^

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 May 2021 14:29 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/6 "2021-05-28T14:29:10Z")

</div>

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

```auto
[{"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

```auto
[{"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"]]}]

```

]

---

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [28 May 2021 14:51 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/7 "2021-05-28T14:51:19Z")

</div>

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

Answering your question, here is an example:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f2c7849bf0f509cfdae7e98a09c39dc801bae04.png)

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](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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [28 May 2021 14:53 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/8 "2021-05-28T14:53:49Z")

</div>

> [@thalesmaoa](#):
>
> Answering your question, here is an example:
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f2c7849bf0f509cfdae7e98a09c39dc801bae04.png)

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.

---

<div class="post-metadata">

**Author:** ![thalesmaoa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thalesmaoa/32/17067_2.png) [@thalesmaoa](https://discourse.nodered.org/u/thalesmaoa)\
**Post date:** [28 May 2021 15:07 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/9 "2021-05-28T15:07:10Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/9686da69938479f34cfd5fb95b839e5ddb96e2b2.png)

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 June 2021 15:08 UTC](https://discourse.nodered.org/t/pass-msg-only-if-another-arrive/46402/10 "2021-06-11T15:08:11Z")

</div>

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