Node Red Ignore Switch

Hey,

If the two switches are off and then I trigger one of the injectors, the function behind it is still executed, but why?

grafik

grafik

Why is this still happening?

Thanks in advance

It's still happening because you misunderstand the role of a ui-switch.

For a node which either blocks messages or lets them through, try node-red-contrib-simple-gate

Thank you.
I thought the switch blocks messages.
I put a function behind the Switch with this code:

if(msg.payload == true)
{
return msg;
}

Now its working

I'm glad you have fixed it.

At the risk of confusing you, there is also a Switch node (not UI) which can very easily discard or divert messages based on their payload.

It's probably a mistake to jump too quickly into writing functions rather than using the available nodes.

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