Switch a flow on or off

#1

I would like to use a dashboard switch to allow or stop a flow of time triggered analog data from a sensor input to a save to file node.

It seems like a fairly simple task to request but I can't picture how I can do it.

On the dashboard switch properties I can see True and False or could make it a number 0 and 1, but what node can I use to "switch" the flow?

The Function Switch node seems like a logical choice but I need an in and an out for the flow, and I need somewhere to connect the output of the Dashboard Switch?

Does it have to do with Topic?
Do I use the input of the Function Switch for both the flow and the switch and somehow tell it what to do the the properties settings of the Function Switch?
I have not yet grasped the concept of Topic. Can anyone suggest a simple tutorial that could help?

Thank you.

0 Likes

#2

The cookbook is always a good place to start.
Take a look at this flow and it should give you a start on how a dashboard switch could control a different flow

https://cookbook.nodered.org/basic/route-on-context

0 Likes

#3

Thank you.

So there is no connecting line between the change node and the switch node.
It just magically watches the value of state without any connection.

0 Likes

#4

Well it’s not magic.

https://nodered.org/docs/user-guide/context

0 Likes

#5

Or you could use a function node as a simple gate (and keep the wiring visible).
https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65
Up to you

0 Likes

#6

I recommend using node-red-contrib-simple-gate for this. You can feed the signal from the switch straight into it to control whether it allows messages to pass or not.

0 Likes