I have trouble restoring the previous state for an item and send it back to my pulse energy meter on request.
I have tried to code below, but it gives me the following error:
Error during the execution of rule 'Arduino sends to Openhab': Could not invoke method: org.openhab.core.persistence.extensions.PersistenceExtensions.previousState(org.openhab.core.items.Item,boolean,java.lang.String) on instance: null
I’m using the persistence service provided by “my openhab”.
I’ve always wondered if my.openhab lets you query for historical data or whether it only publishes the data to enable the my.openhab service to work. Have you tried any of the other persistence such as rrd4j or db4o?
It is not clear from the documentation, but I have seen comments in other posts (not able to find them right now) that are pretty clearly stating that the my.openhab persistence service does not support restore/retrieve/query [take your pick].
2015-10-09 21:39:33.845 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Arduino sends to Openhab’: Could not invoke method: org.openhab.core.persistence.extensions.PersistenceExtensions.previousState(org.openhab.core.items.Item,boolean,java.lang.String) on instance: null
However when starting after a restart I see the following in my log:
2015-10-09 21:34:38.843 [DEBUG] [.p.internal.PersistenceManager] - Restored item state from 'Oct 9, 2015 9:28:00 PM' for item 'cellarWatt01' -> '2937'
2015-10-09 21:34:38.854 [DEBUG] [.p.internal.PersistenceManager] - Restored item state from 'Oct 9, 2015 9:28:00 PM' for item 'cellarKwh01' -> '35.5379999999999967030817060731351375579833984375'
2015-10-09 21:34:38.865 [DEBUG] [.p.internal.PersistenceManager] - Restored item state from 'Oct 9, 2015 9:28:00 PM' for item 'pulseCountItem' -> '35538'
So not sure how my pulseCountItem can be null here
You are not calling previousState with the correct arguments. You are passing now when you need to pass a boolean.
pulseCountItem.previousState(true, "rrd4j").state // gets most recent state that is different from the current state
pulseCountItem.previousState(false, "rrd4j").state // get the most recent update, even if it is the same as the current state
The underlying rules engine cannot convert the Joda time object “now” to a boolean so it passes a null instead is what I’m guessing is happening and why you got a null error. Maybe not.
I find it a little confusing that the documentation on the Persistence wiki page do not match what I’m seeing in Designer with <ctrl><space>. The wiki may be out of date.
Do you have more than one persistence binding configured and is that one the default one? If the answer is “no” to either question, try just previousState(true)
Is Rollo_test a Number, Switch, Contact, DateTime, or any other kind of Item that is represented by a Number? rrd4j will only store numerical data.
Are you saving the value for Rollo_test using an everyMinute strategy? Charting and the persistence methods tend not to work very well unless you save items once per minute, even if it only changes once per hour.
Well I’m stumped. I’ve used rrd4j since I started using OH and I’ve never seen this error. I wonder if the DB became corrupt or something of the sort.
Try to clear out and recreate your persistence store to see if the error goes away or changes.
Stop openHAB, move /var/lib/openhab/persistence/rrd4j to a temporary folder, and restart openHAB. It should recreate the DBs from scratch from that point forward. If everything starts working then we found the problem. If not, I’m out of ideas.
Hello, same problem here. I try to store and recover the value of a number with the following rule:
Item MyNumb changed
logInfo("MyNumb.CurrentState = ", MyNumb.state.toString )
This leads to the following error:
2015-11-16 19:06:08.959 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘test_numero’: rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested
I know that something is working beacuas when I stop and restart OH tha value of the number is restored.
In my ubuntu installation I do not find the file /var/lib/openhab/persistence/rrd4j.
Running into the same problem. Tried blowing away the old rrd files, still getting:
2015-12-16 07:14:46.085 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Today Water Used': rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested
rule "Today Water Used"
Item Water_Meter changed
val double current_meter = Water_Meter.state
val double previous_meter = Water_Meter.previousState(true).state
val double today_water_used = if(Today_Water_Used.state == Uninitialized) 0 else Today_Water_Used.state
postUpdate(Today_Water_Used, today_water_used + (current_meter - previous_meter))
rule "Today Water Used Reset"
Time cron "59 59 23 * * ?"
The best to use depends on what you want to do with it. rrd4j doesn’t support Switches and Contacts anymore so that one is not a good choice. Mapdb only saves the most recent state and is an excellent choice for restoreOnStartup or if all you care about is the time of the most recent update to the Item.
Beyond that I can’t tell you what is the “best” because it depends on what you want to with the data and your level of experience.
Thanks for Information and patterns. I have Plex and when I start movie my lights go to wanted scene. When I press stop I want to get back states before I press start. As I understand rrd4j can’t help me as mapdb too or i wrong?