Merging Values to a single payload

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.

[
    {
        "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

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 ```)

``` 
   code goes here 
```

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

See this post for more details - How to share code or flow json

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

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

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.

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.

Try this...

[{"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...


Gives this as a merged Object...

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?

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

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.

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.

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?

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.

1 Like

Thanks a lot, this works :+1:

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