Rule to reset at midnight not working?

II’m sure I’ve got something very simple very wrong here…

I’m counting up KwH usage and what I want to do is reset it back to 0.00 every night so that I get some nice per day charts. but the code below doesn’t seem to work? It should be running at 0:01 ever day but doesn’t work…

rule "Clear daily KwH consumption"
		Time cron "0 1 0 * * ?"  // every day at midnight, 00:01

I use this for my daily resets…

rule "Reset daily energy counters"
    Time is midnight

Here is mine:

rule "Clear daily consumption"
Time cron "0 0 0 * * ?" // every day
	postUpdate(DailyEnergyConsumption, 0)

Thanks guys, I think my timed rule was working but there is something wrong with the first line after the “then”…

2016-08-17 00:21:00.218 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Clear daily KwH consumption 2
java.lang.IllegalStateException: Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,org.openhab.core.types.State) on instance: null
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation( ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation( ~[na:na]

Is there an easy way to do a NULL check somehow?

rule "init"
    System started or
    Time is midnight
then {
    createTimer(now.plusSeconds(120)) [|
        if (item.state == NULL) item.postUpdate(0)

I think you may need to use the following instead:

1 Like


Sorry I didn’t catch this, could we say that


is equivalent to:

postUpdate(Power01KwHDay, 0)


Ummmm… I don’t think so.

  • Power01KwHDaily.postUpdate(Power01KwHDay.state)
    Power01KwHDaily is an item and Power01KwHDay.state is the current value of the Power01KwHDay item

is equivalent to:

  • postUpdate(Power01KwHDaily, Power01KwHDay.state)
    Power01KwHDaily is again an item and Power01KwHDay.state is the new value you are to the Power01KwHDaily.

In the first one you are calling to the postUpdate method of the Power01KwHDaily item, you can consider it as an action of the item itself. The second one is a generic postUpdate action, so you need to specify the item who’s value you want to update and the new value itself.

The syntax that you have used (postUpdate(Power01KwHDay, 0)) will update the status of the Power01KwHDay item to 0, and as you can see, the Power01KwHDaily items value is not referenced nor used.

Is it more clear now? :wink:

If you are still confused, don’t hesitate to ask!

yes thankyou :slight_smile: