A change in parodyme for flow construction and the `GATE` node

I admit I am still learning some of the existing nodes.

When I got into NR a bit further I was wanting a way to control if a message could pass a point.

By default there is no obvious way of doing this with the supplied nodes.

The way around it for me was this way:

[{"id":"de6e9992.645088","type":"link in","z":"8c64c96f.09f13","name":"TRAIN","links":["8fd2d7ca.72146"],"x":810,"y":2260,"wires":[["590e4a25.90892c","81d505d2.aa7da8"]],"l":true},{"id":"590e4a25.90892c","type":"function","z":"8c64c96f.09f13","name":"Train detect","func":"let m = flow.get('MODE');\nif (m == \"HOLD\")\n{\n    //      HOLD\n    flow.set('TRAIN','HELD');\n//    msg.payload = \"STOP\";\n//    return msg;\n    return;     //  Don't return anything.\n                //  Though I may need to send\n                //  something as a \"signal\" of\n                //  a new message.\n}\nreturn msg;","outputs":1,"noerr":0,"x":980,"y":2260,"wires":[["79823e18.d22d68"]]},{"id":"81d505d2.aa7da8","type":"change","z":"8c64c96f.09f13","name":"Get MODE","rules":[{"t":"set","p":"payload","pt":"msg","to":"MODE","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":2190,"wires":[["1ba6b9d7.19f76e"]]},{"id":"1ba6b9d7.19f76e","type":"switch","z":"8c64c96f.09f13","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"HOLD","vt":"str"},{"t":"eq","v":"RELEASE","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1140,"y":2190,"wires":[["916777f.3131688"],["817bae21.99f678"]]},{"id":"817bae21.99f678","type":"change","z":"8c64c96f.09f13","name":"Allow","rules":[{"t":"set","p":"payload","pt":"msg","to":"GO","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":2210,"wires":[["79823e18.d22d68"]]},{"id":"79823e18.d22d68","type":"gate","z":"8c64c96f.09f13","name":"","controlTopic":"CONTROL","defaultState":"open","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1470,"y":2260,"wires":[[]]},{"id":"916777f.3131688","type":"change","z":"8c64c96f.09f13","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":2160,"wires":[["79823e18.d22d68"]]},{"id":"924ab50e.4d2258","type":"comment","z":"8c64c96f.09f13","name":"Allow trains to pass (or stop them)","info":"","x":1080,"y":2120,"wires":[]}]

Which looks like this:
Screenshot from 2020-01-04 14-31-37

And this is better than the original way I did it by having a separate message to control the flow.
The example uses a flow variable to do it.

Walk through:
A message arrives a the TRAIN input node.
Going up, it gets the flow.MODE and then splits if it is ON or OFF.
That then makes two messages which are sent to the gate node to allow/block the message.

Though it works, I only now realised an EASIER way of doing just that.
Granted it is a given that you are reading a context (right term?) variable rather than a message.

But all that could be replaced with this:

[{"id":"de6e9992.645088","type":"link in","z":"8c64c96f.09f13","name":"TRAIN","links":["8fd2d7ca.72146"],"x":950,"y":2260,"wires":[["1ba6b9d7.19f76e"]],"l":true},{"id":"1ba6b9d7.19f76e","type":"switch","z":"8c64c96f.09f13","name":"","property":"MODE","propertyType":"flow","rules":[{"t":"eq","v":"ALLOW","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":2260,"wires":[["79823e18.d22d68"]]},{"id":"79823e18.d22d68","type":"gate","z":"8c64c96f.09f13","name":"","controlTopic":"CONTROL","defaultState":"open","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1300,"y":2260,"wires":[[]]},{"id":"924ab50e.4d2258","type":"comment","z":"8c64c96f.09f13","name":"Allow trains to pass (or stop them)","info":"","x":1130,"y":2190,"wires":[]}]

Or:
Graphically

Screenshot from 2020-01-04 14-37-32

So much easier and compact.

Basically it works like so:

As before, message arrives at TRAIN node.

The switch node:
check if flow.MODE == "Allow" (for example)
If it does match, it passes the message.

To give you more food for thought: do you need the gate node ?

1 Like

Ah!

I goofed.

In the original flow I posted, it was to switch (control) the state of the gate node that then either stops or allows things to go through it.

I didn't include the part of the flow which was controlled. I only went as far as the gate node.

Really the switch node in the last flow is all that is needed in the bigger flow to switch/control the flow of messages.

I guess I am still making my mistakes of posting too quickly and not thinking of the bigger picture.

(One step forward, two back.) Oh well.

Thanks for the heads up though.