actually I am playing with Persistence Extensions for Rules. I thought I started simple with the following rule:
rule "Temperaturtest"
when
//Time cron is "0 0 0/1 1/1 * ? *" //stündlich
Time cron is "0 42 12 1/1 * ? *"
then
logInfo("rules","Temperatur vor einer Stunde:" +HK_WEATHER1Kizi_Temperature.historicState(now.minusHours(1),"rrd4j"))
end
I am trying to get a log message with the temperature before one hours. I get the following log:
12:42:04.667 [INFO ] [eclipse.smarthome.model.script.rules] - Temperatur vor einer Stunde:org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@acb281
I am using rrd4j (defined as standard) and JDBC as persistence services. Without
I had the same. The quotes around rrd4j are breaking the logInfo statement
Out the historic state you want to log into a variable first, and use the new variable in your logInfo Statement.
Thank you for your help, but I have tried it with the same result:
14:55:04.561 [INFO ] [eclipse.smarthome.model.script.rules] - Temperatur vor einer Stunde:org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@192272d
Changed the rule to:
rule "Temperaturtest"
when
//Time cron is "0 0 0/1 1/1 * ? *" //stündlich
Time cron is "0 55 14 1/1 * ? *"
then
var Number temphist
temphist=HK_WEATHER1Kizi_Temperature.historicState(now.minusHours(1),"rrd4j")
logInfo("rules","Temperatur vor einer Stunde:" +temphist)
end
var Number temphist = (HK_WEATHER1Kizi_Temperature.historicState(now.minusHours(1), "rrd4j").state as DecimalType)
Other than that I guess you’ve already checked that rrd4j is properly persisting the data. Did you check the graph and data from last hour is available?
15:09:04.511 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Temperaturtest: cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
and without .state (but with as DecimalState)
15:12:04.934 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Temperaturtest: org.eclipse.smarthome.core.library.types.DecimalType
Datas are saved with rrd4j. That I have checked for sure.
val Number temphist=(HK_WEATHER1Kizi_Temperature.historicState(now.minusHours(1),"rrd4j")).state
logInfo("rules","Temperatur vor einer Stunde: " +String.format("%.2f",(temphist).floatValue()))
I’m trying the same thing but solution doesn’t appear to work for me , its still returning a object value:
org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@247e1164
I have:
msg += "Historical value (6 hours ago: " + Hotwater_temperature.historicState(now.minusHours(6))
or
val oldtemp= Hotwater_temperature.historicState(now.minusHours(6))
msg += "Historical value (6 hours ago: " + String.format("%.2f",(oldtemp))