Stop flow after a message

Dear people, i am looking for a way to stop a flow.
I use an inject node that gives an inject every 10 minutes to see if the lux meter outside is within a certain value. If he does that, a lamp is switched on.
but now the problem he continues to give every 10 minutes an inject. I have set these. . how can I make sure that if 1 msg has come through then the next one can be blocked.


Hi, try putting an RBE node between the last two nodes! (Read the RBE node information to understand what is happening).

hi ghayne,
I tried that, but then I can't get it on again

I am not understanding what you mean.

Here is what I understand:

Every 10 minutes you send a pulse and that is used to trigger a node to return the outside lux value.

he and that. Not defined.

Continuing to read, it nearly implies that after one cycle you want to stop. why?

The ongoing cycle of 10 minutes is not relevant. That is just time passing. It happens anyway.

Are you asking how to stop accepting those pulses?

But under what condition?

Your qualification of the condition is not clear so I am not understanding that part.

An alternative is to use a node-red-contrib-simple-gate which can easily be set to pass or block messages by sending it commands.

1 Like

best trying to learn, I give a pulse every 10 minutes to turn on a lamp. this lamp only switches on if the lux range is between 0 and 50. If not, the lamp will remain off. Because it is not dark yet. 10 minutes later he gives another pulse. just as long as it is necessary to switch on the lamps and that it is dark enough. Once the lamp has been switched on, the pulse may also stop. I will continue to give this pulse from 17:00 to 22:30.
Do I make it clearer with this ??

if you have other ideas to get this done I would love to hear it. just to be clear I am quite new with node red and am certainly not a programmer.

gr Vlak

So won't my solution with the gate node work for you?

Hi Collin, no this is not working. I switch to a light value that can be between 0 and 100 lux. I trigger this with an inject noder every 10 minutes from 5:00 PM to 11:00 PM.
The RBE node cannot block a flow if the value does not change. But that's just the value that is constantly changing. I want the lux meter to turn on the lights once. After that it can be blocked.

How bout:

  • Big Timer for the kickoff, lets say on message is "kickoff"
    has the advantage: you can (if you want to go advanced) f.e. set latitude and longitude inside the BigTimer, and then define to always start f.e. always dawn with an offset of -60, which is 60 minutes before dawn in your region.

  • then set a first function node. Something like (just written it before sleep so not tested, may need a bit tweeking):

if (msg.payload == "kickoff")
flow.set('lampOn', 0); // reset marker 
msg.payload = 0;
return message;

which is the start for a second function node you have to add. There, just loop until a specific value, and also check for a flow variable you can change when your lamp is on. Lets say every ten minutes for three hours, is 18 runs (?) max:

var lampOn = flow.get('lampOn') || 0; // look for variable "lampOn", return 0 if not exist
if ((msg.payload < 18) && (lampOn == 0)) // loop has not reacht 18 runs and lamp is not set on so far
msg.payload = msg.payload +1;
return msg;

and the output of the node is just connected to your lux-stuff and also to a delay-node, which just delays for 10 minutes. And the delay-node output is again connected to the input of the second node. So the second node kicks itself every ten minutes until the 18 is reached.

For the Lux-stuff, just add a function node. Connect its input to where is an output when your lamp is set on, just a one-liner:

flow.set('lampOn', 1); // sets your flow-variable to 1, so the loop will not continue.

An improvement then could be to add a time off message to the BigTimer, lets say "loopOff", and then add to the first function node:

if (msg.payload == "loopOff"){
 flow.set('lampOn', 1);

which also results in a stop of your loop. Could be helpful if the loop starts before dawn (which varies every day), but should stop always at a certain time.

Again: this is not tested, just written down before sleep. Maybe you need some minor improvements.


( // means it is commented out in function nodes if you don´t know. Its just to understand the code)

couldn't you just run this every 1 minute (instead of 10 minutes) - check the lux value and feed it to the smooth node

Average the last 10 readings - send them out to the switch node - check if it is in your dark range and switch to output 1, if it is in the light range switch to output 2

Have a change node on each switch output, that takes the incoming and output a 1 or 0

Use the RBE node to send the light on or off command

If i get time later i can do up a flow for this

The advantage of this is you have no functions or code to write etc (for a beginner)


I suggested using the simple-gate node not an RBE.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.