[SOLVED] Problem with accessing persisted data

I am running openHAB 1.7.1 on a Raspberry Pi 2. I have installed the binding for rrd4j persistence, and configured a strategy to persist data from my electricity meter every minute.

Using HABmin I am able to chart the persisted data so I assume the persistence as such is working OK. One funny thing, though: When looking at the table view of data in HABmin there is only values for every 4 minutes - not every minute as I have set in the rrd4j.persist file.

Anyway, I am trying to build a rule to pick up some historic data from the persistence service (like the average, maximum and minimum power usage for last 24 hours, 7 days, etc.).

For this purpose I have the following items:

Number  nPower
Number  nPowerAverage24h
Number  nPowerMaximum24h
Number  nPowerMinimum24h

And the following rule:

import org.openhab.core.types.*
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.joda.time.*

rule "Power"
    Item S01D012_nPower changed
    var Number Power = S01D012_nPower.state as DecimalType
    postUpdate(nPower, Power)

    // Calculate values for last 24 hours (using 5 minutes while testing)
    if (S01D012_nPower.historicState(now().minusMinutes(5)) != null) {
        var Number PowerAverage = S01D012_nPower.averageSince(now().minusMinutes(5)).state as DecimalType
        var Number PowerMaximum = S01D012_nPower.maximumSince(now().minusMinutes(5)).state as DecimalType
        var Number PowerMinimum = S01D012_nPower.minimumSince(now().minusMinutes(5)).state as DecimalType
        postUpdate(nPowerAverage24h, PowerAverage)
        postUpdate(nPowerMaximum24h, PowerMaximum)
        postUpdate(nPowerMinimum24h, PowerMinimum)

Now, my problem is that I end up with the following ERROR in the openhab.log file:

2015-09-10 23:08:36.222 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Power’: The name ‘.state’ cannot be resolved to an item or type.

It would be great if someone could help me resolve this issue, as I am more or less stuck.

Problem solved. Apparently the averageSince()-method returns a number and consequently has no .state-member. The maximumSince- and minimumSince-methods, however, return Items and thus the .state-member must be accessed to get to the actual value.

Looking at it now, I guess it is kind of logical. I just wish such details were documented somewhere, :frowning: