Isolate a value


#1

Hello,
Iam looking for a solution to isolate a "value" with the Function Node. The Node have 2 outputs.
The value is 0 or 1,
If it is 0 a output must deploy a 1, the other output does nothing
if de value is 1 the other output becomes 1. the other output does nothing
the input of the Function is:

{"len":11,"objectId":{"type":3,"instance":0},"property":{"id":85,"index":4294967295},"values":[{"type":9,"value":1}]}

thanks.


#2

If you feed that into a debug node, select the property you are interested in (the 1 in this case) and hover over it then some little buttons appear to the right. One of those when clicked will say Path Copied (the leftmost button I think). If you paste that somewhere you will see how to access the value property. Having done that you can do what you want in a function but you could use a Change node set to Move that property into msg.payload, then a Switch node to test the value and send the message on to the appropriate output.


#3

this page in the docs is worth a read
https://nodered.org/docs/user-guide/messages


#4

For this kind of problem you don't need a function Node. Try to do this using the "Switch" node (add 2 outputs to it and configure it to look for msg.value) and after the Switch use 2 "Change" nodes.

Actually the function Node is used only in extreme cases. In 90% of the cases you can play with Switch (as an "if"), with Split and Join(as a "for") and with Change (as a value changer). Trust me, once you learn how to use those 4 nodes your life will change forever.