Declare msg.payload as a value

My message payload is a value of X, its always changing, in this example it's 33.13.

Payload

How would I go about declaring it so I can use it in the position or value I have as "X" in this example

Thank you for your help

There are numerous ways to do this, here are examples of 4 ways.

[{"id":"ee071f60.912ab","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"33.45","payloadType":"num","x":200,"y":3260,"wires":[["7c38eac9.44776c","483ff17b.1523d8","52df4dc0.6d0da4","9a658455.b43348"]]},{"id":"7c38eac9.44776c","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"hold","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{\"p1\":{\"v\":1,\"w\":2}}","tot":"json"},{"t":"move","p":"hold","pt":"msg","to":"payload.p1.x","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":3160,"wires":[["a51b5a1f.26af08"]]},{"id":"483ff17b.1523d8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"p1\":{\"v\":1,\"w\":2,\"x\":$$.payload}}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":3260,"wires":[["a51b5a1f.26af08"]]},{"id":"52df4dc0.6d0da4","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"p1\":{\"v\":1,\"w\":2,\"x\":{{{payload}}}}}","output":"json","x":370,"y":3320,"wires":[["a51b5a1f.26af08"]]},{"id":"9a658455.b43348","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload = {\"p1\":{\"v\":1,\"w\":2,\"x\":msg.payload}}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":3400,"wires":[["a51b5a1f.26af08"]]},{"id":"a51b5a1f.26af08","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":3240,"wires":[]}]
1 Like

I'm just a beginner, and to be honest I'm lost with your code. Can you break out one so I can review it.

Thank you

To see the 4 examples - copy the code and then in Node-RED - click on the hamburger menu top-right - select Import - paste into the big box and click on import

You can then see them all

I personally would think that the template one is the easiest to understand and play around to suit what you want

Got it now, this makes a big difference.

Thank you

I don't think I'm asking the question properly.

the string I send to my controller is

image

what ever I set in "value": "X" presently ( "value": "85")

gets written.

how do i make this my payload value?

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