# Merging Values to a single payload

**URL:** <https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947>\
**Category:** General\
**Created:** [6 November 2024 20:48 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947 "2024-11-06T20:48:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerribaldi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerribaldi/32/38935_2.png) [@gerribaldi](https://discourse.nodered.org/u/gerribaldi)\
**Post date:** [6 November 2024 20:48 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/1 "2024-11-06T20:48:59Z")

</div>

Hi,

i want to sent this value "2c1426085000" via MQTT to a valve. This is basicly no problem. But the point ist this:  
I need to join the value from different sources. Most of the sources are always the same and i can inject it anytime when i want it. Two of the digits are changing more often (in the example "14") and i need to insert it to the value.

So, the question ist: How can i join all this single values to one big value like this "2c1426085000"

Here are the code which i try. For testing, the source are inject nodes. In the final version, some of the sources are mqtt inputs and the rest are inject nodes which are infected in a period of time.

```auto
[
    {
        "id": "52fe3b78327ab63e",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "99882603db7c3a7b",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "Temp via MQTT",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Temp",
        "payload": "19",
        "payloadType": "num",
        "x": 160,
        "y": 340,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "be2258171f9de346",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "Vorwahl Um-Temp",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "UMT",
        "payload": "20",
        "payloadType": "num",
        "x": 170,
        "y": 260,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "cf2dbf3357fd8a58",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "SSV",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "18",
        "payloadType": "num",
        "x": 150,
        "y": 400,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "b5fdbe16236d4c02",
        "type": "join",
        "z": "52fe3b78327ab63e",
        "name": "",
        "mode": "auto",
        "build": "merged",
        "property": "payload",
        "propertyType": "msg",
        "key": "payload",
        "joiner": "\\n",
        "joinerType": "str",
        "useparts": true,
        "accumulate": false,
        "timeout": "",
        "count": "5",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 490,
        "y": 340,
        "wires": [
            [
                "ec5e3c3471d91c3b"
            ]
        ]
    },
    {
        "id": "c30eb7349705e5da",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "RCI",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "5",
        "payloadType": "num",
        "x": 150,
        "y": 460,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "355daf3cf526d89e",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "UM",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 150,
        "y": 520,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "ad43ad613ba89018",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "SM",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 150,
        "y": 580,
        "wires": [
            [
                "b5fdbe16236d4c02"
            ]
        ]
    },
    {
        "id": "ec5e3c3471d91c3b",
        "type": "debug",
        "z": "52fe3b78327ab63e",
        "name": "Value",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 340,
        "wires": []
    },
    {
        "id": "6e4adf53c93ca4ba",
        "type": "debug",
        "z": "52fe3b78327ab63e",
        "name": "Hex Wert",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 120,
        "wires": []
    },
    {
        "id": "08f522263f7791ea",
        "type": "base64",
        "z": "52fe3b78327ab63e",
        "name": "",
        "action": "",
        "property": "payload",
        "x": 600,
        "y": 120,
        "wires": [
            [
                "6e4adf53c93ca4ba",
                "154c7740175d3e40"
            ]
        ]
    },
    {
        "id": "d2d922ae78d177fe",
        "type": "buffer-parser",
        "z": "52fe3b78327ab63e",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "item1",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "swap16",
        "swap2": "swap16",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "buffer",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 390,
        "y": 120,
        "wires": [
            [
                "08f522263f7791ea"
            ]
        ]
    },
    {
        "id": "97e4064d250b3e64",
        "type": "inject",
        "z": "52fe3b78327ab63e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "raw",
        "payload": "2c1426085000",
        "payloadType": "str",
        "x": 140,
        "y": 120,
        "wires": [
            [
                "d2d922ae78d177fe"
            ]
        ]
    },
    {
        "id": "ecedac17f9d34fc5",
        "type": "comment",
        "z": "52fe3b78327ab63e",
        "name": "Finished value; converted and sent via mqtt",
        "info": "",
        "x": 240,
        "y": 60,
        "wires": []
    },
    {
        "id": "154c7740175d3e40",
        "type": "mqtt out",
        "z": "52fe3b78327ab63e",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "x": 790,
        "y": 180,
        "wires": []
    },
    {
        "id": "854b049ceb91291a",
        "type": "comment",
        "z": "52fe3b78327ab63e",
        "name": "Join all single values to one big value",
        "info": "",
        "x": 230,
        "y": 200,
        "wires": []
    },
    {
        "id": "b3cf75f8de8dc8f2",
        "type": "comment",
        "z": "52fe3b78327ab63e",
        "name": "Normaly MQTT Input",
        "info": "",
        "x": 170,
        "y": 300,
        "wires": []
    }
]

```

Regards

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 November 2024 09:09 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/2 "2024-11-07T09:09:08Z")

</div>

It is unclear to me what your problem is since you don't explain what the sources of the data are (what nodes they are), how you inject 'inject' the data.

Please create a small flow demonstrating your problem and post it to a reply.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [7 November 2024 09:54 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/3 "2024-11-07T09:54:50Z")

</div>

