[Solved] Some persistence extensions in rules not working

I’m trying to use the persistence extensions in a rule like described here

I’m on a very late openhab 2 snapshot release and using Influx-db as persistence service which is working fine.
I’m persisting an number item for power usage every 5min.

But some persistence extensions in rules are not working.
“maximumSince”, “minimumSince”, “historicState” for example are working. “sumSince”, “averageSince”, “deltaSince” are not working.

My Code:

    rule "Get Power usage of the last 24h"
    when
        Item Powermeter received update
    then
        
        var pl24h1 = (Powermeter.lastUpdate).state  as DecimalType       // - Query for the last update timestamp of a given item.
        logInfo("lastUpdate: ", pl24h1.toString )
        var pl24h2 = (Powermeter.historicState(now.minusDays(1))).state as DecimalType// - Retrieves the state of the item at a certain point in time
        logInfo("historicState: ", pl24h2.toString )
        var pl24h3 = (Powermeter.changedSince(now.minusDays(1))).state as DecimalType // - Checks if the state of the item has (ever) changed since a certain point in time
        logInfo("changedSince: ", pl24h3.toString )
        var pl24h4 = (Powermeter.updatedSince(now.minusDays(1))).state as DecimalType // - Checks if the state of the item has been updated since a certain point in time
        logInfo("updatedSince: ", pl24h4.toString )
        var pl24h5 = (Powermeter.maximumSince(now.minusDays(1))).state as DecimalType  // - Gets the maximum value of the state of the item since a certain point in time
        logInfo("maximumSince: ", pl24h5.toString )
        var pl24h6 = (Powermeter.minimumSince(now.minusDays(1))).state as DecimalType // - Gets the minimum value of the state of the item since a certain point in time
        logInfo("minimumSince: ", pl24h6.toString ) 
        var pl24h7 = (Powermeter.averageSince(now.minusDays(1))).state as DecimalType // - Gets the average value of the state of a given item since a certain point in time.
        logInfo("averageSince: ", pl24h7.toString )
        var pl24h8 = (Powermeter.deltaSince(now.minusDays(1))).state  as DecimalType   // - Gets the difference value of the state of a given item since a certain point in time.
        logInfo("deltaSince: ", pl24h8.toString )
        var pl24h9 = (Powermeter.previousState()).state as DecimalType                 // - Retrieves the previous state of the item (returns HistoricItem).
        logInfo("previousState: ", pl24h9.toString )
        var pl24h10 = (Powermeter.previousState(true)).state as DecimalType             // - Retrieves the previous state of the item, skips equal state values and searches the first state not equal the current state (returns HistoricItem).
        logInfo("previousState: ", pl24h10.toString )
        var pl24h11 = (Powermeter.sumSince(now.minusDays(1))).state as DecimalType // - Retrieves the sum of the previous states since a certain point in time. (OpenHab 1.8)
        logInfo("sumSince: ", pl24h11.toString )

In the log I’m getting such an error with not working extensions:

[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Get Power usage of the last 24h': An error occured during the script execution: The name '<XMemberFeatureCallImplCustom>.state' cannot be resolved to an item or type.

Found the explanation here

Working code (with clarified comments, also updated in the wiki page):

var pl24h1 = Powermeter.lastUpdate                                           // - Query for the last update timestamp of a given item.
        logInfo("lastUpdate: ", pl24h1.toString )
        
        var pl24h2 = (Powermeter.historicState(now.minusDays(1))).state as DecimalType //Retrieves the historic item at a certain point in time
        logInfo("historicState: ", pl24h2.toString )
        
        var pl24h3 = Powermeter.changedSince(now.minusDays(1))                         // - Checks if the state of the item has (ever) changed since a certain point in time
        logInfo("changedSince: ", pl24h3.toString )
        
        var pl24h4 = Powermeter.updatedSince(now.minusDays(1))                         // - Checks if the state of the item has been updated since a certain point in time
        logInfo("updatedSince: ", pl24h4.toString )
        
        var pl24h5 = (Powermeter.maximumSince(now.minusDays(1))).state as DecimalType// - Gets the item with the maximum value (state) since a certain point in time
        logInfo("maximumSince: ", pl24h5.toString )
        
        var pl24h6 = (Powermeter.minimumSince(now.minusDays(1))).state as DecimalType// - Gets the item with the minimum value (state) since a certain point in time
        logInfo("minimumSince: ", pl24h6.toString ) 
        
        var pl24h7 = Powermeter.averageSince(now.minusDays(1))                         // - Gets the average value of the state of a given item since a certain point in time.
        logInfo("averageSince: ", pl24h7.toString )
        
        var pl24h8 = Powermeter.deltaSince(now.minusDays(1))                          // - Gets the difference value of the state of a given item since a certain point in time.
        logInfo("deltaSince: ", pl24h8.toString )
        
        var pl24h9 = (Powermeter.previousState()).state as DecimalType                 // - Retrieves the previous item (returns HistoricItem).
        logInfo("previousState: ", pl24h9.toString )
        
        var pl24h10 = (Powermeter.previousState(true)).state as DecimalType             // - Retrieves the previous item, skips items with equal state values and searches the first item with state not equal the current state (returns HistoricItem).
        logInfo("previousState: ", pl24h10.toString )
        
        var pl24h11 = Powermeter.sumSince(now.minusDays(1))                             // - Retrieves the sum of the previous states since a certain point in time. (OpenHab 1.8)
        logInfo("sumSince: ", pl24h11.toString )
1 Like