Design Pattern: Group Based Persistence

Okay, there’s data for today. Is your rule trying to get data for the same Item?

yes, there are several entries for today and using the query
var Number n_AvgTempDay=myActualTemp.averageSince(now.withTimeAtStartOfDay,"mysql")
shall return the average of today.

Okay, what’s your problem?

I got the problem, there was one Item that did not have a temperature persistent. Now it is working.

Thanks for pointing me to the right direction.
Martin

1 Like

I would like to use Group Based Persistence in OH3.4. In my example I have put the items StromHaus_Verbrauch/StromHaus_Zaehlerstand into the group gPersistenceMysql, but for these items the default persistance is still used as my rule gives following error:
[WARN ] [nce.extensions.PersistenceExtensions] - There is no default persistence service configured!
[WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id ‘null’
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘d3745560f2’ failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null

Any idea what is wrong?

jdbc.persist

Strategies {
    // if no strategy is specified for an item entry below, the default list will be used
    everyMinute : "0 * * * * ?"
    every5Minutes : "0 */5 * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
    default = everyChange
}

Items {
    gPersistenceMysql* : strategy = everyUpdate
}

rrd4j.persist

Strategies {
    // if no strategy is specified for an item entry below, the default list will be used
    everyMinute : "0 * * * * ?"
    every5Minutes : "0 */5 * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
    default = everyChange
}

Items {
    gPersistenceRrd4j* : strategy = everyUpdate, everyMinute
} 

I think I have found the issue. MyItem.previousState() is always using the default presistence service independent what is defined in the .persist file.
So it is mandatory in my case to use MyItem.previousState(“jdbc”).

There is no way to define a default persistence service in a .persist file. That’s a separate setting. In MainUI you can find it under Settings → Persistence. Choose which service you want to be the default there and that’s what will be used when you don’t otherwise specify a persistence service in your calls.

I would have expected that MyItem.previousState() will use the right persistence service what is defined over the .persist files. But this is not the case, you need to use MyItem.previousState(“jdbc”) if the default persistence service is RRD4J.