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"
when
Time cron "0 1 0 * * ?" // every day at midnight, 00:01
then
Power01KwHDaily.postUpdate(Power01KwHDay)
Power01KwHDay.postUpdate(0.00)
end
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(XbaseInterpreter.java:738) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713) ~[na:na]
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.