--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.
And I didn't really do anything to fix it.
It seems when I start the script it can't sync up with the rr database for after like 3 - 5 minutes.
Then it suddenly gets correct values. Error code for the first minutes:
"Error during the execution of rule 'PWR Consumption': cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null"
I've tried to change the time in "historicState(now().minusMinutes(60)" back and forth, and every time its the same error as above at first.
My theory is that either the rrd4j has to "adjust" to get the correct timestamps to match or it just syncs up somehow. But I don't know really :)
Heres the working rule:
rule "PWR Consumption"
when
Time cron "0 0 * * * ?" //Every Hour
then
val Number historic = pwrTotal.historicState(now().minusMinutes(60), "rrd4j").state as DecimalType
val Number current = pwrTotal.state as DecimalType
postUpdate(pwrHour, current - historic)
end
Cheers
Ivar
rule "taeglichen Gasverbrauch ermitteln"
when
Time cron "59 59 23 * * ?"
then
var Number currGas = Z_Gas.state as DecimalType
var State histState = Z_Gas.historicState(now().minusHours(24))
if (histState != null) {
prevGas = histState.state as DecimalType
var Number diff = currGas - prevGas
var String msg = "Gestriger Verbrauch : "+ diff.floatValue.toString + " m3"
sendXMPP( addr , msg)
}
end