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

Improve existing and add new persistence filters #3642

Merged
merged 6 commits into from
Jun 18, 2023

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented Jun 1, 2023

#2871 introduced working persistence filters base on time and threshold, but since they were never documented, I doubt they have been used at all.

This PR changes is API breaking because it changes the filter definitions in persistence.xtext but this will probably not be noticed at all. It also adds two new persistence filters: "Equals" and "NotEquals" that can be used to allow/disallow a certain set of values.

Filters can be defined by

Filters {
  tenseconds : T 10 s
  fivepercent : > % 5
  hundredmilliamps : > 100 mA
  equals : = "only","these","values"
  notequals : ! "not","these","values"

and be applied with

Items {
  item1, item2 : strategy = everyChange filter = fivepercent
  group1 : strategy = everyUpdate filter = tenseconds

I'll add documentation in the next few days.

@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label Jun 1, 2023
@J-N-K J-N-K requested a review from a team as a code owner June 1, 2023 16:52
@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/is-the-a-way-to-persist-only-if-a-value-is-equal-or-not-equal-so-it-doesnt-graph-in-rrd4/146993/3

@rkoshak
Copy link

rkoshak commented Jun 1, 2023

While you are at it, does it make sense to add a range filter? Ignore all values that are above/below a min/max range for filtering out obviously bogus sensor readings. That's a common use case.

One could argue that would best be applied in a profile I'll concede.

J-N-K added 3 commits June 2, 2023 18:58
Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: Jan N. Klug <[email protected]>
@J-N-K J-N-K force-pushed the persistencefilters branch from 511ff51 to f6a5156 Compare June 2, 2023 18:10
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jun 6, 2023
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify treshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <[email protected]>
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jun 6, 2023
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify treshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <[email protected]>
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jun 6, 2023
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify threshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <[email protected]>
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jun 6, 2023
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify threshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <[email protected]>
J-N-K added 2 commits June 7, 2023 16:31
Signed-off-by: Jan N. Klug <[email protected]>
Signed-off-by: Jan N. Klug <[email protected]>
@kaikreuzer
Copy link
Member

@J-N-K What do you think about @rkoshak suggestion above?

@J-N-K
Copy link
Member Author

J-N-K commented Jun 11, 2023

It's easy from code, the question is as @rkoshak already pointed out: is this something that should be done for persistence or is it more something for a profile? If you think it's useful as persistence filter, then I can add it.

@kaikreuzer
Copy link
Member

I personally would consider it useful, because I often see the situation that bogus sensor values get persisted and there is no easy way to clean up persisted data afterwards. So if it is easy to implement and nobody vetos - why not add it.

@rkoshak
Copy link

rkoshak commented Jun 15, 2023

I thought of a case that can only be solved as a persistence filter. What if you have a sensor where you do want to process errant readings in a rule (e.g. send an alert, take remedial action, etc.) but do not want to persist the data? If you used a profile you can't do that but as a persistence filter you can. (Or in a rule of course with the persist() action.

And it probably deserves it's own issue, but periodically users lament the fact that the persistence config doesn't allow something like "everything but". If I had two Items I don't want to be persisted but want all the rest to be, I have to include all the rest in the config instead of just the two to exclude.

That's not an easy change I suspect but is it something worth opening another issue for?

Signed-off-by: Jan N. Klug <[email protected]>
@kaikreuzer
Copy link
Member

That's not an easy change I suspect but is it something worth opening another issue for?

Feel free to open one. 😄

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@kaikreuzer kaikreuzer merged commit d64bd3b into openhab:main Jun 18, 2023
@kaikreuzer kaikreuzer added this to the 4.0 milestone Jun 18, 2023
@J-N-K J-N-K deleted the persistencefilters branch June 18, 2023 07:43
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jun 23, 2023
It is accessible from the add-on settings page and has both a design and a code tab.

The design tab allows to set persistence strategies for Items, define cron strategies and set the default strategies.
It does not duplicate names for (cron) persistence strategies and duplicate configs for the same set of Items.

The code tab also allows to also specify threshold and time filters and needs minor adjustment once openhab/openhab-core#3642 is merged code completion is not provided.

Signed-off-by: Florian Hotze <[email protected]>
ghys pushed a commit to openhab/openhab-webui that referenced this pull request Jun 28, 2023
Closes #1463.
Refs openhab/openhab-core#2871.
Refs openhab/openhab-core#3642.

It is accessible from the add-on settings page and has both a design and
a code tab.

The design tab allows to set persistence strategies for Items, define
cron strategies and set the default strategies. It does not duplicate
names for (cron) persistence strategies and filters as well as configs
for the same set of Items.
All four filters provided by openHAB core (treshold, time, equals/not
equals, include/exclude) can be configured.
When the user removes a cron strategy or a filter, it is automatically
removed from all configs so that there is no API failure (400 Bad
Request).

No code completion is not provided, but required attributes for filters
are automatically set on save to avoid API failure (500 Internal Server
Error).

A few words about order and sorting:
- openHAB Core seems to sort the cron strategies.
- Configurations itself are unsorted, they could be sorted
alphabetically by the UI.
- Items of configuration are sorted by their type (groups before normal
Items) as well as alphabetically.

--
Signed-off-by: Florian Hotze <[email protected]>
Co-authored-by: J-N-K <[email protected]>
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
* Improve existing and add new persistence filters
* include filter

Signed-off-by: Jan N. Klug <[email protected]>
GitOrigin-RevId: d64bd3b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants