I have an automation that I want to trigger off a fluctuating sensor (amps). I would like to smooth the data - a running average of 5 samples would be quite adequate. However, the sensor I am monitoring doesn't report if the value doesn't change. I've set up a statistical sensor and tried using a mean and several of the average methods, but all of them cease to update if the target entity doesn't update. As a result, if the target entity goes from 20 amps to zero then stops reporting, the average sensor remains high. Am I missing something? Any suggestions on how to handle this?
#How to smooth data for a static sensor
1 messages · Page 1 of 1 (latest)
Are you running the latest version of HA? There was a PR a few months ago that should have addressed this, as long as the sensor does actually repeatedly report zero instead of reporting one zero and then not reporting again.
The problem seems to be that the sensor doesn't report static values - once it goes to zero, no more values are reported. There doesn't seem to be a parameter on the hardware to change that.
While this is ugly, if you really must have this, you can make a template sensor that applies a small "fuzz" to the source, to keep a stream of new data flowing.
Like during even-numbered minutes return the raw value, and in odd numbered minutes, return the raw value + 0.00001
Kind of a bad limitation of sample based calculations. =\
I haven’t tried this since the updates to the statistics integration but you might not need the fuzz workaround any more, if a time-pattern-based template sensor fires state_reported events. I don’t know if it does though.
There is also a custom integration which does a better job of calculating time-based averages and I think it handles this type of edge case
https://github.com/Limych/ha-average