How to seperate value from incoming msg.payload?

I want to seperate out the value from incoming message as red marked into screenshot...then only I can update this vale to counter dashboard.

please help me hoe to sepertae out the value?

BR

Madhumati

This page shows you how to identify where the part of the message you want is stored and the path to it
https://nodered.org/docs/user-guide/messages

You can the use the Change node to move the part of the message you want to msg.payload which is where the Gauge node looks

As mentioned - you can use a change node to get at the value and put in into the msg.payload
image
[edit]
Note - it should say msg.payload.Value not msg.payload.value
[/edit]

Can someone give some examples of extracting data using the change node?
An example of adding a topic with change node? Changing a topic? I’ve read all the tutorials, but I’m just not understanding how to put it into action.

1 Like

Where it says Set msg.payload
change it to Set msg.topic

But most nodes expect to get the important piece of information as msg.payload

I can see just below but the counter value is not updating yet in Gauge. In text I see counter value updatted.

Do I have to add function node to seperate out the value from JSON strinng?

In a previous reply, @cymplecy showed you how to copy msg.payload.value to msg.payload so that Gauge node will receive the value properly.

In @ukmoose’s reply, where he said to change msg.payload to msg.topic - he was illustrating how you’d configure a Change node in order to set msg.topic as an example. You still need the Change node @cymplecy showed to set msg.payload in order for your flow to work. If you also want to set msg.topic, you can add a second rule to the Change node to do that separately.

I Have changed to msg.payload only, please check below -

image

image

properties are case sensitive so payload.Value is not the same as payload.value…

Sorry - I didn't realise that

Thanks all for your support, I got now value updated.

It would be great if someone would write another tutorial on the subject of msg.payload, msg.topic etc in the context of node red, and give examples of common configurations of nodes extracting or manipulating their content. Despite having read 2 or 3 tutorials on the subject, I still don’t understand whether msg, payload, topic, are variables, or what they are. Nor do I understand how they are formatted in the raw data as a javascript or json notation. Its very confusing for a beginner, I’m usually pretty good with this sort of stuff, but the tutorials I’ve read so far don’t make the concepts clear to me.

For example from “Writing Functions”:

“The message is passed in as an object called msg. By convention it will have a msg.payload property containing the body of the message.”

What do they mean by msg.payload “property”? How is that different from msg? It “containing the body of the message.” What part contains the body of the message? msg, payload or msg.payload?

4 Likes

Does https://nodered.org/docs/user-guide/messages help?

I think also that possibly it would be useful to you to look at some tutorials on javascript, as object properties and how to handle them are javascript features. Though most such tutorials assume that you are using js in a web page rather than with node.js which can make it tricky to find the stuff that is useful in a node-red environment.

Hello again,

Now I want to access array variable --please see I can get array values in debug-

I want to create tab on dashboard for each array variable seperately...do I need to create a function for this?
Could you please help for creating such function?

Thanks
BR

Madhumati

I posted a link a few replies ago to the docs which show how you can identify how to address any message element. Have another look at that and let us know if it helps, and if not, what problem you are having.

I searched for function to seperate out array value & implemented accordingly below ---


but it shows error

If you recall the discussion at the start of this topic, and also as shown be your debug node output, the array you have is msg.payload.Value not msg.payload.

So try msg.payload.Value.map(...

now it gives error as ; msg.payload.Value = undefined

if msg.payload.Value contains an array then 1st element would be msg.payload.Value[0]

2nd would be msg.payload.Value[1]

etc