# Sum up three outputs from mqtt

**URL:** <https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991>\
**Category:** General\
**Created:** [4 August 2019 10:53 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991 "2019-08-04T10:53:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [4 August 2019 10:53 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/1 "2019-08-04T10:53:53Z")

</div>

Hi i think the solution is simple but i get stuck with adding up some values.  
I am a total N00b so please be patient.  
Situation:

I get data from Domoticz via Mqtt. (works)  
I split the messages to get only the data i need (from 3 sensors) (works)  
Now the difficoult part. The output is like this:

{"Battery":255,"RSSI":12,"description":"","dtype":"Usage","id":"0000000","idx":25,"name":"Delivery L3","nvalue":0,"stype":"Electric","svalue1":"1710.0","unit":6}  
{"Battery":255,"RSSI":12,"description":"","dtype":"Usage","id":"0000000","idx":24,"name":"Delivery L2","nvalue":0,"stype":"Electric","svalue1":"1443.0","unit":5}  
{"Battery":255,"RSSI":12,"description":"","dtype":"Usage","id":"0000000","idx":23,"name":"Delivery L1","nvalue":0,"stype":"Electric","svalue1":"1726.0","unit":4}

Now i want to ad the three values from 'svalue1' together. In this case the result would be 1710+1443+1726 = 4879

Fist i tried to create a new function and retrack the svalues.  
then is have this result.  
{"n1":"1791.0"}  
{"n2":"1637.0"}  
{"n3":"1826.0"}

But now i am stuck with a nwe function to add up n1+n2+n3

I also tried the join node but that is giving me nothing at all.. ☹

This is what is have.  
[{"id":"40635ad8.24fde4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"78374b80.4fda64","type":"debug","z":"40635ad8.24fde4","name":"uitkomst","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":320,"y":40,"wires":},{"id":"52e4c849.3b2da8","type":"mqtt in","z":"40635ad8.24fde4","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"b008ef44.96838","x":110,"y":60,"wires":[["78374b80.4fda64","136268c3.04fb97"]]},{"id":"c6bf5e01.5ef9e","type":"switch","z":"40635ad8.24fde4","name":"Delivery\_P1","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"25","vt":"str"},{"t":"eq","v":"24","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":270,"y":200,"wires":[["b5470ea6.8e6db","77d414ed.945cdc","3dc25f8f.4fa3"],["b5470ea6.8e6db","77d414ed.945cdc","a0b0f3c6.09f3f"],["b5470ea6.8e6db","77d414ed.945cdc","1028c61c.0d6c5a"]]},{"id":"1028c61c.0d6c5a","type":"function","z":"40635ad8.24fde4","name":"IDX25","func":"msg.payload = {\n "n3":msg.payload.svalue1,\n};\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":140,"wires":[["19eb6d4.7f9ab93","27b742d8.030f7e"]]},{"id":"27b742d8.030f7e","type":"debug","z":"40635ad8.24fde4","name":"123","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":220,"wires":},{"id":"a0b0f3c6.09f3f","type":"function","z":"40635ad8.24fde4","name":"IDX24","func":"msg.payload = {\n "n2":msg.payload.svalue1,\n};\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":100,"wires":[["19eb6d4.7f9ab93","27b742d8.030f7e"]]},{"id":"19eb6d4.7f9ab93","type":"function","z":"40635ad8.24fde4","name":"optellen","func":"msg.payload = \n\nmsg.payload.n1 + msg.payload.n2 + msg.payload.n3;\n\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":80,"wires":[]},{"id":"6c33bb30.de8c24","type":"debug","z":"40635ad8.24fde4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":280,"wires":},{"id":"3dc25f8f.4fa3","type":"function","z":"40635ad8.24fde4","name":"IDX23","func":"msg.payload = {\n "n1":msg.payload.svalue1,\n};\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":60,"wires":[["19eb6d4.7f9ab93","27b742d8.030f7e"]]},{"id":"b5470ea6.8e6db","type":"join","z":"40635ad8.24fde4","name":"opgeteld","mode":"custom","build":"object","property":"","propertyType":"full","key":"payload.svalue1","joiner":"\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":520,"y":260,"wires":[["6c33bb30.de8c24"]]},{"id":"77d414ed.945cdc","type":"debug","z":"40635ad8.24fde4","name":"#1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":500,"y":320,"wires":},{"id":"136268c3.04fb97","type":"json","z":"40635ad8.24fde4","name":"","property":"payload","action":"","pretty":false,"x":120,"y":160,"wires":[["c6bf5e01.5ef9e"]]},{"id":"b008ef44.96838","type":"mqtt-broker","z":"","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

---

<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:** [4 August 2019 11:07 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/2 "2019-08-04T11:07:55Z")

</div>

> [@R0yk3](#):
>
> I split the messages to get only the data i need (from 3 sensors)

Do you mean that you are starting with one message from MQTT, then splitting that into three messages and then trying to put it back together to add up the bits you need? If so then don't do the split, just add them up from the original message direct from mqtt. Post what that message contains when viewed in a debug node.

---

<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:** [4 August 2019 11:09 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/3 "2019-08-04T11:09:15Z")

</div>

Also see this post on how to share code or flow so that it is importable

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [4 August 2019 11:14 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/4 "2019-08-04T11:14:22Z")

</div>

No,  
From mqtt i get loads of messages from all domoticz devices. From all these messages i filter out three (in this case idx23, idx24 , idx25).  
Then i want to add up the svalue1 from these three nodes.

---

<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:** [4 August 2019 11:15 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/5 "2019-08-04T11:15:45Z")

</div>

OK, then you can use a Join node. Make sure the three messages have different topics and set the Join node to Manual, key/value pairs, using topic as key, and expecting three messages.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 August 2019 11:23 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/6 "2019-08-04T11:23:34Z")

</div>

Been asked soooo many times. A simple search would uncover many threads.

This one might give you a head start....

> [@Summing all msg.payload in a month](https://discourse.nodered.org/t/summing-all-msg-payload-in-a-month/13723/16):
>
> [image] Thank you. It works! slight_smile

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 09:18 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/7 "2019-08-05T09:18:03Z")

</div>

> [@Colin](#):
>
> topic as key

I think there is my problem?  
Following the explanation from the other article. using ,"stype":"Electric", as topic. i get the error "message missing key property 'msg.stype' - cannot ad to object"  
Sorry cannot post image couse i'm working on my phone.

---

<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:** [5 August 2019 10:04 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/8 "2019-08-05T10:04:49Z")

</div>

I don't understand what you mean by

> [@R0yk3](#):
>
> using ,"stype":"Electric", as topic

Do you mean you have specified `stype` as the _key_? If so then the message must have a property stype, which it does not, according to the error. The most common way is to specify `topic` as the key and then put a value in the topic that identifies the message contents. If that doesn't make sense then tell us what it is that identifies which message is which.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 11:12 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/9 "2019-08-05T11:12:42Z")

</div>

This is one output of three: see first post. This is the debug message from the split node.  
{"  
Battery":255,"  
RSSI":12,"  
description":"","  
dtype":"Usage","  
id":"0000000","  
idx":25,"  
name":"Delivery L3","  
nvalue":0,"  
stype":"Electric","  
svalue1":"1710.0","  
unit":6:  
}  
IDX is the unique value, but name is also unique.  
But using any value as key i get the error??

---

<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:** [5 August 2019 11:24 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/11 "2019-08-05T11:24:27Z")

</div>

Set the debug node to Show Complete Message and show us what it says.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 11:29 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/12 "2019-08-05T11:29:01Z")

</div>

I wil do that at home. I'm now at work and the office firewall does not allow me to connect to my NodeRed. And at my phone it is not working well.

---

<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:** [5 August 2019 12:28 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/13 "2019-08-05T12:28:23Z")

</div>

I suspect that the data you posted is in the payload, in which case you need something like `msg.payload.idx` or `msg.payload.name` as the key in the Join node.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 12:51 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/14 "2019-08-05T12:51:34Z")

</div>

If i do that msg.payload.idx i get no debug message at all.

---

<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:** [5 August 2019 12:56 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/15 "2019-08-05T12:56:45Z")

</div>

Post an image showing how you have configured the Join node.  
Also the debug message with Show Complete as previously discussed.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 August 2019 16:11 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/16 "2019-08-05T16:11:16Z")

</div>

Here is my proposed solution based on the data in the first post.

Join the three chunks together  
 ![26%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/83434167afe19a682ca8167f71a69c542eaf1f1f.png)

In a change node, use jsonata to  
 ![12%20PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/acb3a2e7d5ae633e2443474bd1decbb15b6432b3.png)  
1 - change svalue1 from a string to a number  
`payload ~> | $ | { "svalue1": $number(svalue1) } |`  
2 - sum up all occurances of svalue1  
`$sum(payload.svalue1)`

Here is the sample solution flow:

```auto
[{"id":"61bbc058.4acfa","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"22e8ad89.490e9a","type":"comment","z":"61bbc058.4acfa","name":"using 2 jsonata statements: (1) change all svalue1's to number (2) sum(svalue1)","info":"","x":560,"y":260,"wires":[]},{"id":"b625917b.a88948","type":"inject","z":"61bbc058.4acfa","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":25,\"name\":\"Delivery L3\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"1710.0\",\"unit\":6}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":100,"wires":[["4ea2092f.458a68","836cc330.865038","daa1d47.dfc32a8"]]},{"id":"daa1d47.dfc32a8","type":"change","z":"61bbc058.4acfa","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":25,\"name\":\"Delivery L3\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"1710.0\",\"unit\":6}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":60,"wires":[["15971af0.23c13d"]]},{"id":"836cc330.865038","type":"change","z":"61bbc058.4acfa","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":24,\"name\":\"Delivery L2\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"1443.0\",\"unit\":5}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":120,"wires":[["15971af0.23c13d"]]},{"id":"4ea2092f.458a68","type":"change","z":"61bbc058.4acfa","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":23,\"name\":\"Delivery L1\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"1726.0\",\"unit\":4}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":180,"wires":[["15971af0.23c13d"]]},{"id":"15971af0.23c13d","type":"join","z":"61bbc058.4acfa","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":120,"wires":[["1e092022.9a923"]]},{"id":"1e092022.9a923","type":"change","z":"61bbc058.4acfa","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload ~> | $ | { \"svalue1\": $number(svalue1) } |\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$sum(payload.svalue1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":320,"wires":[["8f328c43.8a085"]]},{"id":"8f328c43.8a085","type":"debug","z":"61bbc058.4acfa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":380,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 17:48 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/17 "2019-08-05T17:48:42Z")

</div>

This is what i have now. And no messages in the debug window.  
[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/56f833a1bcb376c7ac116c703752725156cea66f.png)](https://i.imgur.com/mS9iOXY.png)

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 18:34 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/18 "2019-08-05T18:34:21Z")

</div>

Thank you this works.  
You use the join node different. Why?  
What was wrong with the approach of manual join?  
Thanks in advance, i wil reuse this a lot. 😃

This is my result. I gues some optimisation from the string to number back to string again? Or is it not possible to add up a string?

```auto
[{"id":"b34e1f67.0949d","type":"comment","z":"e0b44d74.cf477","name":"using 2 jsonata statements: (1) change all svalue1's to number (2) sum(svalue1)","info":"","x":780,"y":60,"wires":[]},{"id":"44c403d4.0fbabc","type":"join","z":"e0b44d74.cf477","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":530,"y":140,"wires":[["b0c152b3.ace7a"]]},{"id":"b0c152b3.ace7a","type":"change","z":"e0b44d74.cf477","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload ~> | $ | { \"svalue1\": $number(svalue1) } |\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$sum(payload.svalue1)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":140,"wires":[["eeaac0cc.e1a51"]]},{"id":"ac6ac279.5615d","type":"mqtt in","z":"e0b44d74.cf477","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"b008ef44.96838","x":70,"y":140,"wires":[["4cfb6221.8f05dc"]]},{"id":"4cfb6221.8f05dc","type":"json","z":"e0b44d74.cf477","name":"","property":"payload","action":"","pretty":false,"x":210,"y":140,"wires":[["f61d7c2d.233ad"]]},{"id":"f61d7c2d.233ad","type":"switch","z":"e0b44d74.cf477","name":"Delivery_P1","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"25","vt":"str"},{"t":"eq","v":"24","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":350,"y":140,"wires":[["44c403d4.0fbabc"],["44c403d4.0fbabc"],["44c403d4.0fbabc"]]},{"id":"eeaac0cc.e1a51","type":"function","z":"e0b44d74.cf477","name":"teruglevering","func":"msg.payload = {\n \"idx\": 298,\n \"nvalue\": 0,\n \"svalue\": msg.payload.toString(),\n};\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":140,"wires":[["211ec0e3.71a5a"]]},{"id":"b0e29ea5.57ba7","type":"debug","z":"e0b44d74.cf477","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":100,"wires":[]},{"id":"211ec0e3.71a5a","type":"json","z":"e0b44d74.cf477","name":"","property":"payload","action":"","pretty":false,"x":1050,"y":140,"wires":[["b0b1d0b6.ed5fc","b0e29ea5.57ba7"]]},{"id":"b0b1d0b6.ed5fc","type":"mqtt out","z":"e0b44d74.cf477","name":"Send to domoticz","topic":"domoticz/in","qos":"","retain":"","broker":"b008ef44.96838","x":1230,"y":140,"wires":[]},{"id":"b008ef44.96838","type":"mqtt-broker","z":"","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bbe70385a73459353dbf441e7018835a7ebe1ca7.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 August 2019 19:16 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/19 "2019-08-05T19:16:03Z")

</div>

> You use the join node different. Why?  
> What was wrong with the approach of manual join?  
> I used the join just to put the three objects together into one so I could apply the jsonata to it and do the summing.

> is it not possible to add up a string?  
> using the plus sign on two numbers that are stored as strings will concatinate them not add them...because they are strings not numbers 🙂

---

<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:** [5 August 2019 19:37 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/20 "2019-08-05T19:37:20Z")

</div>

The reason your Join node did not work is because you had not told it when to send the message on. You should have told it to send it after three message parts.  
When I said to set the debug node to show the complete message I meant a debug node showing what was going _into_ the Join node. However if you have it all working now then that is ok, there are often multiple ways of solving a problem. The more people you have contributing suggestions the more different solutions you are likely to get.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [5 August 2019 19:51 UTC](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991/21 "2019-08-05T19:51:48Z")

</div>

Thank you. I'm stil going to try my first thoughts.  
Now i have at least an outcome. But nothing is joined? after three inputs, te last input is shown.

```auto
[{"id":"78374b80.4fda64","type":"debug","z":"40635ad8.24fde4","name":"uitkomst","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":760,"y":440,"wires":[]},{"id":"c6bf5e01.5ef9e","type":"switch","z":"40635ad8.24fde4","name":"Delivery_P1","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"25","vt":"str"},{"t":"eq","v":"24","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":350,"y":440,"wires":[["b5470ea6.8e6db","77d414ed.945cdc"],["b5470ea6.8e6db","77d414ed.945cdc"],["b5470ea6.8e6db","77d414ed.945cdc"]]},{"id":"b5470ea6.8e6db","type":"join","z":"40635ad8.24fde4","name":"opgeteld","mode":"custom","build":"object","property":"svalue1","propertyType":"msg","key":"payload.name","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":560,"y":440,"wires":[["78374b80.4fda64"]]},{"id":"77d414ed.945cdc","type":"debug","z":"40635ad8.24fde4","name":"#1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":530,"y":340,"wires":[]},{"id":"99c2cc0a.073b4","type":"inject","z":"40635ad8.24fde4","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":25,\"name\":\"Delivery L3\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"25.0\",\"unit\":6}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":400,"wires":[["c6bf5e01.5ef9e"]]},{"id":"96775b00.c3d8d8","type":"inject","z":"40635ad8.24fde4","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":23,\"name\":\"Delivery L1\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"23.0\",\"unit\":4}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":480,"wires":[["c6bf5e01.5ef9e"]]},{"id":"42bffe0e.ce61c","type":"inject","z":"40635ad8.24fde4","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"\",\"dtype\":\"Usage\",\"id\":\"0000000\",\"idx\":24,\"name\":\"Delivery L2\",\"nvalue\":0,\"stype\":\"Electric\",\"svalue1\":\"24.0\",\"unit\":5}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":440,"wires":[["c6bf5e01.5ef9e"]]}]

```

[Next page](https://discourse.nodered.org/t/sum-up-three-outputs-from-mqtt/13991.md?page=2)
