averageSince results in null

I want to get the average temperature of my swimmingpool.

logInfo("testrule", "temp -1h: " + Pool_Temp.historicState(now.minusHours(1)).state as DecimalType)
logInfo("testrule", "temp avg 1h: " + Pool_Temp.averageSince(now.minusHours(1)).state as DecimalType) 

but the result is always null or something else depending on the command usage…

2020-04-05 10:51:57.679 [INFO ] [ipse.smarthome.model.script.testrule] - temp -1h: 7.3
2020-04-05 10:51:57.684 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ' test': 'state' is not a member of 'org.eclipse.smarthome.core.library.types.DecimalType'; line 13, column 55, length 47

I use influxDB for persistance:

Strategies {

    everyHour : "0 0 * * * ?"

    everyDay  : "0 0 0 * * ?"

    // if no strategy is specified for an Item entry below, the default list will be used

   default = everyChange

}

Items {

g*     : strategy = everyChange, restoreOnStartup //persist all direct members of the group 'group'

//item       : strategy = everyChange, everyHour // persist the item 'item'

//otherItem     // no strategy set, so use default strategy for item 'otherItem'

*          : strategy = everyChange, restoreOnStartup   // persist every item

}

persistance is working:
image
I tried a couple of averageSince command variants found in the forum, but all failed. can someone give me a hint whats wrong here?
thx

Log out the result of your averageSince. It is not an “historic object”, does not have a .state. It’s just a Number I believe.

logInfo("test", "db returns {}", Pool_Temp.averageSince(now.minusHours(1)) )

Don’t forget that goes to whichever persistence service you have set as the default, which may or may not be influxdb

Ok, it works, thanks. during my tests I never tried {}. it does not return a value without {}:

logInfo("test", "db returns {}", Pool_Temp.averageSince(now.minusHours(12)) )

logInfo("test", "db returns:", Pool_Temp.averageSince(now.minusHours(12)) )

logs:

2020-04-05 13:21:05.472 [INFO ] [.eclipse.smarthome.model.script.test] - db returns 7.565375522291510

2020-04-05 13:21:05.476 [INFO ] [.eclipse.smarthome.model.script.test] - db returns:

logInfo() requires only two strings, if you don’t use {} it has no idea to even look for the third or subsequent arguments.

Alternative approach, with just two strings

logInfo("test", "db returns:" + Pool_Temp.averageSince(now.minusHours(12)) ).toString

EDIT - fixed! thanks @Udo_Hartmann

logInfo("test", "db returns:" + Pool_Temp.averageSince(now.minusHours(12)).toString )
1 Like

.toString at the wrong round bracket :wink:

1 Like