Enable setting a median manually for the band-pass (outlier) filter#13386
Enable setting a median manually for the band-pass (outlier) filter#13386nielstron wants to merge 5 commits into
Conversation
| if (diff > self._radius): | ||
|
|
||
| self._stats_internal['erasures'] += 1 | ||
|
|
| else: | ||
| diff = abs(new_state - statistics.median(self.states)) | ||
| if (diff > self._radius): | ||
|
|
OttoWinter
left a comment
There was a problem hiding this comment.
I honestly don't see why we should do this. Sure it would fix the issue, but the much much cleaner solution would be #13075.
Why should we add an additional configuration option if the other solution actually fixes the issue long-term?
| if (self.states and | ||
| abs(new_state - statistics.median(self.states)) | ||
| > self._radius): | ||
| if(self.states): |
There was a problem hiding this comment.
No parentheses for if in python:
if self.states:| """Initialize Filter.""" | ||
| super().__init__(FILTER_NAME_OUTLIER, window_size, precision, entity) | ||
| self._radius = radius | ||
| self._manual_median_enabled = (median == NO_MANUAL_MEDIAN) |
There was a problem hiding this comment.
Why would you store this? I mean you can calculate it on the fly with self._manual_median.
|
This does not only fix #13363 but also enables freedom for the users. Maybe someone does want to limit the temperature sensor data to exactly -30 to 50 degrees celsius but the actual median of measured data is unknown. This allows for more control over which values to pass and which to keep. Running the statistics on historical data (as I understood #13075) is great too and should be added for median compuation. |
Use the median if set manuall, not else
|
I think the use case #13386 (comment) is sound. But I would simply set two variables: lower_bound, upper_bound (you could set both or just one) Fixing the median is very strange IMHO and looks little bit hackish. |
|
I'm not sure whether my previous comment got posted (kind of on a flakey connection here...), so posting this again: IMHO I don't really think the Kind of like this: sensor:
- platform: filter
name: "filtered realistic humidity"
entity_id: sensor.realistic_humidity
filters:
- filter: range
min: 10 # If not specified, just use max as upper bound. Could also be called lower_bound
max: 80 # If not specified, just use min as lower bound.I think this would make more sense because then the "dynamic" outlier filter would be separate from the "static" range filter (static in that it doesn't adapt to incoming values). |
|
I have created a new bandpass filter that rather matches the idea of a range/basic band pass filter: #13390 |
Description:
Automatic computation of the median for the outlier filter lead to issues. This is an attempt at fixing it.
Also user can clearly define a band for passing values this way.
Related issue: fixes #13363 (but is not only meant as fix for this)
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4984
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices: