Question on how to apply persistence

  • Platform information: Ubuntu 16.04
    • Hardware: DELL 8core with 8GB of RAM
    • OS: Ubuntu 16.04
    • Java Runtime Environment: java version “1.8.0_171”
    • openHAB version: 2.3.0
  • Issue of the topic: How to apply persistance

I am trying to calculate the average net power consumption (PC generation - usage) over minutes.

In a rules file, which is generally working well (triggered time based every minute), I made the following statement:

var net_avg_consumption = SolarLogMeter_ConsumptionPAC.averageSince(now.minusMinutes(avg_time)) -
                              SolarLogMeter_PDC.averageSince(now.minusMinutes(avg_time))

Whereas “SolarLogMeter_ConsumptionPAC” and “SolarLogMeter_PDC” are defined items in Paper UI and I can read them.

I defined persistence in paper UI using rrd4j as the default persistence service (in Configuration/System)

In /etc/openhab2/persistence i created a file named rrd4j.persist with the following content:

Strategies {

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

Items {
        // persist the Item states of items indicated below on every change and restore them from the db at startup
        TeslaModelS_Charge, SolarLogMeter_ConsumptionPAC, SolarLogMeter_PDC: strategy = everyChange, restoreOnStartup
}

Based on that, the result of the above calculation is always “null”. Hence I assume, that there are no values.

If I add in the rules file, the following statements:

SolarLogMeter_PDC.persist
SolarLogMeter_ConsumptionPAC.persist

The above average calculation works. But I think this is not the right way to implement it - is it?

Can someone help me to correctly implement that?

Thanks
Heinz

The strategy everyMinute (60 seconds) has to be used, otherwise no data will be persisted (stored).

rrd4j HAS to be persisted every minute:

Strategies {

        // if no strategy is specified for an Item entry below, the default list will be used
       everyMinute : "0 * * * * ?"
       default = everyChange
}

Items {
        // persist the Item states of items indicated below on every change and restore them from the db at startup
        TeslaModelS_Charge, SolarLogMeter_ConsumptionPAC, SolarLogMeter_PDC: strategy = everyMinute, everyChange, restoreOnStartup
}

After changing a persist file, I recommend to restart OH but it’s not always necessary.

Thanks a lot.

So, the 2 lines in the rules files should NOT be necessary then?

Heinz

Thats right!

Yep, start/stop worked!
Thanks