Switch a value from boolean

Hi all.
I want set a function output to an input value when a boolean becomes true and to zero when boolean become false.
I try with switch and change but nothing runs correct.
I try with two ways : set a value 0 for false and 1 for true and multiply it with the input value otherwise in a if structure put the output = msg.payload (input value) if the boolean is true and = 0 if false.
Some ideas?

It is hard to be certain from your description, but maybe the problem is that the Boolean and the "input value" arrive at your function node as separate messages. So the function has no knowledge of the Boolean when an input value arrives.

You need to join the messages into one containing both Boolean and input data or else store the Boolean as a context variable.

Thanks for the answer
I try to explain the situation in a better way.
I receive from a machine a value from a communication block.
This block send the actual speed value from a pump every second.
In the meantime a valve divert pump flow from main circuit to recirculation.
I want a variable that is the actual speed ONLY if the valve is on main circuit.

Analog switch.json (4.0 KB)
By this way is ok for my application

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