# Adding a "reduce" option to the Smooth node

**URL:** <https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180>\
**Category:** Feature Requests\
**Created:** [5 September 2019 22:59 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180 "2019-09-05T22:59:17Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2019 15:48 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/21 "2019-09-06T15:48:42Z")

</div>

It prob would but as usual its a choice between an extra specialist node or trying to do it with basic ones 🙂

I went for the easy option on this one  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2da2f4cffd8f8e93dc1a5b01228a23ed190b66a9.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 September 2019 15:52 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/22 "2019-09-06T15:52:14Z")

</div>

> [@Colin](#):
>
> I don't think the proposed PR would handle that.

Agreed. I was just building onto the original request with some similar issues I've seen...

> [@Colin](#):
>
> I suppose if the smooth node had a msg.transform input that told it to do the maths on what it had, output the value, and clear its memory then that would do it

As Simon mentions, I've also used the `node-red-contrib-aggregator` to do this (until I wrote my own custom node). But I still would prefer a core node that could "pare down" my data, similar to what was proposed, but with a more generic field-based (or even JSONata expression) to do the grouping...

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 September 2019 15:56 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/23 "2019-09-06T15:56:12Z")

</div>

> [@shrickus](#):
>
> but with a more generic field-based (or even JSONata expression) to do the grouping...

... although now that I put it that way, perhaps it makes more sense for this "grouping" to be an option on the `join` node... hmmm

Of course, now that I look at it, the `join` node already has a "reduce sequence" feature, which will probably do what I want:

> Reduce Sequence mode
> 
> When configured to join in reduce mode, an expression is applied to each message in a sequence and the result accumulated to produce a single message.

---

<div class="post-metadata">

**Author:** ![clickworkorange](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clickworkorange/32/12109_2.png) [@clickworkorange](https://discourse.nodered.org/u/clickworkorange)\
**Post date:** [6 September 2019 16:19 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/24 "2019-09-06T16:19:06Z")

</div>

> [@Adding a "reduce" option to the Smooth node](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/19):
>
> I currently use node-red-contrib-aggregator to achieve same effect in my pool temp monitor. The pool sends readings every sec and I average the readings over 60 secs and then pass that on to rest of flow I wouldn't want to just send a single value to represent the 60 readings as it may be an outlier - I use the average (actually the median value) instead

I had already looked at node-red-contrib-aggregator, but it suffered from the same problem as @Colin's suggestion (using the Delay node w. rate limiting); that messages are averaged over _time_ rather than _by message count_. I need to take N number of messages and get an average (or minimum, or maximum) of those, regardless of what time they arrived at, and I need that behaviour to be perfectly linear and predictable. The fact that the Smooth node already does 99% of this, and could be quite easily modified to add the missing piece, without any chance of breaking existing flows, to me personally makes this seem like a good solution. But I'm probably an edge case - I'll see if I can figure out how to pull in this node independently from the other node-red-nodes from my own fork for now. Maybe the ultimate answer is to create a completely new "Reduce" function node for this particular behaviour.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2019 16:23 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/25 "2019-09-06T16:23:19Z")

</div>

> [@clickworkorange](#):
>
> The fact that the Smooth node already does 99% of this, and could be quite easily modified to add the missing piece, without any chance of breaking existing flows, to me personally makes this seem like a good solution.

I think it is as well

---

<div class="post-metadata">

**Author:** ![mauromago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mauromago/32/6576_2.png) [@mauromago](https://discourse.nodered.org/u/mauromago)\
**Post date:** [9 September 2019 18:11 UTC](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180/26 "2019-09-09T18:11:44Z")

</div>

Calculate node do what you want.

> **[node-red-contrib-calculate](https://flows.nodered.org/node/node-red-contrib-calculate)**
>
> A calculating node for node-red

  
I use it

[Previous page](https://discourse.nodered.org/t/adding-a-reduce-option-to-the-smooth-node/15180.md?page=1)
