Join, Getting order incorrect sometimes

Hi,

I have several payloads I need to joint to form a string, I have a very long winded way and it is cumbersome, how do I stream line it?

image

As sometimes the order gets muddled up.

image

image
image

You really need to share your flow for a decent answer.

[{"id":"35b73a03.2ff426","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"54be287.c469cd8","type":"inject","z":"35b73a03.2ff426","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"0 6-17 * * *","once":false,"onceDelay":0.1,"x":180,"y":220,"wires":[["199cbab1.1f3665"]]},{"id":"f5af2bc6.2c73d8","type":"change","z":"35b73a03.2ff426","name":"","rules":[{"t":"set","p":"number","pt":"msg","to":"payload","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":560,"wires":[["fe5ea807.1433b8"]]},{"id":"255ebbbb.6f8da4","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-000006c7f31d","timer":"21600","repeat":true,"x":400,"y":460,"wires":[["54faa4ed.25266c","2bce2f69.7248"]]},{"id":"fe5ea807.1433b8","type":"debug","z":"35b73a03.2ff426","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1020,"y":680,"wires":[]},{"id":"f510b7f1.f10d38","type":"function","z":"35b73a03.2ff426","name":"Temp 1: Grey\"","func":"msg.payload = \"Temp 1: Grey: \";\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":340,"wires":[["1b9edb33.6c7945","54faa4ed.25266c"]]},{"id":"1b9edb33.6c7945","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":400,"wires":[["255ebbbb.6f8da4"]]},{"id":"c1db60d7.a07df","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":380,"y":640,"wires":[["e4051a8a.06c118"]]},{"id":"e4051a8a.06c118","type":"function","z":"35b73a03.2ff426","name":"Temp 2: Black","func":"msg.payload = \"Temp 2: Black: \";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":700,"wires":[["f64f1208.997de","d4ee2a3d.279998"]]},{"id":"84499cc8.162ed","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-02131a935faa","timer":"21600","repeat":false,"x":360,"y":820,"wires":[["d4ee2a3d.279998","a8972d7f.a2c8e"]]},{"id":"6c9f9474.6cad0c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":660,"y":1220,"wires":[["52781460.83607c"]]},{"id":"c7bc6a6a.292038","type":"sensor-ds18b20","z":"35b73a03.2ff426","name":"","topic":"","sensorid":"28-000006c88310","timer":"21600","repeat":false,"x":340,"y":1180,"wires":[["70b6d292.630dbc","6c9f9474.6cad0c"]]},{"id":"b0b3d691.a15bc8","type":"function","z":"35b73a03.2ff426","name":"Temp 2: Grey 2\"","func":"msg.payload = \"Temp 2: Grey 2: \";\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":1060,"wires":[["caa34f08.5e67","6c9f9474.6cad0c"]]},{"id":"a8972d7f.a2c8e","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":880,"wires":[["3b8746a5.4d84aa"]]},{"id":"f64f1208.997de","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":360,"y":760,"wires":[["84499cc8.162ed"]]},{"id":"caa34f08.5e67","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1120,"wires":[["c7bc6a6a.292038"]]},{"id":"d9d6043c.3b8f88","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":580,"wires":[["54faa4ed.25266c","c1db60d7.a07df"]]},{"id":"3b8746a5.4d84aa","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":940,"wires":[["d4ee2a3d.279998","a788e2b8.5cacc"]]},{"id":"107a959a.828eda","type":"function","z":"35b73a03.2ff426","name":"°C","func":"msg.payload = \" °C\";\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":1300,"wires":[["6c9f9474.6cad0c"]]},{"id":"199cbab1.1f3665","type":"function","z":"35b73a03.2ff426","name":"Office","func":"msg.payload = \"Office\";\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":220,"wires":[["11cb63cd.4c287c","52781460.83607c"]]},{"id":"54faa4ed.25266c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":650,"y":500,"wires":[["52781460.83607c"]]},{"id":"d4ee2a3d.279998","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":630,"y":860,"wires":[["52781460.83607c"]]},{"id":"52781460.83607c","type":"join","z":"35b73a03.2ff426","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"Office","reduceInitType":"str","reduceFixup":"","x":830,"y":460,"wires":[["f5af2bc6.2c73d8"]]},{"id":"11cb63cd.4c287c","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":280,"wires":[["f510b7f1.f10d38"]]},{"id":"2bce2f69.7248","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":520,"wires":[["d9d6043c.3b8f88"]]},{"id":"70b6d292.630dbc","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1240,"wires":[["107a959a.828eda"]]},{"id":"a788e2b8.5cacc","type":"delay","z":"35b73a03.2ff426","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1000,"wires":[["b0b3d691.a15bc8"]]}]

Any body perhaps have some ideas for me as the join don't always get the order correct.

The messages below are all from the flow in my first post, the order jumps around.

image

What is the end result you are tying to achieve?

I always want it to be in the same order, but it's not always.

This is what I want image

Have you read this (https://nodered.org/docs/user-guide/messages#message-sequences) in the documentation?

Also, why not just build the message as you go along?

Hi @ScheepersJohan

Are the Delay nodes there just to try to get the ordering right? If so, you don't need them and you can
simplify the flow considerably.

I would do something like the following: (the flow json for this is shared at the end of this post)

The three DS18b20 nodes on the left are placeholders for your real sensor-ds18b20 that I don't have installed locally.

The flow gets a reading from the first sensor node, then the change node moves its value to msg.temp1. It then gets the next reading and then moves that to msg.temp2 and then the third reading is captured and moved to msg.temp3. The message then passes to the Template node, that contains the template:

Office
Temp1: Grey: {{temp1}} °C
Temp2: Black: {{temp2}} °C
Temp2: Grey 2: {{temp3}} °C

The other piece of feedback is your flow is using a lot of Function nodes just to set msg.payload to a fixed String value. I'd recommend getting into the habit of using the Change node for that sort of thing.

Here's the JSON:

[{"id":"a9963da1.09f22","type":"inject","z":"c3c543df.668ac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"0 6-17 * * *","once":false,"onceDelay":0.1,"x":330,"y":60,"wires":[["ba8dfd35.9e54d"]]},{"id":"ba8dfd35.9e54d","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":60,"wires":[["88dc9348.e89ce"]]},{"id":"88dc9348.e89ce","type":"change","z":"c3c543df.668ac","name":"Move payload to temp1","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":60,"wires":[["b21ddcf4.09ad6"]]},{"id":"b21ddcf4.09ad6","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":120,"wires":[["4b2bac19.f93eb4"]]},{"id":"4b2bac19.f93eb4","type":"change","z":"c3c543df.668ac","name":"Move payload to temp2","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":120,"wires":[["4445bc16.cfa924"]]},{"id":"4445bc16.cfa924","type":"function","z":"c3c543df.668ac","name":"DS18b20","func":"\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":180,"wires":[["fd51b008.d226f"]]},{"id":"fd51b008.d226f","type":"change","z":"c3c543df.668ac","name":"Move payload to temp3","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp3","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":180,"wires":[["84cb690e.2ca0d8"]]},{"id":"84cb690e.2ca0d8","type":"template","z":"c3c543df.668ac","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Office\nTemp1: Grey: {{temp1}} °C\nTemp2: Black: {{temp2}} °C\nTemp2: Grey 2: {{temp3}} °C","output":"str","x":980,"y":180,"wires":[["95520998.2e2328"]]},{"id":"95520998.2e2328","type":"debug","z":"c3c543df.668ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1150,"y":180,"wires":[]}]
1 Like