Combining two outputs of different datatypes to form a conditional statement

Hello everyone,

I have been posting a lot of beginner questions lately as I have been trying to explore some new functionalitites and develop a better understanding. Here begins my new problem:

"1. I have a MQTT listening node, which reads a tagID as string.
2. I have another output from a weather data extracting node which shows the weather details.

I am trying to combine these 2 outputs with 'join' node and then 'split' node to feed into a function node, which gives a conditional output.

I am trying to have a condition. For eg: "If the temperature < 20 and the ID = 73219136, it should display a message "Please be safe. The commodity is hazardous"

As of now, my "Conditional Statement" function node has the following content, as in the screenshot attached. I have also attached a screenshot of my flow.

Few days back, I had some queries regarding the similar flows and some experts here assisted me exactly to the solution. I thank you all and I hope I have highlighted my doubt in an understandable way. I have read some similar forums but unable to solve he problem for the 'uID', temperature is not showing any error.
Thanks and Regards

in your example you have

Temp = msg.payload.tempc
uID = msg.payload

msg.payload cannot be a variable and an object at the same time.
A node only (generally) works on the last message it was sent so if you are expecting the function node to have some form of memory, you will need to do that yourself.

I'd suggest you put debug nodes along your flow to see what the messages are that you are sending through ( not sure what the going and split nodes are doing for example)

To merge data from different messages you can do it in two ways.
You can either use the join node
or use context variables which allow you to "carry over" a variable from one flow to another


Thanks @ukmoose for your prompt response. I understand what you mean and I have also seen these join streams link yesterday while dealing with this condition.

  1. The output from the MQTT input node is a string
  2. Output from Weather data is an object

Reason for using split node is to break the payload and like I said the conditional function node understands the 'msg.payload.tempc' correctly. The problem I am facing is to combine this with the 'string' output to form a condition, I lack the proper knowledge of variables and datatypes but I am sure you guys will be able to solve it out. Please see the pic below for a lot more better understanding.

Thanks and Regards

Use a Join node in Key/Value pair node, then you will have both payloads available in the output message of the Join node.

1 Like

To get the best from Node-RED you really need to understand that there are loads of good tutorials on javascript objects, variables and arrays online.
So I would suggest starting by reading one of those tutorials, read the docs on the Node-RED website about functions and working with messages. And as I have already suggested, add debug nodes to see exactly what messages are going along your flow.

1 Like

@ukmoose Thanks a lot for your suggestion. I am following some tutorials parallely and trying to gather much knowledge. :slight_smile:

Or try changing your flow to make it in series, which is a lot easier in the long run

1 Like