# Block first message

**URL:** <https://discourse.nodered.org/t/block-first-message/17144>\
**Category:** General\
**Created:** [25 October 2019 14:01 UTC](https://discourse.nodered.org/t/block-first-message/17144 "2019-10-25T14:01:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [25 October 2019 14:01 UTC](https://discourse.nodered.org/t/block-first-message/17144/1 "2019-10-25T14:01:58Z")

</div>

Hello Community,

Two quick questions:

1. Is there any ways to block the first message coming to the flow, and then let the following to pass ?

2. any chance to reset the RBE function after 1h or 2h after the first message has been blocked ?

Thank you very much for your preciouse help.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 October 2019 15:53 UTC](https://discourse.nodered.org/t/block-first-message/17144/2 "2019-10-25T15:53:52Z")

</div>

Hi  
yes - the info panel on the right for the RBE node tells you about msg.reset.  
And the node options include - ignore initial value. (ie block it)

---

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [26 October 2019 11:26 UTC](https://discourse.nodered.org/t/block-first-message/17144/3 "2019-10-26T11:26:18Z")

</div>

Hi dceejay,

I have tried the RBE - Ignore initial value, but I cannot find a good result using it. According to my flow, each time two buy messages are coming, the RBE blocks both. As soon as a sell message comes, it passes.

What I would expect here is the RBE - ignore initial value to block the first "buy message", then let the second buy to pass. As soon as it turns to "sell" message, block the 1st sell one, then let the second to pass.

```auto
[{"id":"685360b7.22a1b","type":"link out","z":"bf3bef9a.b6faf","name":"","links":["2333c760.a5a568","6d254b4d.d156c4","67619b0a.8245b4","96ebcc.5b423438","186344db.624dfb","a6eb259c.a7a368","c4d89bb5.4156b8","176593ca.87d22c","443f31a1.9058","5713ac11.01d544","5846ab79.5ee1b4","a3e69091.80c","5fd911df.05f63","9c7cd9cb.b8fe58"],"x":1535,"y":400,"wires":[]},{"id":"b96a4b3.e677db8","type":"function","z":"bf3bef9a.b6faf","name":"Set to Buy","func":"if (flow.get(\"Direction\") != \"Buy\")\n{\n flow.set(\"Direction\",\"Buy\"); \n}\n// else\n// {\n// // Stop flow\n// return null;\n// }\nreturn msg;\n","outputs":1,"noerr":0,"x":1390,"y":380,"wires":[["685360b7.22a1b"]]},{"id":"84c7325f.6e1fd","type":"inject","z":"bf3bef9a.b6faf","name":"Sell","topic":"","payload":"Sell","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":420,"wires":[["cc11d921.7096f8"]]},{"id":"c3265a99.2bf198","type":"function","z":"bf3bef9a.b6faf","name":"Set to Sell","func":"if (flow.get(\"Direction\") != \"Sell\")\n{\n flow.set(\"Direction\",\"Sell\"); \n}\n// else\n// {\n// // Stop flow\n// return null;\n// }\nreturn msg;\n","outputs":1,"noerr":0,"x":1390,"y":440,"wires":[["685360b7.22a1b"]]},{"id":"9fa9f9b0.f1bb68","type":"inject","z":"bf3bef9a.b6faf","name":"Buy","topic":"","payload":"Buy","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":770,"y":380,"wires":[["cc11d921.7096f8"]]},{"id":"cc11d921.7096f8","type":"rbe","z":"bf3bef9a.b6faf","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":1010,"y":400,"wires":[["c49a8b2e.806a18"]]},{"id":"c49a8b2e.806a18","type":"switch","z":"bf3bef9a.b6faf","name":"Buy/Sell","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Buy","vt":"str"},{"t":"eq","v":"Sell","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":1160,"y":400,"wires":[["b96a4b3.e677db8"],["c3265a99.2bf198"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/12053673cef485dbf32a9127bdab933433ec18ff.png)

Regarding the reset of the RBE, I couldn't find a way to incorporate it on my flow. I have checked it out on the internet and I have find this, but unfortunately it doesn't work properly:

```auto
[{"id":"685360b7.22a1b","type":"link out","z":"bf3bef9a.b6faf","name":"","links":["2333c760.a5a568","6d254b4d.d156c4","67619b0a.8245b4","96ebcc.5b423438","186344db.624dfb","a6eb259c.a7a368","c4d89bb5.4156b8","176593ca.87d22c","443f31a1.9058","5713ac11.01d544","5846ab79.5ee1b4","a3e69091.80c","5fd911df.05f63","9c7cd9cb.b8fe58"],"x":1535,"y":400,"wires":[]},{"id":"b96a4b3.e677db8","type":"function","z":"bf3bef9a.b6faf","name":"Set to Buy","func":"if (flow.get(\"Direction\") != \"Buy\")\n{\n flow.set(\"Direction\",\"Buy\"); \n}\n// else\n// {\n// // Stop flow\n// return null;\n// }\nreturn msg;\n","outputs":1,"noerr":0,"x":1390,"y":380,"wires":[["685360b7.22a1b"]]},{"id":"84c7325f.6e1fd","type":"inject","z":"bf3bef9a.b6faf","name":"Sell","topic":"","payload":"Sell","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":420,"wires":[["cc11d921.7096f8"]]},{"id":"c3265a99.2bf198","type":"function","z":"bf3bef9a.b6faf","name":"Set to Sell","func":"if (flow.get(\"Direction\") != \"Sell\")\n{\n flow.set(\"Direction\",\"Sell\"); \n}\n// else\n// {\n// // Stop flow\n// return null;\n// }\nreturn msg;\n","outputs":1,"noerr":0,"x":1390,"y":440,"wires":[["685360b7.22a1b"]]},{"id":"9fa9f9b0.f1bb68","type":"inject","z":"bf3bef9a.b6faf","name":"Buy","topic":"","payload":"Buy","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":770,"y":380,"wires":[["cc11d921.7096f8"]]},{"id":"cc11d921.7096f8","type":"rbe","z":"bf3bef9a.b6faf","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":1010,"y":400,"wires":[["c49a8b2e.806a18","986ceddd.e1347"]]},{"id":"c49a8b2e.806a18","type":"switch","z":"bf3bef9a.b6faf","name":"Buy/Sell","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Buy","vt":"str"},{"t":"eq","v":"Sell","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":1160,"y":400,"wires":[["b96a4b3.e677db8"],["c3265a99.2bf198"]]},{"id":"986ceddd.e1347","type":"switch","z":"bf3bef9a.b6faf","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":1170,"y":300,"wires":[["74f1c82e.a60c08"],["96e5e633.7120e8"]]},{"id":"74f1c82e.a60c08","type":"delay","z":"bf3bef9a.b6faf","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":180,"wires":[[]]},{"id":"96e5e633.7120e8","type":"change","z":"bf3bef9a.b6faf","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":180,"wires":[["74f1c82e.a60c08"]]}]

```

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

Overall, what I am looking for is:

1. block the first message, then let the other to pass
2. reset the RBE after a certain period of time (1 minute), this would allow to only send a message to the flow every minute.

The result would be:

BLOCK (because of the ignore initial value)  
PASS (buy or sell)  
BLOCK  
BLOCK  
BLOCK  
...  
1 minute later (reset of RBE)  
...  
BLOCK (because of the ignore initial value)  
PASS (buy or sell)  
BLOCK  
BLOCK  
BLOCK  
etc...

Thanks a lot

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 October 2019 19:55 UTC](https://discourse.nodered.org/t/block-first-message/17144/4 "2019-10-26T19:55:06Z")

</div>

How do you determine what the "first" message is ?  
ie. what is the trigger to block it ? If you restart node-red, is there a "first" message or does it continue ?

Your RBE flow won't work, you will have to inject `msg.reset` into the RBE node.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [26 October 2019 21:14 UTC](https://discourse.nodered.org/t/block-first-message/17144/5 "2019-10-26T21:14:09Z")

</div>

> [@mambui](#):
>
> What I would expect here is the RBE - ignore initial value to block the first "buy message", then let the second buy to pass. As soon as it turns to "sell" message, block the 1st sell one, then let the second to pass.

That is WAY different to blocking **the first** message.

Next thing:

(Looking at the latter flow)

The `inject` nodes. They inject "BUY" and "SELL". (Fair enough.  
The `RBE` node. Yeah. Ok.  
Going up. The `switch` node. That will never work because it is looking for `msg.payload` to be "off" or "on".

It is receiving "BUY" and "SELL". It won't work.

On that: This has two outputs. Those outputs go to a `change` node and the `delay` node.  
_tidying up_ the flow a bit, the _wires_ cross over each other.  
Only for neatness, I would suggest you reverse the "on" and "off" detection to which output they use.

![Screenshot%20from%202019-10-27%2008-11-59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6c8edadd6a3b4bae108fc834f71148df8521067c.png)

The `change` node. (Change 2 rules). You forgot to change one of them.  
What you really need to do is set `msg.reset` to `true` - well usually - to get that to work.  
If you are wanting to negate (delete/get rid of) the `msg.payload`, in the `change node` you `delete` `msg.payload`.

I'm stuck now what you are wanting but I hope this helps you with working that out.

---

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [27 October 2019 11:31 UTC](https://discourse.nodered.org/t/block-first-message/17144/6 "2019-10-27T11:31:17Z")

</div>

Hello,

I have found out a way to reset the RBE node on a 10 sec basis. And it works.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4415a89f3d918fddf4b8e5e38148184c504686e2.png)

So far, couldn't find a way to ignore the first value.  
@bakman2 the first value is defined when the incoming message switch from one side (buy) to the other side (sell).

For example:  
Flow reset  
BUY (first message here)  
BUY  
BUY  
BUY  
SELL (fist message here)  
SELL  
BUY (first message here)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 October 2019 11:35 UTC](https://discourse.nodered.org/t/block-first-message/17144/7 "2019-10-27T11:35:14Z")

</div>

> Flow reset  
> BUY (first message here)  
> BUY

What happens in this situation ?

> Flow reset  
> BUY (first message here)  
> SELL (first message here)

---

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [27 October 2019 11:37 UTC](https://discourse.nodered.org/t/block-first-message/17144/8 "2019-10-27T11:37:50Z")

</div>

Nothing happens in this situation.  
If I have continuously that kind of message, the flow will not push any orders:  
BUY  
SELL  
BUY  
SELL  
BUY  
SELL

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [27 October 2019 13:09 UTC](https://discourse.nodered.org/t/block-first-message/17144/9 "2019-10-27T13:09:46Z")

</div>

> [@mambui](#):
>
> So far, couldn't find a way to ignore the first value.

Would this work for you? - you node-red-contrib-counter to count messages and only pass ones with count \> 1

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

```auto
[{"id":"1abbde50.1b4f02","type":"inject","z":"4a7532ff.d6041c","name":"","topic":"","payload":"Buy","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":182,"y":198,"wires":[["231fb195.e4d9de"]]},{"id":"c5e9ea1e.fb1ec8","type":"inject","z":"4a7532ff.d6041c","name":"","topic":"","payload":"Sell","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":182,"y":242,"wires":[["231fb195.e4d9de"]]},{"id":"eab132b9.87468","type":"debug","z":"4a7532ff.d6041c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":820,"y":220,"wires":[]},{"id":"231fb195.e4d9de","type":"counter","z":"4a7532ff.d6041c","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":390,"y":220,"wires":[["e016caa4.fa5d38"]]},{"id":"e016caa4.fa5d38","type":"switch","z":"4a7532ff.d6041c","name":"","property":"count","propertyType":"msg","rules":[{"t":"gt","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":534,"y":220,"wires":[["eab132b9.87468"]]}]

```

---

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [27 October 2019 13:58 UTC](https://discourse.nodered.org/t/block-first-message/17144/10 "2019-10-27T13:58:55Z")

</div>

Thank you @cymplecy  
I test it out. This counter node works, however it only works for the first message entering in the flow. Doesn't work for upcoming new "first message".

For example:  
Flow reset  
BUY (first message here) . IT WORKS HERE  
BUY  
BUY  
BUY  
SELL (fist message here) NOT WORKING HERE  
SELL  
BUY (first message here) NOT WORKING HERE

---

<div class="post-metadata">

**Author:** ![mambui](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mambui](https://discourse.nodered.org/u/mambui)\
**Post date:** [27 October 2019 14:14 UTC](https://discourse.nodered.org/t/block-first-message/17144/11 "2019-10-27T14:14:37Z")

</div>

Found out a solution here. I also reset that side of the flow (counter), as follow:

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

It works, thanks to all of you for your precious help.
