# How to sum many messages (numbers) that's arrive from one node

**URL:** <https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103>\
**Category:** General\
**Created:** [13 June 2021 15:08 UTC](https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103 "2021-06-13T15:08:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![badr\_al\_moragab](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@badr\_al\_moragab](https://discourse.nodered.org/u/badr_al_moragab)\
**Post date:** [13 June 2021 15:08 UTC](https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103/1 "2021-06-13T15:08:45Z")

</div>

Hello this is me Badr I'm student I tried many time to sum the messages that I arrive them from the same node  
For example I'm sending the temperature value 25° after a while mints the temperature become 30 so I need to add the second value that I arrived it (30) to the first value which is (25) to become the output value (55). After this when I arrive different value for example 35 it will add to the last value 55 to be the output 55+20= (((75)))  
so when I arrive message it will add to the last value that I got  
please help me to do the function that sum the values is arriving to the gauge.  
I will I appreciate your help.  
Thanks,,

 ![node red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a6d8d1f07bdc63e80a4c3836da59a69b0ce93e2f.png)

---

<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:** [13 June 2021 15:25 UTC](https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103/2 "2021-06-13T15:25:19Z")

</div>

You would need to store the sumed value in context storage  
e.g.

```auto
[{"id":"f9da93c6.58f8f","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":120,"y":4020,"wires":[["1cd0b2ff.15800d"]]},{"id":"1cd0b2ff.15800d","type":"function","z":"c74669a0.6a34f8","name":"","func":"msg.payload = (flow.get(\"sumTempVal\") || 0) + msg.payload;\nflow.set(\"sumTempVal\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":4080,"wires":[["7db5426b.da77f4"]]},{"id":"7db5426b.da77f4","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":4020,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![badr\_al\_moragab](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@badr\_al\_moragab](https://discourse.nodered.org/u/badr_al_moragab)\
**Post date:** [13 June 2021 16:00 UTC](https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103/3 "2021-06-13T16:00:46Z")

</div>

Thank you so much it helps me. ^\_^.

---

<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:** [27 June 2021 16:00 UTC](https://discourse.nodered.org/t/how-to-sum-many-messages-numbers-thats-arrive-from-one-node/47103/4 "2021-06-27T16:00:59Z")

</div>

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