How to create payloads (strings merged/concatenated from array objects) from Excel data?

Hello everyone,
I am just getting back into Node-Red and I am trying to send MQTT payloads.

I have an Excel spreadsheet that contains one column with the topics and one column with the commands.
I have read the excel using node-red-contrib-spreadsheet-in. This gives me an array of objects containing the topics and one containing the commands.

But now I am at a loss how to join these together and create multiple MQTT messages.

So per row I would like to join column a and column b together and create one payload that is sent with MQTT out. Next row, next payload to be sent with the same MQTT out.

Is this possible somehow?

I thought I could simply join, but this seems to be incorrect (maybe because it is an array that I am trying to join?).
image

I did manage to split and then rejoin to an object.
image

But the order of the payloads is wrong and I want to join them to one string payload
image

Array1:

[{"Topic":"cmnd/tasmota_02B2D1/"},
{"Topic":"cmnd/tasmota_02A70A/"},
{"Topic":"cmnd/tasmota_228C3D/"}]

Array 2:

[{"ip":"Backlog IPAddress1 192.168.0.201; savedata"},
{"ip":"Backlog IPAddress1 192.168.0.202; savedata"},
{"ip":"Backlog IPAddress1 192.168.0.203; savedata"}]

Desired output

[{"cmnd/tasmota_02B2D1/Backlog IPAddress1 192.168.0.201; savedata"},
{"cmnd/tasmota_02A70A/Backlog IPAddress1 192.168.0.202; savedata"},
{"cmnd/tasmota_228C3D/Backlog IPAddress1 192.168.0.203; savedata"}]

Thank you very much for your help :slight_smile:
Alex

I think you may be better off trying to read the data in using the CSV node (save it as a CSV first)

it has the option to output a single message per row which you can then more easily either store as an array with objects of the two fields - or just do some string work as you read it in and build your mqtt messages straight off.

Craig

Thank you, @craigcurtin , for you suggestion :slight_smile:

I thought about that and had tried that before installing the excel package.
However, the problem is that CSV either uses comma or semicolon as delimiter, but both can appear as part of the payload. So it was a problem to then read it properly.

In addition, the Excel is the one I am working in and which holds a lot more, additional information. So ideally I can read directly from that.

Not sure waht your output is as it not an array of objects.

My best guess is it should be an array of strings.
Try this

[{"id":"5850ef51.1cf508","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic","payload":"[{\"Topic\":\"cmnd/tasmota_02B2D1/\"}, {\"Topic\":\"cmnd/tasmota_02A70A/\"}, {\"Topic\":\"cmnd/tasmota_228C3D/\"}]","payloadType":"json","x":120,"y":720,"wires":[["ed8e9f0d.d519c8"]]},{"id":"ed8e9f0d.d519c8","type":"join","z":"20bb0f7f9fab47a8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":240,"y":740,"wires":[["5a02da4f.5cf044"]]},{"id":"32979764.c051a8","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ip","payload":"[{\"ip\":\"Backlog IPAddress1 192.168.0.201; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.202; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.203; savedata\"}]","payloadType":"json","x":130,"y":760,"wires":[["ed8e9f0d.d519c8"]]},{"id":"5a02da4f.5cf044","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.topic#$i.($.Topic & $$.payload.ip[$i].ip)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":720,"wires":[["3e0ad2eb.1a47ae"]]},{"id":"3e0ad2eb.1a47ae","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":740,"wires":[]}]
1 Like

Sorry, I am not that familiar with the right syntax to have my above "Desired output" be an array of strings. I wrote it in the text and thought that that syntax was an array of strings.

Your code does exactly what I wanted!
And going through it, the join step was close to what I had but I could not figure out how to create a msg.topic from the "sheet-to-json-node". I thought that the "Topic" inside Array 1 would automatically be used. And "ip" inside array 2 would automatically be used.

So would it be best to add the topic using a change node? If so, is it possible to have the change node take the "Topic"/"ip" from the incoming array (apologies, would that be called the "variable" or what is the correct name for it; I am struggling a bit with all the different code languages and matching names :frowning: )? If it is called "variable", then maybe I do not need a change node and can directly use the join node with msg.variable as the key?

EDIT:
Just to be sure, since I am using sheet-to-json node, the data is a json. Is me calling it an array then still allowed or should I call my payload a json?

The data you showed is an array, not JSON. JSON would be a string representation of the data.

This post should help to clarify the difference between Javascript objects/arrays and JSON.

Does the debug node maybe show json as an array?
I am just asking because the node is called "sheet-to-json" and I would have thought that I am the only one who might get that wrong :smiley:

So, then my previous question about how to get my msg.topic into the payload before the joining is correct.
And I would need to get the topic from that payload array.

Update. I was able to add the topic to the payload using a change node.
Now the only "problem" I have is how to pass the value for the msg.topic to the change node from the input array.
So how can I automatically forward the word "topic" in this array to the change node? The entire array will only contain "topic" plus a value. Same for the array "ip".

[{"topic":"cmnd/tasmota_02B2D1"},{"topic":"cmnd/tasmota_02A70A"},{"topic":"cmnd/tasmota_228C3D"}]

This should create an array of objects topic, ip. It can then be split and moved to msg.topic and msg.payload, then sent to a mqtt node.

[{"id":"5850ef51.1cf508","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic","payload":"[{\"Topic\":\"cmnd/tasmota_02B2D1/\"}, {\"Topic\":\"cmnd/tasmota_02A70A/\"}, {\"Topic\":\"cmnd/tasmota_228C3D/\"}]","payloadType":"json","x":120,"y":720,"wires":[["ed8e9f0d.d519c8"]]},{"id":"ed8e9f0d.d519c8","type":"join","z":"20bb0f7f9fab47a8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":240,"y":740,"wires":[["5a02da4f.5cf044"]]},{"id":"32979764.c051a8","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ip","payload":"[{\"ip\":\"Backlog IPAddress1 192.168.0.201; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.202; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.203; savedata\"}]","payloadType":"json","x":130,"y":760,"wires":[["ed8e9f0d.d519c8"]]},{"id":"5a02da4f.5cf044","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.topic#$i.{\"topic\": $.Topic,\"ip\": $$.payload.ip[$i].ip}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":720,"wires":[["72094ad2.5a5cb4"]]},{"id":"72094ad2.5a5cb4","type":"split","z":"20bb0f7f9fab47a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":630,"y":720,"wires":[["fd5e355b.9034e"]]},{"id":"fd5e355b.9034e","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"move","p":"payload.topic","pt":"msg","to":"topic","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.ip","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":800,"wires":[["3e0ad2eb.1a47ae"]]},{"id":"3e0ad2eb.1a47ae","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":800,"wires":[]}]

Thank you for your suggestion.
The problem right now is that the msg.topic is being defined by your inject node.

I do not have a manual inject node.

So I am getting the payload from a node and this payload does not have a msg.topic defined. So I need to define the msg.topic from the incoming payload.

For this I need to use an expression in the change node "Set to" field. This expression would need to get the string "topic" from the incoming payload array.
If used on the ip array it would need to get the string "ip" from the incoming payload array.

Then add msg.topic's by adding change nodes after your incoming nodes or before your link out nodes.
e.g.

[{"id":"5850ef51.1cf508","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Topic\":\"cmnd/tasmota_02B2D1/\"}, {\"Topic\":\"cmnd/tasmota_02A70A/\"}, {\"Topic\":\"cmnd/tasmota_228C3D/\"}]","payloadType":"json","x":110,"y":660,"wires":[["f2a3ba99.c4e258"]]},{"id":"f2a3ba99.c4e258","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"topic","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":170,"y":700,"wires":[["ed8e9f0d.d519c8"]]},{"id":"ed8e9f0d.d519c8","type":"join","z":"20bb0f7f9fab47a8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":360,"y":740,"wires":[["5a02da4f.5cf044"]]},{"id":"4438e713.66cde8","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"ip","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":780,"wires":[["ed8e9f0d.d519c8"]]},{"id":"5a02da4f.5cf044","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.topic#$i.{\"topic\": $.Topic,\"ip\": $$.payload.ip[$i].ip}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":720,"wires":[["72094ad2.5a5cb4"]]},{"id":"32979764.c051a8","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"ip\":\"Backlog IPAddress1 192.168.0.201; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.202; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.203; savedata\"}]","payloadType":"json","x":110,"y":840,"wires":[["4438e713.66cde8"]]},{"id":"72094ad2.5a5cb4","type":"split","z":"20bb0f7f9fab47a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":750,"y":720,"wires":[["fd5e355b.9034e"]]},{"id":"fd5e355b.9034e","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"move","p":"payload.topic","pt":"msg","to":"topic","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.ip","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":800,"wires":[["3e0ad2eb.1a47ae"]]},{"id":"3e0ad2eb.1a47ae","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":800,"wires":[]}]

Or to do it dynamically from incoming payloads.

[{"id":"5850ef51.1cf508","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Topic\":\"cmnd/tasmota_02B2D1/\"}, {\"Topic\":\"cmnd/tasmota_02A70A/\"}, {\"Topic\":\"cmnd/tasmota_228C3D/\"}]","payloadType":"json","x":110,"y":660,"wires":[["f2a3ba99.c4e258"]]},{"id":"f2a3ba99.c4e258","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"$keys($$.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":170,"y":740,"wires":[["ed8e9f0d.d519c8"]]},{"id":"32979764.c051a8","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"ip\":\"Backlog IPAddress1 192.168.0.201; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.202; savedata\"}, {\"ip\":\"Backlog IPAddress1 192.168.0.203; savedata\"}]","payloadType":"json","x":110,"y":840,"wires":[["f2a3ba99.c4e258"]]},{"id":"ed8e9f0d.d519c8","type":"join","z":"20bb0f7f9fab47a8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":360,"y":740,"wires":[["5a02da4f.5cf044","645ceaca.bdb0ac"]]},{"id":"5a02da4f.5cf044","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.Topic#$i.{\"topic\": $.Topic,\"ip\": $$.payload.ip[$i].ip}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":720,"wires":[["72094ad2.5a5cb4"]]},{"id":"645ceaca.bdb0ac","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":620,"wires":[]},{"id":"72094ad2.5a5cb4","type":"split","z":"20bb0f7f9fab47a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":750,"y":720,"wires":[["fd5e355b.9034e"]]},{"id":"fd5e355b.9034e","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"move","p":"payload.topic","pt":"msg","to":"topic","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.ip","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":800,"wires":[["3e0ad2eb.1a47ae"]]},{"id":"3e0ad2eb.1a47ae","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":800,"wires":[]}]

That was exactly what I was doing but I was missing that one piece of the puzzle:

$keys($$.payload)

This I simply could not figure out! Thank you so much!!!!

So, for my understanding
$keys is the key that I am looking for and ($$.payload) is the place where it can be found?

So, if I wanted to e.g. convert only one array of objects to strings (like you did after joining the two payloads but with only one incoming payload), would this be correct:
msg.payload is an array with msg.topic being "ip". I want to convert all objects in msg.payload to strings.
So it would be a change node with "Set msg.payload to" expression $$.payload.ip[$i].ip
?

So if $keys($$.payload)gives me the key of an array. What would be the equivalent to get the value? Because it is not $values($$.payload) or $payloads($$.payload) :frowning:

No $keys() gives an array of all keys of a object,. Unless only one is returned. To force that to an array, [$keys()] would `force a single result to a single array, it would not affect a array with multiple values.

To get values of payload
$$.payload.*

Or if you are in map of an array of objects the context in loop is $
$$.payload.($.property_name)

$.* would return an array of all values from the object, in a map of an array of objects.

1 Like

I do not know why this is proving to be so tricky. I feel like I am trying to achieve simple things and find it unusually difficult to find the help in the documentation.
Is there a Node-RED discord channel that I can ask questions?

I want to now add some text to each object in the array.

Maaning, I have an array and I changed the topic to match the payload. But I would like to change it to the payload plus a string (same string for each object in the array).
image

But this gives me
["cmnd/tasmota_02A70A/","cmnd/tasmota_45147C/"]Backlog
I see what is happening. I am not adding to each object to the entire array. But I do not understand why and how to fix it :frowning:

I also tried the Array Functions but they don't fit my need. Append only adds an entry to the array instead of appending each entry with the string.

$$.payload.* gives an array of values, I'm guessing that that payload is an object of strings. Please supply a copyable sample of input data in future, it's very helpful.
$$.payload.*.($ & "Backlog") will loop through the array of strings and append "Backlog"
e.g.

[{"id":"48319116.f1a9e","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"blah\":\"123\",\"blur\":\"456\"}","payloadType":"json","x":90,"y":1440,"wires":[["f2381f33.2e6678"]]},{"id":"f2381f33.2e6678","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.*.($ & \"Backlog\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1540,"wires":[["49cf4942.4c7ec"]]},{"id":"49cf4942.4c7ec","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":1600,"wires":[]}]

That worked perfectly.
Now maybe I am doing too many conversions. Now all arrays contain strings instead of objects (if I am not getting the nomenclature wrong). The mqtt out node is now throwing an error. Is this because I now have arrays of strings or have I got something else wrong. I did not see in the documentation that arrays of strings were not allowed for mqtt out nodes. It actually expects strings, if I am not mistaken.

I will try to attach everything needed.

[{"id":"fe76f7928e585317","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"86c2199d431df0bd","type":"change","z":"fe76f7928e585317","name":"Change topic to payload and add 'Backlog'","rules":[{"t":"set","p":"topic","pt":"msg","to":"$$.payload.*.($ & \"Backlog\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":220,"wires":[["a00f3bf2c3a73970","4d4f3e342c1bdf41"]]},{"id":"a00f3bf2c3a73970","type":"mqtt out","z":"fe76f7928e585317","name":"MQTT settings","topic":"","qos":"2","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"0d7f426189a0c8d3","x":950,"y":460,"wires":[]},{"id":"377daf87819fe500","type":"change","z":"fe76f7928e585317","name":"Change topic to payload and add 'Backlog0'","rules":[{"t":"set","p":"topic","pt":"msg","to":"$$.payload.*.($ & \"Backlog0\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":280,"wires":[["a00f3bf2c3a73970","4d4f3e342c1bdf41"]]},{"id":"08d4ae2e02d224c1","type":"change","z":"fe76f7928e585317","name":"Change array to string","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.*.$","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":460,"wires":[["a00f3bf2c3a73970","def6f99c5c87eefc"]]},{"id":"1a54e119f462f5c5","type":"inject","z":"fe76f7928e585317","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"topic\":\"cmnd/tasmota_02A70A/\"},{\"topic\":\"cmnd/tasmota_45147C/\"}]","payloadType":"json","x":200,"y":220,"wires":[["86c2199d431df0bd","377daf87819fe500"]]},{"id":"52547f50b505e42a","type":"inject","z":"fe76f7928e585317","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"settings\":\"SO21 1; Teleperiod 3600; WattRes 1; PowerOnState 0; Timezone 99; SerialLog 0; MqttHost 192.168.0.2; MqttUser mqtt; MqttPassword MQ; savedata\"},{\"settings\":\"SO21 1; Teleperiod 3600; WattRes 1; PowerOnState 0; Timezone 99; SerialLog 0; MqttHost 192.168.0.2; MqttUser mqtt; MqttPassword MQ; savedata\"}]","payloadType":"json","x":210,"y":460,"wires":[["08d4ae2e02d224c1"]]},{"id":"4d4f3e342c1bdf41","type":"debug","z":"fe76f7928e585317","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":250,"wires":[]},{"id":"def6f99c5c87eefc","type":"debug","z":"fe76f7928e585317","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]},{"id":"0d7f426189a0c8d3","type":"mqtt-broker","name":"MQTT Home Assistant","broker":"192.168.0.2","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

P.S.:
So, in my flow, both "topic" and "settings" are sent simultaneously. But here in this example for you they have separate inject nodes.

Not moving things at correct times.
Try this

[{"id":"1a54e119f462f5c5","type":"inject","z":"fe76f7928e585317","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"topic\":\"cmnd/tasmota_02A70A/\"},{\"topic\":\"cmnd/tasmota_45147C/\"}]","payloadType":"json","x":210,"y":300,"wires":[["bda4e22f.ad16a"]]},{"id":"bda4e22f.ad16a","type":"change","z":"fe76f7928e585317","name":"set topics and create arrays from objects","rules":[{"t":"set","p":"topic","pt":"msg","to":"$keys($$.payload[0])","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$$.payload.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":360,"wires":[["1627204c.9cb928"]]},{"id":"52547f50b505e42a","type":"inject","z":"fe76f7928e585317","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"settings\":\"SO21 1; Teleperiod 3600; WattRes 1; PowerOnState 0; Timezone 99; SerialLog 0; MqttHost 192.168.0.2; MqttUser mqtt; MqttPassword MQ; savedata\"},{\"settings\":\"SO21 1; Teleperiod 3600; WattRes 1; PowerOnState 0; Timezone 99; SerialLog 0; MqttHost 192.168.0.2; MqttUser mqtt; MqttPassword MQ; savedata\"}]","payloadType":"json","x":210,"y":460,"wires":[["bda4e22f.ad16a"]]},{"id":"1627204c.9cb928","type":"join","z":"fe76f7928e585317","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":360,"wires":[["def6f99c5c87eefc","08d4ae2e02d224c1","8eb87f19.ad2958"]]},{"id":"def6f99c5c87eefc","type":"debug","z":"fe76f7928e585317","name":"debug 6","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":360,"wires":[]},{"id":"08d4ae2e02d224c1","type":"change","z":"fe76f7928e585317","name":"create array of objects and set topic","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.topic#$i.{\"topic\": $ & \"Backlog\", \"settings\": $$.payload.settings[$i]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":300,"wires":[["468c27ce.f9c9d"]]},{"id":"8eb87f19.ad2958","type":"change","z":"fe76f7928e585317","name":"as above but backlog0","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.topic#$i.{\"topic\": $ & \"Backlog0\", \"settings\": $$.payload.settings[$i]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":420,"wires":[["468c27ce.f9c9d"]]},{"id":"468c27ce.f9c9d","type":"split","z":"fe76f7928e585317","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1050,"y":340,"wires":[["c4e9a2f6.1a5c9"]]},{"id":"c4e9a2f6.1a5c9","type":"change","z":"fe76f7928e585317","name":"move payloads to topic and payload","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload.topic","tot":"msg"},{"t":"move","p":"payload.settings","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":340,"wires":[["51ebc85a.412ae"]]},{"id":"51ebc85a.412ae","type":"delay","z":"fe76f7928e585317","name":"rate limit send as to not flood","pauseType":"rate","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1670,"y":340,"wires":[["da9903a0.63a26"]]},{"id":"da9903a0.63a26","type":"debug","z":"fe76f7928e585317","name":"mqtt","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1530,"y":420,"wires":[]}]

Also in a change node, rules run in order top to bottom. Once a rule has run, all rules below will rely on the rule above not deleting/moving/etc properties that the below rules rely on.
You can up the rate limit to what ever your system will take, it's there just as a precaution.

1 Like

Wow, this is interesting. I thought that my mistake was maybe just that I still had a payload in my sub-flow of the topic.

I will need to check why this "complicated" approach is needed. Because you had to change, join, change, split, change and then rate limit. So it seems not only a question of timing :frowning:

Not timing, moving things at correct time/order
1st you need to create topics and move the object values into an array.
2nd the 2 simultaneous messages need to be join.
3rd The now join messages can be manipulated into an array of objects, each object containing the values topic and settings, from the corresponding array indices.
4th The new array can be split.
5th payload.topic and payload.settings from the splits of the array then need to be moved to topic and payload.

1 Like