Merge different messages with same TOPIC

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.

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.

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.

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.

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 sorry i didin't get what node you want me to open and take screen shot.

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

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?

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

And the flow

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

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?

Ok i'll try the thing you said.

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:

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!

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.

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.

Can you please explain this part?

So i've manage this solution:

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

Thank you for the replys

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.

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.

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

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.

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)

[{"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 debugnode goes to the part of the flow which needs the battery temperature.

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

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

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.

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!

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.

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