Org.openhab.core.persistence.HistoricItem.getState() on null

Running into:

2015-12-09 17:18:42.386 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Today Water Used': cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null

My test line is:
logInfo(“Testing”, "Water_Meter = " + Water_Meter.previousState(true).state)

I verified that Water_Meter is being stored in db4o and that is my default persistence for openhab.

Finally found the solution:

“Every rule that has at least one status change event trigger, will have the variable previousState available, which can be used inside the execution block.”

I was not using changed as a trigger for my rule.

Hi @sipvoip,

could you please specify, what you did wrong?
I don’t get the point :frowning:

The triggering rule has to be “changed” vs. “received update” for example. I’m running into this also right now implementing .previousState.state

Best, Jay

Thanks. That’s an old post though.
It’s nice to see people being active here ince ages :wink:
That’s why I am always coming back.

By the way: Nowadays I am using previousState a lot as well.
Some in Blockly some in DSL.