Issue of the topic:
Whenever I try to access the previous state of a variable in the rule I get the following error in the logs
2020-08-25 18:01:30.448 [WARN ] [nce.extensions.PersistenceExtensions] - There is no default persistence service configured!
2020-08-25 18:01:30.449 [WARN ] [nce.extensions.PersistenceExtensions] - There is no queryable persistence service registered with the id ‘null’
I have two persistence services configured as following
I can see that mysql has the records of every change in the table
| 2020-08-25 17:26:10 | 24 |
| 2020-08-25 17:31:15 | 45 |
| 2020-08-25 17:39:07 | 86 |
| 2020-08-25 17:45:35 | 60 |
| 2020-08-25 17:55:20 | 34 |
| 2020-08-25 18:00:30 | 64 |
| 2020-08-25 18:01:29 | 92 |
61 rows in set (0.00 sec)
But for some reason the OH throws an error that “There is no default persistence service configured!”
There are several topics in the forum that discuss default persistence including how to configure it. For example:
You need to make sure you either specify which persistence service to use in your attempt to access the previous state or have OH configured to use one of the services in the absence of a more specific call.
Apparently if I set .previousState(“mapdb”).state or .previousState(“mysql”).state it does not work and produces the same error,
However if I define globally the
then .previousState().state works. Really weird…
Somehow the historic state works when I specify the mysql
Apparently you MUST specify true or false when retrieving previousState. I don’t think it is mentioned in the manual
so the correct statement is
I am testing using the following statement
logInfo("ALARM2: ", "previous " + sens_vibr02_angle_x.previousState().state)
persistence default is set to mapdb. I have both mysql and mapdb persistence enabled.
2020-08-28 13:04:53.110 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘vibration strength notification’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions.pr
eviousState(org.eclipse.smarthome.core.items.Item,boolean) on instance: null
2020-08-28 13:07:41.265 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘vibration strength notification’: cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
Okay, if mapdb is your default then
just cannot work. Mapdb has no other state than the one it currently holds, so you cannot retrieve the state before.
Not all the standard persistence functions make sense for any particular database.
Of course, any given previousState might return null if there is no record e.g. when persisting once a month.
I do not know if the way that you have chosen to set the default produces any different result to the recommended way.
It’s a bit nuts having mySQL doing restore as well as mapdb, but that’s not related here.
I would have thought that even with the mapdb it should be possible to retrieve the last value. Providing that the new value is not yet written to the mapdb, it will contain the previous state.
re mysql and restoreonstartup, i remember i had a problem a while back when I just started playing with persistence, but I guess it might have been due to the fact that I didn’t set the default persistence and set mapd in .perstist file only. But you are right, restoring from both sources doesn’t make any sense.
no problems left with persistence, and thanks for your help.