# Merge different messages with same TOPIC

**URL:** <https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367>\
**Category:** General\
**Created:** [10 January 2022 00:06 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367 "2022-01-10T00:06:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 00:06 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/1 "2022-01-10T00:06:34Z")

</div>

Hello, first of all greetings to everyone, i'm new in the forum so if I make any mistake sorry in advance.

Its my first time on Node-Red and i'm trying to create a dashboard for my electric car using node-red-contrib-renault-ze.

So everything is ok with the connection to the car, and now i want to read and display the information, but i'm getting 6 payloads but with duplicated topics.

 ![Captura de ecrã 2022-01-09, às 23.55.36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe7979eb618b6f357ba931e3d110c7888ec62030.png)

So, my first question is, how can i merge the same topics into one payload?

I've tried to use Join and not getting results, can someone help me?

Best regards

PS: sorry for any errors on writing, i'm from Portugal.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 01:33 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/2 "2022-01-10T01:33:56Z")

</div>

> [@IAlves2022](#):
>
> So, my first question is, how can i merge the same topics into one payload?

Hi and welcome.

That is a fair enough question, but I am sure you may understand it isn't always that easy.

Oh, first off: _why_? Why do you want to _merge_ them into one payload?

They are probably coming from different places - only you know that though.

The `join` node is a bit tricky in how to use it.

Open the node (edit it) and take a screen shot and post it to show what you have.

---

<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:** [10 January 2022 07:54 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/3 "2022-01-10T07:54:05Z")

</div>

I think you need to take a look at what is in the msg.payload as the Info section on the Node's page says the node will output multiple messages for battery and cockpit.

 ![Screen Shot 01-10-22 at 07.50 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/313f2bf3d2d13d06d0a5627dc13b93df3690930e.gif)

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 08:28 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/4 "2022-01-10T08:28:25Z")

</div>

Fisrt of all thanks for the replys.

So to answer both of you, because manly its the same reply.

My output as same topic and duplicated content, so, when i storage this or try to acess, the content of the topic its duplicated, and i want only one content per topic.

[Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn) sorry i didin't get what node you want me to open and take screen shot.

[dynamicdave](https://discourse.nodered.org/u/dynamicdave) Its true, the node give that info, but my zoe its one model, when i try to connect to a recent model, the info that i get its clear, one payload per topic, so its what i'm trying to get.

Thank you all for the responses.

Best regards

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 08:43 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/5 "2022-01-10T08:43:25Z")

</div>

The `join` node.

So why it isn't working can be seen.  
Or at least see what you are then given.

BTW, why are you sending the same message multiple times?

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 08:51 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/6 "2022-01-10T08:51:28Z")

</div>

So, this is the screeshot of the response with the join mode.

 ![Captura de ecrã 2022-01-10, às 08.45.24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee2453b5620acf933280cea1d6760e29513eabcf.jpeg)

And the flow

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78b845284a261cefbeb919e23bd4e3bbcda3b06a.jpeg)

