Trending Average Trigger

  • Platform information:
    • Hardware: RPi 3B
    • OS: Openhabian
    • Java Runtime Environment: ??
    • openHAB version: 3.0.1
  • Issue of the topic:
    I would like to create a rule to monitor the trending average of a value (pH) and when the value trends high or low trigger an action (engage switch item). Basically, if the pH rises or falls over a two hour time period, I would like to know, so I can adjust accordingly. I may implement the rule to actually engage the pH pump but I have not decided.

I have implemented many rules, just nothing with any kind of averaging.

Is this possible?

Do you have any suggestions?


There’s no truly out-of-the-box solution that I’m aware specifically for moving averages, but there are a couple of avenues that might work for you with only a little specific figuring. Depending on how you have your persistence configured, I think the easiest is probably a rule that takes advantage of the averageSince persistence feature.

1 Like

Thanks! I’ll take a look. I do have persistence setup. I don’t recall at the moment which flavor I went with but I believe it was the recommended setting found in the forum.

You get rrd4j by default with OH3, which should be perfectly adequate for this purpose.

Just to provide an outline for how I would solve this using the UI rules.

  • First make sure the Item is being persisted.

  • In the UI create a rule that triggers when the pH Item changes, or on a cron polling period depending on which works best for you.

  • Next add a Script Condition (But only if…) and in this get the averageSince or historicStatefor the Item. Depending on the value of the averageSince return true or false.

  • If the Script Condition returned false, the rule won’t run. If it returned true the rule will run. So add a Script Action to take the action you desired. You already know that some action needs to take place because that was calculated in the Script Condition.

  • It might make sense to split it into two separate rules, one for the pH going high and a separate one for the pH going low.

1 Like

I’ll take a look at that routine. That doesn’t seem too difficult to get setup. I appreciate the bullet points and detail in your post. Thanks so much!