Based on what I have learned I will rephrase the question:
How do I create a sensor that averages another (real) sensor over a time period, not just an average of the individual real sensor readings?
The real sensor has long periods at 0 which should count as many individual readings (and be averaged). In actuality the long periods at 0 simply count as a single 0 reading so the computed average (using a filter time_simple_moving_average ) is wrong.
I’m really stuck here so would very much appreciate any help.
Original question:
I have created a filter sensor to iron out spikes in the value of an electricity import sensor:
The problem I have is that if the input value (in this case sensor.givtcp_sa2236g166_import_power) to the filters has been positive for a while and suddenly drops to zero and stays there, the zero value is not included in the internal calculations so the output value of the sensor (Import Power filtered) stays with whatever is was. I would expect that as more and more zero input values arrive the output value of the filter would decay away to zero.
All your zero values are further than your specified outlier radius so they are being rejected and the last known good value that occurred is being kept. This is how the outlier filter works.
Thanks for the reply Tom. Unfortunately, this doesn’t appear to be my problem. I have removed the outlier filter altogether and the result is the same.
For example. a while ago the import figure was around 500 watts and the output of this filter sensor became very close to 500 (480 to be exact). The input import figure then dropped to 0 and has remained that value for around 15 minues. The filter sensor is still outputting 480.