I am having some issues with accessing persistence data.
Rules:
val luminanceAvgMinutes = 10
val luminanceThreshold = 500
rule "Check if its dark"
when Item Sensor01_Sensor01Light changed
then
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) {
Dark.sendCommand(ON)
}
} else { // its light
if(Dark.state != OFF) {
Dark.sendCommand(OFF)
}
}
end
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:
http://openhabianpi:8080/rest/persistence/items/Sensor01_Sensor01Light?serviceId=influxdb
{"name":"Sensor01_Sensor01Light","datapoints":"1438","data":[{"time":1581177660162,"state":"200.0"},
{"time":1581177720165,"state":"200.0"},
...
{"time":1581263520063,"state":"382.0"},
{"time":1581263580065,"state":"409.0"},
{"time":1581263640066,"state":"409.0"},
{"time":1581263700068,"state":"409.0"},
{"time":1581263760070,"state":"435.0"},
{"time":1581263820072,"state":"435.0"},
{"time":1581263880074,"state":"461.0"},
{"time":1581263940075,"state":"461.0"},
{"time":1581264000078,"state":"461.0"}]}
and
http://openhabianpi:8080/rest/persistence/items/Sensor01_Sensor01Light?serviceId=mapdb
{"name":"Sensor01_Sensor01Light","datapoints":"1","data":[{"time":1581263851637,"state":"461"}]}
Could it be that my rules are trying to get the average from the mapdb persistence service instead of the finluxdb ?