[SOLVED] Get sum since period of time from item type number:power

openHAB version: 3.2

I want to calculate my power usage since 7 days from my smartmeter item SmartMeter_101670 which is type number:power and stored in influxdb persistence. i can also view all values in a defined period coming from influxdb from a page. The influxdb-UI also shows me the correct values. When i try to calculate my usage with the “.sumSince” function i always get zero/ nothing from my persistence service.

house_usage7d.postUpdate(SmartMeter_101670.sumSince(now.minusDays(1), "influxdb"))

When i change the my item SmartMeter_101670 to plain number type it also returns zero/ nothing.

Does anybody know where my mistake is?

See if you have basic function, before trying to do all in one.

var results = SmartMeter_101670.historicState(now.minusDays(1), "influxdb")
if (results === null) {
   logInfo("test", "No return")
} else {
   logInfo("test", "return {}", results)

thanks for the hint!
it returned:

return [FAILED toString()]

I’d be surprised if you don’t get entries in your openhab.log to go with that.

Some part of the processing within OH persistence service has gone wrong. It’s the kind of thing you see if an Item type has been changed, and stored data no longer suits live Item.

You might try with a brand new Item to see if it is along those lines.

EDIT - in another thread, it looks like
logInfo("test", "return {}", results)
is misbehaving somehow.
Try instead

logInfo("test", "return state ", results.state.toStrng)
logInfo("test", "return stamp ", results.getTimestamp.toStrng)

i have now recreated the item and the influxdb database and still don’t get any data back…
the rule results (NULL):

2022-01-17 23:25:33.968 [INFO ] [org.openhab.core.model.script.test  ] - return state 

2022-01-17 23:25:33.970 [INFO ] [org.openhab.core.model.script.test  ] - return stamp

but influxdb has data …

Thanks for the help, i have found the solution with this topic: OH3: Error trying to retrieve historical data from influxdb

the problem is that openhab does not handle underscores correctly. so you are not allowed to use underscores in the bucket name with influxdb2.x. i have now recreated my bucket and now it works!
thanks again to @rossko57.
the command to debug was:

logInfo("test", "return state {}", results.state.toString())
logInfo("test", "return stamp {}", results.getTimestamp.toString())

Yes, at the moment the only workaround is not naming your default policy/bucket with underscores. Not that this fact is mentioned anywhere.
Funny thing is, persisting works, just the query to the database does not.