Sanity checking sensor values by default

It would be nice to have a general sanity check for sensor values with configurable limits.

For example - I’m reading a storage battery voltage via Modbus and the system will sometimes hiccup and return 0V. Barring a serious disaster, the battery would never have a voltage outside the range of 40 to 60V. This incorrect value of 0 V then messes up my automations and graphs.

A properly designed sensor should always disregard nonsensical readings. So I propose the following:
The basic sensor should have setting options minimum_allowed_value and maximum_allowed_value (or something similar). If these are set and the read value is outside this range, it should be discarded (not taken as sensor state, it should be like the readout never happenned). There could also be an attribute like last_invalid_value_detected and similar mechanisms to help with debugging and detecting such cases.

I know that this could also be done with templates (and am doing it that way myself), but I see value in having the sensors behave properly from the ground up.

This is exactly what the outlier filter is for.

1 Like

Thank you for this, it is a way I didn’t know yet. :slight_smile:
But it is an additional entity instead of being a basic property of a sensor. I have a really large system and even on a RPi 4, my load values average over 0.2 all the time. I’m constantly looking for a way to make things simpler and this looks like something that should be part of the basic makeup of a sensor.
Of course, averages and the like do belong in filters.
Thank you for the help :slight_smile: