Problems with deltaSince in rule

Hi everybody,

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:


rule "Kosten der letzten Stunde anzeigen"
  Item ArbZ_Strom_TV_Verbrauch changed
  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 €"))

rule "Kosten des letzten Tages anzeigen"
  Item ArbZ_Strom_TV_Verbrauch changed
  var kostenD = ArbZ_Strom_TV_Summe.deltaSince(now.minusHours(24))
  postUpdate(ArbZ_Strom_TV_SummeD, kostenD)
  logInfo("xy.rules", "Stromkosten / Tag (ArbZ TV): " + kostenD)

but something seems to be faulty in the second rule (“Kosten des letzten Tages anzeigen”)…


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

Maybe someone of you could help!?

Thanks in advance!

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"
  Item ArbZ_Strom_TV_Verbrauch changed
  var kostenD = ArbZ_Strom_TV_Summe.deltaSince(now.minusHours(24))
  logInfo("xy.rules", "Stromkosten / Tag (ArbZ TV): " + kostenD)

Thanks for your quick answer! You´re right - variable is coming up as null. But don´t realy understand, why…

2017-07-15 17:46:53.796 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Kosten des letzten Tages anzeigen': cannot invoke method public java.lang.String org.eclipse.smarthome.core.library.types.DecimalType.toString() on null
2017-07-15 17:46:53.802 [INFO ] [smarthome.model.script.cloudia.rules] - Stromkosten / Stunde (ArbZ TV): 0.0689129410999934315783320926129817962646484375

which persistence service are you using to store historical data for this item (ArbZ_Strom_TV_Summe) ?

I use rrd4j with this configuration:

Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay  : "0 0 0 * * ?"

    default = everyChange

Items {
    * : strategy = everyMinute, restoreOnStartup

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 :stuck_out_tongue:

Yeah, strange… :smiley:

There is data stored for the last 6 days.
Tried now.minusDays(1), but get the same error as above. Hmm.

try the REST API to check item’s persistence data:




by default, it will use: start time = 1 day before endtime. endtime = current time

you can change this in


Ah okay. There are 148 datapoints stored in that persistence, but can´t read that time format.

{"name":"ArbZ_Strom_TV_Summe","datapoints":"148","data":[{"time":1500096960000,"state":"81.3410156830444321940376539714634418487548828125"}, ... ,"state":"81.98284790234998808955424465239048004150390625"}]}

The second path you posted didn´t work for me.

I´m used to work with openhab 1.x and it´s kind of confusing working with the textual configuration of OH2. :slight_smile:

ah! maybe you haven’t installed the REST Documentation (Misc Addon)

yeah… I don’t know how I can help here :slight_smile: That timestamp is strange also for me.

It is like the standard linux epoch time, but in milliseconds rather than seconds.

1 Like

Ok, installed the binding and tried to understand, how I can change any values through restdocs…


But only get it managed to set a startTime string, which outputs some more time values.

After checking these with the epochconverter (thx @christoph_wempe) it truly seems that there are only historical values from today in my persistence.

In my charts all historical data (including the graphs for day and week) looks correct.


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

Yeah, sounds like a great idea… :slight_smile: Thx for your help

1 Like