I use openHABianPi with opeHAB 2.1.0 stable and I´d like to display the energy costs in the different time-periods (hourly, daily, weekly, monthly). I created some items and this rule to display the historic states:
energy.rules
rule "Kosten der letzten Stunde anzeigen"
when
Item ArbZ_Strom_TV_Verbrauch changed
then
var kostenH = ArbZ_Strom_TV_Summe.deltaSince(now.minusMinutes(60))
postUpdate(ArbZ_Strom_TV_SummeH, kostenH)
logInfo("xy.rules", "Stromkosten / Stunde (ArbZ TV): " + kostenH.toString.format("%.2f €"))
end
rule "Kosten des letzten Tages anzeigen"
when
Item ArbZ_Strom_TV_Verbrauch changed
then
var kostenD = ArbZ_Strom_TV_Summe.deltaSince(now.minusHours(24))
postUpdate(ArbZ_Strom_TV_SummeD, kostenD)
logInfo("xy.rules", "Stromkosten / Tag (ArbZ TV): " + kostenD)
end
but something seems to be faulty in the second rule (“Kosten des letzten Tages anzeigen”)…
*.log
2017-07-15 17:33:49.857 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Kosten des letzten Tages anzeigen': The argument 'state' must not be null or empty.
2017-07-15 17:33:49.935 [INFO ] [smarthome.model.script.cloudia.rules] - Stromkosten / Stunde (ArbZ TV): 0.097029999999997573462314903736114501953125
move the logInfo above the postUpdate and check if the kostenD variable is not coming up as null (or empty)
rule "Kosten des letzten Tages anzeigen"
when
Item ArbZ_Strom_TV_Verbrauch changed
then
var kostenD = ArbZ_Strom_TV_Summe.deltaSince(now.minusHours(24))
logInfo("xy.rules", "Stromkosten / Tag (ArbZ TV): " + kostenD)
ArbZ_Strom_TV_SummeD.postUpdate(kostenD)
end
strange…
obviously there are data for 1 hour back (since you get a delta result from the first rule)
maybe? there are no data available for 1 day back?
have you persisted long enough (more than 1 day) the state of this item?
try also: now.minusDays(1) … but I don’t think that this will make any difference
If you want a really robust time-series DB, I recommend Influx and use this as your secondary persistence service. You can then use Grafana for advanced graphs.
More here: InfluxDB+Grafana persistence and graphing