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.