# Smoothing a value and check for extrems

**URL:** <https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303>\
**Category:** General\
**Created:** [14 September 2023 10:11 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303 "2023-09-14T10:11:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)\
**Post date:** [14 September 2023 10:11 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/1 "2023-09-14T10:11:56Z")

</div>

Hello friends.

Today i am testing a current HAt to measure my 4-20 mA signal. For this i am using the waveshare current HAt and my ROCKPI E, where my Node-red instance is running.

To read the current hat i am using this node: node-red-contrib-easybotics-ina219-sensor

Sadly the signal is not very accurate. When i am using the HAT with my ESP32 i get clean values. Cant figure out what the problem is. Anyway:

I try to live with it, since i am depning on my ROCKPI E (until now), i try to smooth the value. I know that there is a smooth-node.

Problem 1: I could live with the 4-20 mA signal, if there wouldnt be every 7 sec. a very bad signal.  
Problem 2: If i create a function, where, lets say for example, every value should be ignored, that is +- 20% from a average away, i face the problem, that if my signal is changing, this "new" values will also be ignored, because this "true" new values are also to much away from my average value.

Has someone an idea how to get this to work?

Thank you

---

<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:** [14 September 2023 10:41 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/2 "2023-09-14T10:41:22Z")

</div>

Have you tried the range node to limit bad readings.  
e.g.

```auto
[{"id":"dc1e8f6e7786190a","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":120,"wires":[["0af72d14e65f4525"]]},{"id":"0af72d14e65f4525","type":"range","z":"65617ffeb779f51c","minin":"4","maxin":"20","minout":"4","maxout":"20","action":"clamp","round":false,"property":"payload","name":"","x":370,"y":120,"wires":[["fa62bcc9fa190dcf"]]},{"id":"882508cffe9e1877","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":130,"y":180,"wires":[["0af72d14e65f4525"]]},{"id":"34899b1448d439bd","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":130,"y":240,"wires":[["0af72d14e65f4525"]]},{"id":"a113aa9f10e2d4e8","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":130,"y":300,"wires":[["0af72d14e65f4525"]]},{"id":"fa62bcc9fa190dcf","type":"debug","z":"65617ffeb779f51c","name":"debug 337","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":120,"wires":[]}]

```

---

<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:** [14 September 2023 12:58 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/3 "2023-09-14T12:58:55Z")

</div>

A post was split to a new topic: [Prevent outlier reading going to Influx](https://discourse.nodered.org/t/prevent-outlier-reading-going-to-influx/81308)

---

<div class="post-metadata">

**Author:** ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)\
**Post date:** [16 September 2023 18:43 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/4 "2023-09-16T18:43:44Z")

</div>

Thank you for the answer

The problem is, that the outliners are in the 4-20 range. I should get the value, lets say 5.5. I will get:  
5.5  
5.4  
5.5  
5.4  
5.4  
7.0

This seven is a outliner. like i meantioned above. the problem is, that the input can change realy fast. So i am kinda now in a wired situation, how to kill this outliners.

thank you

---

<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:** [16 September 2023 18:51 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/5 "2023-09-16T18:51:59Z")

</div>

How about the filter node then.

```auto
[{"id":"fdf121a121fc1e30","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[5.5, 5.4, 5.5, 5.4, 5.4, 7.0, 5.5, 5.4, 5.5, 5.4, 5.4]","payloadType":"json","x":270,"y":60,"wires":[["713a1aa8038d0978"]]},{"id":"713a1aa8038d0978","type":"split","z":"b9860b4b9de8c8da","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":60,"wires":[["3faba304ebecd18c"]]},{"id":"3faba304ebecd18c","type":"rbe","z":"b9860b4b9de8c8da","name":"","func":"narrowband","gap":"5%","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":530,"y":100,"wires":[["825b1902aba22bc3"]]},{"id":"825b1902aba22bc3","type":"debug","z":"b9860b4b9de8c8da","name":"debug 338","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":100,"wires":[]}]

```

---

<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:** [16 September 2023 18:59 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/6 "2023-09-16T18:59:37Z")

</div>

How do you know, in that example, that 7 is an outlier?

---

<div class="post-metadata">

**Author:** ![Manuel\_o](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Manuel\_o](https://discourse.nodered.org/u/Manuel_o)\
**Post date:** [18 September 2023 08:09 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/7 "2023-09-18T08:09:10Z")

</div>

Hello,

@colin0031 Because i can control the input for testing.

I can send a 4-20 mA signal, where i know that it is a 5.5 mA signal. I am 100% sure that the input  
isnt causing this outliners. It is a receiver thing.

My guess is, that it is a I2C range setting thing.  
A littile bachground: I am using a WAVESHARE current loop, that is connected with my RockpiE to measure my 4-20 mA signal. On my ROCKpiE runs NODE-RED to measure the signal. For this i am usining the [node-red-contrib-easybotics-ina219-sensor (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-easybotics-ina219-sensor) node  
There i get this outliners.

Strange is. When i use an ESP32 instead of RockpiE and use Ardunio code, the signal is very constant. Since i can set ranges in my ardunio code, to increase the accuracy of my WAVESHRE, i think that the NODE from easybotics just uses a very roughe range by default. Unfortunly i cant manipulate the range with this node. For this project i depend on my RockpiE. And since i have no idea how else to read the signal of my WAVESHARE 4-20- current module with node-red, i have to live with that.

@E1cid thank you  
Thank you. But the problem remains. What if my input signal is changing? Then this "true" value would be ignored

---

<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:** [18 September 2023 09:32 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/8 "2023-09-18T09:32:09Z")

</div>

> [@Manuel\_o](#):
>
> What if my input signal is changing?

The small data set you supplied the signal is changing.

So please better explain the input signal how it changes. It is impossible to help with out all the info, drip feeding us relevant information is not helpful. We need to work out how to identify an outlier, until we can do that we can not remove it. Maybe show a real data (fairly large) set and then identify the outliers and then we may be able to suggest a strategy.

---

<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:** [18 September 2023 13:59 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/9 "2023-09-18T13:59:44Z")

</div>

> [@Manuel\_o](#):
>
> @colinl Because i can control the input for testing.

I meant how would you know that it is spurious if you saw that sequence come in?

> [@Manuel\_o](#):
>
> It is a receiver thing

I suggest using a receiver that works.

---

<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:** [17 November 2023 14:00 UTC](https://discourse.nodered.org/t/smoothing-a-value-and-check-for-extrems/81303/10 "2023-11-17T14:00:20Z")

</div>

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