How use the function node

Hello, I need help to display a text in a temple node, I attach my flowchart and how I have organized the nodes in the flow.
In the function node c I get values ​​of sensor signals and alarm and pre-alarm constants, what happens in that node is a simple subtraction, just like in the function node h. And this is where I have the problem when comparing them in my 'CONCATENATE' function, it doesn't show me when I have two alerts. Just show me one. I am a beginner in node red.


One important point to know is that messages never travel down the wires at the same time. Your function has two wires & therefore 2 messages will arrive at different times.

You can use a join node to join two or more message (canned text below) however in your case here, the better solution is to write everything in series & use different msg properties. E.g func1 outputs result in msg.payload1, passes that msg to func2 which puts it's value into msg.payload2 which then gets passed to func3 where it has access to msg.payload2 & msg.payload1 at the same time (in the same msg)

Canned text...

See this article in the cookbook for an example of how to join messages into one object.

1 Like

I have a question, the declaration of 'fh' and 'fc' are well matched with msg.payload?
because so with my test values ​​it is supposed to send the alert where 1 and 2 are, however it does not send that.

The important thing to realise is that your function "CONCATENAR" will operate on the messages from "fuction c" and "fuction h" totally independently.
It does not have access to both payloads simultaneously.

fh and fc are identical. They both equal the payload from fuction h at one moment, and they both equal the payload from fuction c at another moment.

@Steve-Mcl has described how you can make the two payloads available in a single message so you can do your comparisons.

Edit - In one of your functions, I presume it is "fuction h", you set msg.payload.hous to either 2 or 0, but in CONCATENAR you set fh = msg.payload and then test if it == 1 or 2.
{hous: 2} is an object, 2 is a number. They can never be equal.

But how would I do the condition using the join node? if they would be separated from my 'Concatenate' node

Take a look at this flow.
After the join there is a single message in which msg.payload.fh == 2 and msg.payload.fc == 0

[{"id":"cb223579aad92683","type":"join","z":"947cea7bd1d96252","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":770,"y":160,"wires":[["f891feb32cadaf79"]]},{"id":"c0be4639e49854a2","type":"inject","z":"947cea7bd1d96252","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":160,"wires":[["9c0198ea99de86d1","c0534cf69da384ae"]]},{"id":"9c0198ea99de86d1","type":"function","z":"947cea7bd1d96252","name":"Set msg.payload = 2, msg.topic = fh","func":"msg.payload = 2\nmsg.topic = \"fh\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":140,"wires":[["cb223579aad92683"]]},{"id":"c0534cf69da384ae","type":"function","z":"947cea7bd1d96252","name":"Set msg.payload = 2, msg.topic = fh","func":"msg.payload = 0\nmsg.topic = \"fc\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["cb223579aad92683"]]},{"id":"f891feb32cadaf79","type":"debug","z":"947cea7bd1d96252","name":"debug 79","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":920,"y":160,"wires":[]}]

There is a series of short videos that might be worth watching, though of course the narration is all in English.

1 Like

Better to do them in series, as suggested by @Steve-Mcl, or possibly even better do it all in one function node. There is no point splitting the flow and then going to the effort of joining it back together again.

1 Like

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