Hi there,
I could a question, which actually sound easy, but confuses me.
I’m trying to use Home Assistant statistics for a signal like this, which show a heat pump’s COP with a stop of the machine at 14:00:
From this time on, the value of the COP is actually not available and therefor drops down to Zero (blue line).
In another test, I’ve changed sensor to not update, if the machine goes to off state and therefore the COP’s value stays at last value (purple line).
Both seem to result in wrong statistics by Home Assistant’s statistics diagram, because the first sensor includes zero values in mean value and the second sensor is including last value for mean value calculation.
Can somebody help, how to properly set up the sensor or explain how to exclude zero values from mean calculation of statistics?
When a device is unavailable, the state should not be 0 but litterally unavailable. If this is an integration the developer should fix it. If this is a template sensor, you can fix it yourself, but we need to know more about it.
If the integration developer does not fix it, you could make a template sensor with the right behavior, assuming the value cannot actually be 0 that you need to know about.
I cannot test myself, so forgive me if I made a mistake somewhere. Changes I made:
The if is gone, that was what gave the problems
an availability template was added, to tell HA when the sensor is available/unavailable
float shoud have a default these days so I changed it to float(0). That basically does the same as the if you had, but with the availability template, it should never happen.
Indentation of last two lines fixed, probably paste error.