# Trying to add 3 incoming msg.payload.value - and failing

**URL:** <https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620>\
**Category:** General\
**Created:** [2 December 2022 16:36 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620 "2022-12-02T16:36:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [2 December 2022 16:36 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/1 "2022-12-02T16:36:14Z")

</div>

Looks so easy but failing to do it.  
I have 3 nodes sending values, all I am trying to do is adding them up so I end up with a payload of the sum of the 3 msg.payload.value(s)  
I thought it was easiest with a function node... problem is the function node sends 3 messages. As I am not sending asyncroneous, I thought it would wait until it has all 3 values... obviously that is not the case  
I am also most likely overcomplicating things..

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/876fb30a4f3b024e35dd3905874a9a8a09856277.png)

```auto
var boiler = context.get('boiler') || 0;
var sink = context.get('sink') || 0;
var micro = context.get('micro') || 0;

var nodeName;
nodeName = msg.nodeName

if (nodeName == "Watts RGBW boiler") {
    boiler = msg.payload.value
}

if (nodeName == "Watts RGBW sink") {
    sink = msg.payload.value
}

if (nodeName == "Watts RGBW micro") {
    micro = msg.payload.value
}

msg.payload.value = sink + boiler + micro

context.set("boiler", 0)
context.set("micro", 0)
context.set("sink", 0)

return msg;

```

---

<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:** [2 December 2022 16:40 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/2 "2022-12-02T16:40:46Z")

</div>

One of the most important premises in node-red is that `msg`s from different wires travel individually (asynchronously) meaning they will NEVER arrive at the function node at the same time.

You have 2 choices here...

1. use a join node (details below)
2. put your nodes in series and move the payload to other parts of the `msg` object

* * *

#### Option 1:

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

* * *

#### Option 2:

inject -\> boiler -\> change node (move msg.payload to msg.boiler) --\>  
sink -\> change node (move msg.payload to msg.sink) --\>  
micro -\> change node (move msg.payload to msg.micro) --\> Function node  
(you can now get msg.boiler and msg.sink and msg.micro in the function node)

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [2 December 2022 17:14 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/3 "2022-12-02T17:14:09Z")

</div>

OK I thought that might be the case. So if I go the join node way I would have a change node after each input to give them a topic boiler, topic micro etc. then join, then going to the function node.  
Or put them all in line with change nodes which seems the easier way. I'll give that a try

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2022 17:22 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/4 "2022-12-02T17:22:45Z")

</div>

If you want to do it in a function something like this should work.

```auto
let sync = context.get('sync') || {};
const nodeName = msg.nodeName;
sync[nodeName] = msg.payload.value;
const sync_array = Object.values(sync);

if (sync_array.length >= 3) {
    msg.payload = sync_array.reduce((acc, num) => acc+num, 0)
    sync = undefined;
}else{
    msg = null;
}

context.set("sync", sync)
return msg;

```

e.g.

```auto
[{"id":"9d658e1986a3ca06","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":1,\"HourDescription\":\"12 am - 1 am\",\"Value\":-0.11487,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":1,\"HourDescription\":\"12 am - 1 am\",\"Value\":16.101,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":2,\"HourDescription\":\"1 am - 2 am\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":2,\"HourDescription\":\"1 am - 2 am\",\"Value\":10.175,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":3,\"HourDescription\":\"2 am - 3 am\",\"Value\":-0.15443,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":3,\"HourDescription\":\"2 am - 3 am\",\"Value\":13.202,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":4,\"HourDescription\":\"3 am - 4 am\",\"Value\":-0.130146,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":4,\"HourDescription\":\"3 am - 4 am\",\"Value\":13.289,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":5,\"HourDescription\":\"4 am - 5 am\",\"Value\":-0.125505,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":5,\"HourDescription\":\"4 am - 5 am\",\"Value\":11.953,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":6,\"HourDescription\":\"5 am - 6 am\",\"Value\":-0.109888,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":6,\"HourDescription\":\"5 am - 6 am\",\"Value\":11.8,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":7,\"HourDescription\":\"6 am - 7 am\",\"Value\":-0.105976,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":7,\"HourDescription\":\"6 am - 7 am\",\"Value\":11.441,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":8,\"HourDescription\":\"7 am - 8 am\",\"Value\":-0.109031,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":8,\"HourDescription\":\"7 am - 8 am\",\"Value\":14.554,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":9,\"HourDescription\":\"8 am - 9 am\",\"Value\":-0.093543,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":9,\"HourDescription\":\"8 am - 9 am\",\"Value\":14.643,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":10,\"HourDescription\":\"9 am - 10 am\",\"Value\":-0.1052,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":10,\"HourDescription\":\"9 am - 10 am\",\"Value\":13.027,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":11,\"HourDescription\":\"10 am - 11 am\",\"Value\":-0.115724,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":11,\"HourDescription\":\"10 am - 11 am\",\"Value\":13.855,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":12,\"HourDescription\":\"11 am - 12 pm\",\"Value\":-0.108498,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":12,\"HourDescription\":\"11 am - 12 pm\",\"Value\":11.367,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":13,\"HourDescription\":\"12 pm - 1 pm\",\"Value\":-0.097682,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":13,\"HourDescription\":\"12 pm - 1 pm\",\"Value\":11.767,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":14,\"HourDescription\":\"1 pm - 2 pm\",\"Value\":-0.094643,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":14,\"HourDescription\":\"1 pm - 2 pm\",\"Value\":12.608,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":15,\"HourDescription\":\"2 pm - 3 pm\",\"Value\":-0.095467,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":15,\"HourDescription\":\"2 pm - 3 pm\",\"Value\":12.206,\"AirQualityCategory\":\"GOOD\",\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":16,\"HourDescription\":\"3 pm - 4 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":16,\"HourDescription\":\"3 pm - 4 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":17,\"HourDescription\":\"4 pm - 5 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":17,\"HourDescription\":\"4 pm - 5 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":18,\"HourDescription\":\"5 pm - 6 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":18,\"HourDescription\":\"5 pm - 6 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":19,\"HourDescription\":\"6 pm - 7 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":19,\"HourDescription\":\"6 pm - 7 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":20,\"HourDescription\":\"7 pm - 8 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":20,\"HourDescription\":\"7 pm - 8 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":21,\"HourDescription\":\"8 pm - 9 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":21,\"HourDescription\":\"8 pm - 9 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":22,\"HourDescription\":\"9 pm - 10 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":22,\"HourDescription\":\"9 pm - 10 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":23,\"HourDescription\":\"10 pm - 11 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":23,\"HourDescription\":\"10 pm - 11 pm\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"CO\",\"ParameterDescription\":\"Carbon monoxide\",\"Units\":\"ppm\",\"UnitsDescription\":\"parts per million\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":24,\"HourDescription\":\"11 pm - 12 am\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null},{\"Site_Id\":1001,\"Parameter\":{\"ParameterCode\":\"PM10\",\"ParameterDescription\":\"PM10\",\"Units\":\"µg/m³\",\"UnitsDescription\":\"microgram per cubic meter\",\"Category\":\"Averages\",\"SubCategory\":\"Hourly\",\"Frequency\":\"Hourly average\"},\"Date\":\"2022-12-01\",\"Hour\":24,\"HourDescription\":\"11 pm - 12 am\",\"Value\":null,\"AirQualityCategory\":null,\"DeterminingPollutant\":null}]","payloadType":"json","x":110,"y":3920,"wires":[["6f3229e0ec292e99","2b3a0fb24ed8d1d9","dc3f93e6dc631268"]]},{"id":"6f3229e0ec292e99","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"nodeName","pt":"msg","to":"Watts RGBW boiler","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3860,"wires":[["5801347964bfdbb2"]]},{"id":"2b3a0fb24ed8d1d9","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"nodeName","pt":"msg","to":"Watts RGBW sink","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3920,"wires":[["5801347964bfdbb2"]]},{"id":"dc3f93e6dc631268","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload.value","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"nodeName","pt":"msg","to":"Watts RGBW micro","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3980,"wires":[["5801347964bfdbb2"]]},{"id":"5801347964bfdbb2","type":"function","z":"452103ea51141731","name":"function 18","func":"let sync = context.get('sync') || {};\nconst nodeName = msg.nodeName;\nsync[nodeName] = msg.payload.value;\nconst sync_array = Object.values(sync);\n\nif (sync_array.length >= 3) {\n msg.payload = sync_array.reduce((acc, num) => acc+num, 0)\n sync = undefined;\n}else{\n msg = null;\n}\n\ncontext.set(\"sync\", sync)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":3920,"wires":[["265550587332c873"]]},{"id":"265550587332c873","type":"debug","z":"452103ea51141731","name":"debug 111","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":3920,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [2 December 2022 17:23 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/5 "2022-12-02T17:23:15Z")

</div>

Thats not working. This is my flow now

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

with the function node

```auto
var boiler = context.get('boiler') || 0;
var sink = context.get('sink') || 0;
var micro = context.get('micro') || 0;

var nodeName;
nodeName = msg.nodeName

if (nodeName == "Watts RGBW boiler") {
    boiler = msg.boiler
}

if (nodeName == "Watts RGBW sink") {
    sink = msg.sink
}

if (nodeName == "Watts RGBW micro") {
    micro = msg.micro
}

msg = sink + boiler + micro

context.set("boiler", 0)
context.set("micro", 0)
context.set("sink", 0)

return msg;

```

---

<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:** [2 December 2022 17:28 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/6 "2022-12-02T17:28:47Z")

</div>

If you moved the props to where I suggested then it should be...

```javascript
msg.payload = msg.sink + msg.boiler + msg.micro
return msg

```

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [2 December 2022 17:39 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/7 "2022-12-02T17:39:32Z")

</div>

I tried this, I left the change nodes as the nodeName is coming from my 'input' nodes anyway. Its now sending the sum of all the payload values as I wanted.  
Now I have to do some reading to understand what it does. I think I understand most, what I dont get (yet) is

```auto
msg.payload = sync_array.reduce((acc, num) => acc+num, 0)

```

@ [Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)

I will still try your way too

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2022 17:43 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/8 "2022-12-02T17:43:30Z")

</div>

> [@Mikee1234K](#):
>
> `msg.payload = sync_array.reduce((acc, num) => acc+num, 0)`

[Reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) iterates over an array and adds the element value (num) to acc, at end acc is sent to msg.payload. The 0 is the initial value of acc

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [2 December 2022 17:48 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/9 "2022-12-02T17:48:28Z")

</div>

OK that makes sense now. So the =\> is part of the .reduce function syntax, I thought is was greater or equal

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 January 2023 17:49 UTC](https://discourse.nodered.org/t/trying-to-add-3-incoming-msg-payload-value-and-failing/71620/10 "2023-01-31T17:49:10Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
