diff --git a/function/smooth/17-smooth.html b/function/smooth/17-smooth.html
index 177fefd7..7fa06e74 100644
--- a/function/smooth/17-smooth.html
+++ b/function/smooth/17-smooth.html
@@ -32,7 +32,10 @@
diff --git a/function/smooth/17-smooth.js b/function/smooth/17-smooth.js
index e924c8ae..14e69af4 100644
--- a/function/smooth/17-smooth.js
+++ b/function/smooth/17-smooth.js
@@ -16,6 +16,13 @@ module.exports = function(RED) {
var old = null;
this.on('input', function (msg) {
+ if (msg.hasOwnProperty("reset")) {
+ a = [];
+ tot = 0;
+ tot2 = 0;
+ pop = 0;
+ old = null;
+ }
if (msg.hasOwnProperty("payload")) {
var n = Number(msg.payload);
if (!isNaN(n)) {
diff --git a/function/smooth/README.md b/function/smooth/README.md
index 9beb68e5..5cb2f7dd 100644
--- a/function/smooth/README.md
+++ b/function/smooth/README.md
@@ -33,5 +33,7 @@ the more the smoothing. E.g. a value of 10 is similar to an α of 0.1.
It is analogous to an RC time constant - but there is no time component to
this as the code is based on events arriving.
+If `msg.reset` is received (with any value), all the counters and intermediate values are reset to an initial state.
+
**Note:** This node only operates on **numbers**. Anything else will try to be
made into a number and rejected if that fails.
diff --git a/function/smooth/package.json b/function/smooth/package.json
index c2f857c4..3c0654f2 100644
--- a/function/smooth/package.json
+++ b/function/smooth/package.json
@@ -1,6 +1,6 @@
{
"name" : "node-red-node-smooth",
- "version" : "0.0.9",
+ "version" : "0.0.10",
"description" : "A Node-RED node that provides several simple smoothing algorithms for incoming data values.",
"dependencies" : {
},
diff --git a/test/function/smooth/17-smooth_spec.js b/test/function/smooth/17-smooth_spec.js
index 14bd2d24..3408151a 100644
--- a/test/function/smooth/17-smooth_spec.js
+++ b/test/function/smooth/17-smooth_spec.js
@@ -48,6 +48,27 @@ describe('smooth node', function() {
});
});
+ it('should be able to be reset', function(done) {
+ var flow = [{"id":"n1", "type":"smooth", action:"mean", count:"5", round:"true", wires:[["n2"]] },
+ {id:"n2", type:"helper"} ];
+ helper.load(testNode, flow, function() {
+ var n1 = helper.getNode("n1");
+ var n2 = helper.getNode("n2");
+ var c = 0;
+ n2.on("input", function(msg) {
+ c += 1;
+ if (c === 3) { msg.should.have.a.property("payload", 2); }
+ if (c === 6) { msg.should.have.a.property("payload", 5); done(); }
+ });
+ n1.emit("input", {payload:1});
+ n1.emit("input", {payload:2});
+ n1.emit("input", {payload:3});
+ n1.emit("input", {reset:true, payload:4});
+ n1.emit("input", {payload:5});
+ n1.emit("input", {payload:6});
+ });
+ });
+
it('should output max over a number of inputs', function(done) {
var flow = [{"id":"n1", "type":"smooth", action:"max", count:"5", wires:[["n2"]] },
{id:"n2", type:"helper"} ];