Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Range Filter profile #3534

Closed
wants to merge 1 commit into from
Closed

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Apr 9, 2023

Add a range-filter profile to allow/discard values inside a given range.

Example .items file:

// Simple range - allows 0 - 30
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[0 .. 30]" }
// exclusive boundaries with ( and ) discards 0 and 30
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="(0 .. 30)" }
// exclusive boundaries only on beginning/end: accepts 0, discards 30
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[0 .. 30)" }

// Supports "inverted" range: discards what's in the given range
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[0 .. 30]", action="discard" }

// Supports begin-less and end-less range, i.e. for a simple "greater than / less than" filter
//   allow anything up to and including 30
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[ .. 30]" }
//   allow anything 30 or above
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[30..]" }

// multiple ranges
Number MyNumber { channel="xxxx" [profile="system:range-filter", range="[0 .. 30], [60..80]" }

// Dimensioned item/channel
Number:Temperature MyTemp { channel="xxxx" [profile="system:range-filter", range="[-50 °C..60 °C]" ] }
// mix units in the range
Number:Temperature MyTemp { channel="xxxx" [profile="system:range-filter", range="[-50 °C..140 °F]" ] }

Config in the Main UI:
image

@jimtng jimtng requested a review from a team as a code owner April 9, 2023 08:35
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/reasonableness-constraints/145795/26

@jimtng jimtng force-pushed the filter-profile branch 8 times, most recently from c51cb0e to c41ff63 Compare April 9, 2023 15:08
@jimtng jimtng marked this pull request as draft April 10, 2023 10:16
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng jimtng changed the title Add SystemFilterProfile to filter values within a given range Add a Range Filter profile Apr 10, 2023
@jimtng jimtng marked this pull request as ready for review April 10, 2023 12:11
@rkoshak
Copy link

rkoshak commented Apr 10, 2023

I suspect if you make it someone somewhere will use it. The range as implemented can handle most common use cases. I'm not sure how one would implemented outlier except though a moving-average, though maybe I'm just not 100% back mentally after being ill all last week.

Thinking through some use cases:

  • reject values that are obviously out of range (e.g. temp sensor reporting 5000 °C)
  • reject values that are a jump beyond what's reasonable from the last value (e.g. temp sensor jumps from 5 °C to 30 °C)
  • reject values that are too small of a change from the last one (smooth out values from a noisy sensor)
  • ignore a discrete state always (e.g. maybe someone has a Switch Item linked to a channel that provides ON, OFF, STANDBY and they want to just ignore STANDBY)

It makes a lot of sense to have one profile that can handle all these (and any others I've not thought of.

@jimtng
Copy link
Contributor Author

jimtng commented Apr 12, 2023

I'm not sure how one would implemented outlier

I've presented several options in the forums, all of which can be implemented, giving user the choice of method to use

  • Inter Quartile Range method
  • Standard deviation as the range (i.e. only accept data if it's below the standard deviation) method
  • A fixed "deviation" method - check how much it deviates from the median of the collected samples - basically the same way HomeAssistant does it
  • Others can be added in the future

Thinking through some use cases:

  • reject values that are obviously out of range (e.g. temp sensor reporting 5000 °C)
  • reject values that are a jump beyond what's reasonable from the last value (e.g. temp sensor jumps from 5 °C to 30 °C)

Either a range or an outlier filter can handle this

  • reject values that are too small of a change from the last one (smooth out values from a noisy sensor)

A moving average filter can handle this - but it's different from an outlier filter.

  • ignore a discrete state always (e.g. maybe someone has a Switch Item linked to a channel that provides ON, OFF, STANDBY and they want to just ignore STANDBY)

Currently this PR only supports numeric channels / items.

Perhaps for this, we need a different type of filter, e.g. value-filter which provides a list of allowed (or forbidden/blocked) discrete values, e.g. a comma separated list of values, which would be suitable for string / non numeric items.

For numeric items, it can be done using this range profile [10..10], [15..15] to allow/reject 10 and 15.

@crnjan
Copy link
Contributor

crnjan commented Apr 13, 2023

Will something like https://www.home-assistant.io/integrations/filter/#time-simple-moving-average also be supported? Currently I'm using something like

  var item = items.getItem(name);
  var from = time.ZonedDateTime.now().minusMinutes(10);
  var average = item.history.averageSince(from);

to smoothen my temperature readings but having a profile to do the job would be imho nicer ...

@jimtng
Copy link
Contributor Author

jimtng commented Apr 13, 2023

Will something like https://www.home-assistant.io/integrations/filter/#time-simple-moving-average also be supported? Currently I'm using something like

  var item = items.getItem(name);
  var from = time.ZonedDateTime.now().minusMinutes(10);
  var average = item.history.averageSince(from);

to smoothen my temperature readings but having a profile to do the job would be imho nicer ...

I think that belongs in a separate profile (to be created) called smoothing-filter with the option of various ways of achieving that, e.g. https://en.wikipedia.org/wiki/Moving_average

@jimtng
Copy link
Contributor Author

jimtng commented Apr 22, 2023

Closing this because it needs to go into an addon

@jimtng jimtng closed this Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants