Hello, I want to plot soil moisture published on MQTT on a graph, which works well in Node Red. Unfortunately the sensor values seem to jump a round a bit in a short timeframe so I wanted actually use the moving average 100 values and think the Moving Average Node is the right Node to do this.
This works fine after deployment but no matter what I do after some time (sometimes hours) the Graph of the unfiltered (top Graph) values keeps plotting but the moving average node seems to always deliver NaN.
Is this a bug in the Node or what am I doing wrong ?
First of all, I think you need to track-down why you are getting NaN - as this indicates a non-number.
I'd start-off by putting a 'debug' node on the MQTT-In node and see what sort of data is there.
You could also use Mqtt-Explorer to "sniff" what is happening.
Note: You could set the 'Output' of the MQTT-In node to 'auto-detect' and then remove your 'json' node.
If you are getting spurious readings/values, you could apply a test or filter like... "if the current reading is 10% or 20% different to the last reading ignore it, otherwise pass it". This obviously depends on how often you take a reading and how much the value could normally change between readings.
If you can share your Node-RED flow I'm sure people will take a look and suggest other things to try.
Thanks for the replies. Debug is a bit tricky as mentioend this sometime only happens after hours and the unfilterted Graph seems to be processing fine - it might be more robust though
Would someting like that work inside the Tripple node , i.e. if a non-Number comes in from MQTT stop processing the message ?
I think it's the data being sent by the Shelly Plus soil moisture sensor.
Gut feel is the voltage goes out of expected range and the Shelly box gives an error when the reading is duff...
Personally I would check the data straight off the sensor (i.e. before it even gets to the MQTT server) but that may not be possible here - in this case I would check for a valid range and reject anything out of spec ASAP in the flow (e.g. after the MQQT collection or JSON conversion). These values can be logged to a file and warning issued if you get too many of them per day or in a row - both signs of a sensor going faulty or needing a clean.
(Living here in a hard water area kills capacitive and resistive sensors very quickly)