A Node-Red subflow acting as a gate valve for messages.
The "Gate valve" subflow operates in one of two states: pass- or blocking. In pass state every input message is passed unmodified, in blocking state incoming messages are not passed thru.
Input
state is set via control messages. control messages are input messages
with payloads of either
{"pass": true}
or {"pass": false}
.
control messages are never passed thru.
Output
messages are passed unmodified or not at all, depending on state.
Install
Copy flow.json to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option
flow.json:
[{"id":"e8c83a2d.f512c8","type":"subflow","name":"Gate valve","info":"Gate valve operates in one of two states: _pass_- or _blocking_. \nIn _pass_ state every input message is passed unmodified, \nin _blocking_ state incoming messages are not passed thru.\n\n\n### Input\n\nstate is set via control messages. control messages are input messages \nwith payloads of either \n`{\"pass\": true}` or `{\"pass\": false}`. \ncontrol messages are never passed thru.\n\n\n### Output\n\nmessages are passed unmodified or not at all, depending on state.\n","in":[{"x":60,"y":40,"wires":[{"id":"f22b8142.b3b69"}]}],"out":[{"x":680,"y":120,"wires":[{"id":"7baad69b.f144d8","port":1}]}]},{"id":"a9f2f30a.b3c33","type":"switch","z":"e8c83a2d.f512c8","name":"payload.pass exists?","property":"payload.pass","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","outputs":2,"x":300,"y":40,"wires":[["dbfaf63b.b562f8"],["7baad69b.f144d8"]]},{"id":"7baad69b.f144d8","type":"switch","z":"e8c83a2d.f512c8","name":"pass false?","property":"pass","propertyType":"flow","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","outputs":2,"x":530,"y":120,"wires":[[],[]]},{"id":"dbfaf63b.b562f8","type":"change","z":"e8c83a2d.f512c8","name":"","rules":[{"t":"set","p":"pass","pt":"flow","to":"payload.pass","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":20,"wires":[[]]},{"id":"f22b8142.b3b69","type":"switch","z":"e8c83a2d.f512c8","name":"payload exists?","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","outputs":2,"x":120,"y":120,"wires":[["a9f2f30a.b3c33"],["7baad69b.f144d8"]]},{"id":"1134f2bc.bc9aed","type":"subflow:e8c83a2d.f512c8","z":"2071f267.3e0df6","name":"","x":160,"y":500,"wires":[["f1e6af34.a4a4b"]]}]