Block first message

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.

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)

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.

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

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:

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

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

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.

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

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.

Hello,

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

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)

Flow reset
BUY (first message here)
BUY

What happens in this situation ?

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

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

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

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

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

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

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