[SOLVED] averageSince returns the last value, not the average

I am having some issues with accessing persistence data.


val luminanceAvgMinutes = 10
val luminanceThreshold = 500

rule "Check if its dark"
when Item Sensor01_Sensor01Light changed
    var luminance_avg = Sensor01_Sensor01Light.averageSince(now.minusMinutes(luminanceAvgMinutes)) as Number 
    logInfo("Status", "Luminance current is " + Sensor01_Sensor01Light.state + ", average is " + luminance_avg + ", threshold is " + luminanceThreshold)
    if(luminance_avg >= luminanceThreshold) { // its dark
        if(Dark.state != ON) {
    } else { // its light
        if(Dark.state != OFF) {

the log output:

020-02-09 16:55:53.105 [INFO ] [clipse.smarthome.model.script.Status] - Luminance current is 435, average is 435, threshold is 500
2020-02-09 16:57:31.667 [INFO ] [clipse.smarthome.model.script.Status] - Luminance current is 461, average is 461, threshold is 500

As you can see the current value and the ‘average’ are always the same. That is not what i expected …

My persistance data:






Could it be that my rules are trying to get the average from the mapdb persistence service instead of the finluxdb ?

It could be. mapdb only stores ONE value. You can specify which DB to use.


Thank you Vincent


The documentation is not so clear. But turns out that also for methods which already have an argument, you can add an optional argument with the persistance serviceId (influxdb here) to use.

Or you can change the defoult persistence service in the paperUI and the rules will use that one by default without the argument

But i have different persistence providers for different groups of items. Don’t want to mess up what is already working. (Until i add the ‘hardcoded’ persistenceId’s in place everywhere).

Created a pull request to add an additional example to the documentation.

1 Like

You might want to make sure you made it to the right branch. Until just a few minutes ago (as of this writing) the URL at the bottom of the page was pointing to the wrong branch in github. I’m sure the maintainers will help with that if that was the case.

1 Like