Occasionally I’ll get really off values from my sensors. My temperature sensor sometimes will report some value over 15,000 which is obviously incorrect. I have the same issue with an Aeonlabs Home Energy Monitor sometimes reporting negative values.
As far as I can tell, neither of these issues are home-assistant’s fault, but I’d like to see an attribute set using customize to limit the range of acceptable values(min/max) for a sensor.
I had the same problem literally yesterday. I wonder what would be a good place to add this. Cap all temperature values in a sensor to a certain range ? Or should it be per platform / device (lots of repetition when it gets to temperature?)
Originally I was thinking per device, but you have a good point that there’d be a lot of repetition. There could be a global max/min temp setting.
What about a min/max per unit of measurement? That’d also fix my other issue with a power sensor if I could set a min/max for w/kwh as well as F/C.
A more complicated solution could be a way to apply a template to all sensors (after their individual templates have been processed) so that someone could write their own logic to do something like this.
I have these problems also from time to to. I think there should be a min/max option for every sensor.
Also contributors should be encouraged to do some basic range checking where it is possible (e.g. % values are usually between 0 and 100). This will make the system much more robust.
Smoothing is not really an option here, because the strange readings are so far off.
Usual values are between 17°C and 22°C and then there is one with 4980°C.
I would really like to just ignore everything below -10°C and + 60°C
There is at least three components that can be used but don’t quite work together currently.
Individual exceptional measurements can be smoothed with statistics and a median of 5 readings would be OK to filter our suddent exceptional changes.
Persisting unlogical input as when my ESIC 433MHz shows temperature below -1000’C in certain conditions (humidity) is another issue. Condition like this could go on longer than reasonable sampling window for smoothing window, for example a couple of hours. Median and statistics then fail for this case.
There should be a way to convert the out of range values to missing or N/A. While value template can be used to change -1000 to 0, this is not OK for statistics.
Using value template to return None currently messes sensor history as HA treats the states discrete after seeing None values.
@mr-varga - I stumbled onto this thread after my humidity sensor was reporting -999 Anyway I was monkeying around today and I believe you need to cast your state to a float. This works for me:
{%- if states.sensor.pws_relative_humidity.state|float >= 0 and states.sensor.pws_relative_humidity.state|float <= 100 -%}
{{(states.sensor.pws_relative_humidity.state)}}
{%- else -%}
nan
{%- endif -%}
its not exactly what you need, as you cannot define a range of permissable values in the outlier filter. Its close to the “range” filter, but range just floors and caps the values, not ignore them.