# Average by unknown numbers of messages and unknown time period

**URL:** https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663
**Category:** General
**Created:** [24 December 2022 16:16 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663 "2022-12-24T16:16:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Crashy77](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Crashy77](https://discourse.nodered.org/u/Crashy77)
#### Post date: [24 December 2022 16:16 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/1 "2022-12-24T16:16:40Z")

</div>

Hi.

I want to make averages for COP´s of my heatpump. Actually I´m sending them every 10 seconds to influxDB, but it´s looking terrible in Grafana.  
The problem is, that the consumption time is always different for heating, cooling or hot water.  
So I can´t use average, calculator or smooth.  
I think the only way is to store the values, knowing the number auf values and make the average of it.  
But I don´t know how. Is there a node for it or does somebody know how to write a function ?  
Thanks a lot.

With kind regards,  
Thorsten

---

<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: [24 December 2022 16:28 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/2 "2022-12-24T16:28:21Z")

</div>

Can you show us some examples of what data you are getting, and explain again why it is difficult to smooth.

---

<div class="post-metadata">

### Author: ![Crashy77](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Crashy77](https://discourse.nodered.org/u/Crashy77)
#### Post date: [25 December 2022 08:18 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/3 "2022-12-25T08:18:02Z")

</div>

I´m getting values for heat consumption and heat production and making the COP with it, for example 600W and 3600W. So the COP is 6. The time for heating up is always different depending on how cold it is.  
The heatpump values are retransmitted to MQTT broker every 30s.  
If the heat-up time takes 30mins I´ll get 60 messages, if it takes 1hour I´ll get 120 messages and when it´s very cold outside the heat-up time may takes 3hours.

---

<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: [25 December 2022 14:05 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/4 "2022-12-25T14:05:33Z")

</div>

So what do you want to do with those 60 (or however many) values?

---

<div class="post-metadata">

### Author: ![Crashy77](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Crashy77](https://discourse.nodered.org/u/Crashy77)
#### Post date: [25 December 2022 14:14 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/5 "2022-12-25T14:14:25Z")

</div>

I want only one value in InfluxDB/Grafana  
You can see, that the heatpump had worked 9 times but now I´m having a lot of data points instead of 9.

 ![heating_times](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c62588c8d0b0eefb4c739216f769042720017773.jpeg)  
I want only one value for each heating-up.

---

<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: [26 December 2022 20:44 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/6 "2022-12-26T20:44:43Z")

</div>

You could use a Join node in Manual Mode, to build and Array containing the values. When the set is complete then send it it msg.complete and it will pass on the array so you can then calculate the average value. That will also clear down the array in the Join node so it will start accumulating them when they arrive.

---

<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: [24 February 2023 20:45 UTC](https://discourse.nodered.org/t/average-by-unknown-numbers-of-messages-and-unknown-time-period/72663/7 "2023-02-24T20:45:22Z")

</div>

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