Might be worth taking a look at this CookBook article...  
[https://cookbook.nodered.org/basic/join-streams](https://cookbook.nodered.org/basic/join-streams)

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [7 November 2024 11:18 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/4 "2024-11-07T11:18:19Z")

</div>

use a join node,and create an object of all different variables

---

<div class="post-metadata">

**Author:** ![gerribaldi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerribaldi/32/38935_2.png) [@gerribaldi](https://discourse.nodered.org/u/gerribaldi)\
**Post date:** [7 November 2024 14:41 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/5 "2024-11-07T14:41:08Z")

</div>

I added some code in my first post, hopefully this helps.

The flow should join all the different sources to one value which i can sent to valve. The valve accept only the format of the values which i posted in my first post.  
In this value are different settings for the valve, most of them never changed. One of the sources are the current temperature from a external sensor which i need to sent to valve so this can move to the rihgt position and regulate the temperature.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 November 2024 15:19 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/6 "2024-11-07T15:19:19Z")

</div>

First you have to join the source messages into one message, then you can build the exact string that you need. For that you can use a Join node as several have already suggested.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [7 November 2024 15:19 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/7 "2024-11-07T15:19:42Z")

</div>

Try this...

 ![tues_orig_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2d78d9d276bfc76324e94abb077ce853f5ba405.png)

```auto
[{"id":"99882603db7c3a7b","type":"inject","z":"52fe3b78327ab63e","name":"Temp via MQTT","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Temp","payload":"19","payloadType":"num","x":160,"y":340,"wires":[["b5fdbe16236d4c02"]]},{"id":"be2258171f9de346","type":"inject","z":"52fe3b78327ab63e","name":"Vorwahl Um-Temp","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"UMT","payload":"20","payloadType":"num","x":170,"y":260,"wires":[["b5fdbe16236d4c02"]]},{"id":"cf2dbf3357fd8a58","type":"inject","z":"52fe3b78327ab63e","name":"SSV","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SSV","payload":"18","payloadType":"num","x":150,"y":400,"wires":[["b5fdbe16236d4c02"]]},{"id":"b5fdbe16236d4c02","type":"join","z":"52fe3b78327ab63e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":true,"accumulate":false,"timeout":"","count":"6","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":340,"wires":[["ec5e3c3471d91c3b"]]},{"id":"c30eb7349705e5da","type":"inject","z":"52fe3b78327ab63e","name":"RCI","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"RCI","payload":"5","payloadType":"num","x":150,"y":460,"wires":[["b5fdbe16236d4c02"]]},{"id":"355daf3cf526d89e","type":"inject","z":"52fe3b78327ab63e","name":"UM","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"UM","payload":"2","payloadType":"num","x":150,"y":520,"wires":[["b5fdbe16236d4c02"]]},{"id":"ad43ad613ba89018","type":"inject","z":"52fe3b78327ab63e","name":"SM","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SM","payload":"0","payloadType":"num","x":150,"y":580,"wires":[["b5fdbe16236d4c02"]]},{"id":"ec5e3c3471d91c3b","type":"debug","z":"52fe3b78327ab63e","name":"Value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":340,"wires":[]},{"id":"854b049ceb91291a","type":"comment","z":"52fe3b78327ab63e","name":"Join all single values to one big value","info":"","x":210,"y":220,"wires":[]},{"id":"b3cf75f8de8dc8f2","type":"comment","z":"52fe3b78327ab63e","name":"Normaly MQTT Input","info":"","x":170,"y":300,"wires":[]}]

```

I've given each input a unique topic-name and adjusted the settings in the Join node to this...

 ![thursday_join](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/ebbdfe6d6d77a0b2134e4888ee57b0724100168c.png)  
Gives this as a merged Object...  
 ![thursday_object](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95b3ffa4920335212cc9119e4fd02b71909f1e09.png)

---

<div class="post-metadata">

**Author:** ![gerribaldi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerribaldi/32/38935_2.png) [@gerribaldi](https://discourse.nodered.org/u/gerribaldi)\
**Post date:** [11 November 2024 20:16 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/8 "2024-11-11T20:16:45Z")

</div>

Thanks, that is a big step in the write direction.

know i have everything in one single message how can i merge it to a value like this "2c1426085000"? For this i need to remove the topics and merge it again, or?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [12 November 2024 08:03 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/9 "2024-11-12T08:03:12Z")

</div>

Here's one simple way you could do it, by adding a 'function' node to your flow.

 ![tues_merge_parts](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10dde3d1a740ea857197d373ade8604e9e3e10c4.png)

The Debug labelled 'Value' shows msg.payload is an Object and is made-up of various parts. Each part can be accessed using the dot '.' notation. For example SSV is in msg.payload.SSV and RCI is in msg.payload.RCI.

 ![tues_merge_parts_debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abd67b971f26774799223fb49169ba215aebf781.png)

Note: I'm assuming these values are numeric and therefore need to be converted to a string before adding them together to create a new payload. If you add them without the conversion then you will get the numerical addition of the objects. e.g. 1 + 2 = 3 Which is not what you want.

In your original question I have no idea where the "2c" came from, so I've added that as text at the start of the new payload.

Here's what's in the 'function', you will need to edit it to suit your needs/application.

```auto
msg.payload = "2c" + msg.payload.SSV.toString() + msg.payload.RCI.toString();
return msg;

```

The Debug labelled 'merged' shows the new contents of msg.payload as a string.

Hope this is useful to you?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2024 09:42 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/10 "2024-11-12T09:42:31Z")

</div>

If the values have to be, for example, 2 digits in the resulting string then you can use something like `msg.payload.SSV.toString().padStart(2,"0")` which will pad the number with zeros on the front if necessary to make it up to 2 digits.

---

<div class="post-metadata">

**Author:** ![gerribaldi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerribaldi/32/38935_2.png) [@gerribaldi](https://discourse.nodered.org/u/gerribaldi)\
**Post date:** [23 November 2024 21:00 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/11 "2024-11-23T21:00:31Z")

</div>

Thanks a lot, this works 👍

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 December 2024 21:00 UTC](https://discourse.nodered.org/t/merging-values-to-a-single-payload/92947/12 "2024-12-07T21:00:48Z")

</div>

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