```auto
[
    {
        "id": "4cffa92d0c8c7c55",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e78e23064b0ba641",
        "type": "inject",
        "z": "4cffa92d0c8c7c55",
        "name": "no topic -> charge /cockpit",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 100,
        "wires": [
            [
                "1313a077bd5626a3"
            ]
        ]
    },
    {
        "id": "632864f98ffdbd08",
        "type": "join",
        "z": "4cffa92d0c8c7c55",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 650,
        "y": 100,
        "wires": [
            [
                "c9279284f2192f69"
            ]
        ]
    },
    {
        "id": "c9279284f2192f69",
        "type": "debug",
        "z": "4cffa92d0c8c7c55",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 810,
        "y": 100,
        "wires": []
    },
    {
        "id": "1313a077bd5626a3",
        "type": "renault-ze",
        "z": "4cffa92d0c8c7c55",
        "name": "IAlves",
        "x": 450,
        "y": 100,
        "wires": [
            [
                "632864f98ffdbd08"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:03 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/7 "2022-01-10T09:03:14Z")

</div>

Well, the `join` node isn't set correctly.

You haven't told it how many message to _join_.  
Also the _format_ of the output is/seems to be problematic.

I think you need to make a `sting/buffer` (look at the `to type` option.  
and put a value in the `after a number of message parts`

Until that is done, nothing will work.

Sorry, but now I am out of my depth with what type of output you need/want.

But again: why send the same message several times?

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 09:10 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/8 "2022-01-10T09:10:35Z")

</div>

Ok i'll try the thing you said.

> [@Trying\_to\_learn](#):
>
> But again: why send the same message several times?

Probably i've missed the explanation, i'm not sending the message several times, i have the inject only one time and the response its this:

 ![Captura de ecrã 2022-01-09, às 23.55.36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe7979eb618b6f357ba931e3d110c7888ec62030.png)

So, one inject and the result its different messages with the same topic, and i want to join the topics, because its the same result!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:13 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/9 "2022-01-10T09:13:20Z")

</div>

So you need to work out how many of these message you get.

Put that in the `join` node as the number of messages to join.

Given they are `json` format, keep it as that. But there is no `keep as received` so you need to pick that one.

Again: Now I am out of my depth.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:29 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/10 "2022-01-10T09:29:09Z")

</div>

New thought.....

You get these messages with are.... (I think called) `objects`.

You can `parse` the message and send that to the part of the flow that will process it.

I can't elaborate on that any more as I don't know the message structure.  
But if it is what Dave posted, then you would use things like:

`msg.data.attributes.batteryTemperature`

So you use the `change` node to set the `msg.payload` to `msg.data.attributes.batteryTemerature` (for instance) and send it to the part of the flow that needs it.

That will need to be done a lot of times, but as I read it, there is no other way.

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 09:29 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/11 "2022-01-10T09:29:38Z")

</div>

Can you please explain this part?

> [@Trying\_to\_learn](#):
>
> Given they are `json` format, keep it as that. But there is no `keep as received` so you need to pick that one.

So i've manage this solution:

 ![joinFLow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d6059447ff122109f674c3d6e78f920a15e7413.jpeg)

I will continue to create the dashboard and the project with this solution.

Thank you for the replys

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:32 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/12 "2022-01-10T09:32:12Z")

</div>

Maybe look at/into my second suggestion.

Using a `join` node only complicates (?) a message that further down the track you will take apart again back to what you originally got. (or nearly originally got)

So it seems repetitive - in a redundant kind of way.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:36 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/13 "2022-01-10T09:36:31Z")

</div>

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d6059447ff122109f674c3d6e78f920a15e7413.jpeg) ](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d6059447ff122109f674c3d6e78f920a15e7413.jpeg)

If the `join` is working as you show: one press of the button should only give you one message out.

So that I can see 3, I'm confused.

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 09:39 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/14 "2022-01-10T09:39:21Z")

</div>

So, what you are saying its to parse all the items into separated payloads?

This is a example of the response on the topic battery-status

 ![Captura de ecrã 2022-01-10, às 09.33.57](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1142b71c5921551f5e7f11964f86b06d82b3aa91.png)

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 09:41 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/15 "2022-01-10T09:41:27Z")

</div>

On the first attemp without the Join node, if you get the response, with One inject i get two responses for the SAME topic, duplicated topics.

And the result that i want, its one message per topic!, so with the join node, its one message per topic in each inject.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 January 2022 09:51 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/16 "2022-01-10T09:51:06Z")

</div>

Well, I'm not sure if that is exactly what I mean.

I don't know what the flow does in the bigger scheme. But parts of the flow want specific parts of those incoming messages.

So rather than messing around _joining_ the message into one homogeneous one which you are going to them split down to smaller ones anyway, you can do that before you join them.

So if part of your dashboard wants to know the battery temperature, you do something like this:

(Hang on while I make the flow)

```auto
[{"id":"d208180966fc5f61","type":"change","z":"437e4108076e5928","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.data.attributes.batteryTemerature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1010,"wires":[["a07415564afbba11"]]},{"id":"2c9a3c0cc525f8c6","type":"function","z":"437e4108076e5928","name":"Existing message","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":130,"y":1080,"wires":[["d208180966fc5f61"]]},{"id":"a07415564afbba11","type":"debug","z":"437e4108076e5928","name":"To the part of the flow that needs the battery temperature","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":1010,"wires":[]}]

```

But this is what it looks like.  
Given: the `function` node is what is sending the actual message and the `debug`node goes to the part of the flow which needs the battery temperature.

 ![Screenshot from 2022-01-10 20-49-47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/0363ebdeb02eb6c636d1a3cde6e364aceb091a0e.png)

Extra `change` nodes are shown to extract other information. Shown as example.

---

<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:** [10 January 2022 10:58 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/17 "2022-01-10T10:58:13Z")

</div>

When you say you want to join messages with the same topics, do you just mean that you want to ignore the repeat messages with the same topics?

If so then if you insert a Delay node configured like this it should do what you want

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/986f503f2ee7bd51ea72c313fe4a10f4f2c9a3cc.png)

That says that for each topic only allow one message every five seconds, and if two arrive within that time then discard the intermediate ones.

---

<div class="post-metadata">

**Author:** ![IAlves2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ialves2022/32/53866_2.png) [@IAlves2022](https://discourse.nodered.org/u/IAlves2022)\
**Post date:** [10 January 2022 11:42 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/18 "2022-01-10T11:42:14Z")

</div>

> [@Colin](#):
>
> If so then if you insert a Delay node configured like this it should do what you want

It's not what i want, because i still get Two responses for topic="cockpit, Two responses for topic="location", Two responses for topic="battery-status".

What i want is to merge both topic's with the same info, because i think this is a error on the node or in the Renault API, i don't need this two duplicated responses for topic!

---

<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:** [10 January 2022 12:07 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/19 "2022-01-10T12:07:23Z")

</div>

Please post a screenshot of how you have setup the Delay node, and feed the output of the delay node into a debug node and show us the repeated messages.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 January 2022 12:16 UTC](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367/20 "2022-01-10T12:16:32Z")

</div>

> [@IAlves2022](#):
>
> i still get Two responses for topic="cockpit, Two responses for topic="location", Two responses for topic="battery-status".
> 
> What i want is to merge both topic's with the same info

Use the Join node with the following settings  
Duplicate Topic message payloads should in theory be overwritten with the most recent Topic payload until all 3 unique Topic msgs arrive.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b0b65617856f3295714319baa6999db4854d514a.png)

[Next page](https://discourse.nodered.org/t/merge-different-messages-with-same-topic/56367.md?page=2)
