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
org.eclipse.smarthome.persistence:default=mysql
then .previousState().state works. Really weirdâŠ
Somehow the historic state works when I specify the mysql
.historicState(now.minusMinutes(60), âmysqlâ).state
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
.previousState(true, âmysqlâ).state
.previousState(false, âmysqlâ).state
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.
WORKS
.previousState().state
.previousState(true,âmysqlâ).state
.previousState(false,âmysqlâ).state
DOESNT WORK
.previousState(âmysqlâ).state
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
.previousState(true).state
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
myItem.previousState(true)
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.
The thing about mapdb is that previousState is meaningless. It holds the ânowâ state. You certainly cannot get the âprevious state that was different to nowâ.