OpenHab 2.4 previousState and previousState return same (incorrect) state

I have openhab 2.4 running on a raspberry Pi 2 using the openhabian image. I just upgraded openhab from version 2.3 to version 2.4. Before that all my rules worked just fine.

I now have the problem that previousState and previousState(true) no longer return a historic state other than the latest one in my database. I am using sqlite with jdbc as persistence service. This works fine as I verified the contents of the database with the sqlite command line utility. I have a MAX heating item that I use with the homematic binding and homegear. The item has 3 entries in its persistence table:

sqlite> select * from item0013;
2018-12-21 18:40:44.060|20.0
2018-12-21 19:21:23.907|12.0
2018-12-21 19:37:41.462|21.0

As you can see I have three different states for this item in the database.

Here are some basic rules and their log output

logInfo("heating.rules", "Heating contact alert")
logDebug("heating.rules", "Buero status " + Thermostat_buero_1_SetTemperature.state)
logDebug("heating.rules", "Buero previous state  " + Thermostat_buero_1_SetTemperature.previousState().state + " datetime: " + Thermostat_buero_1_SetTemperature.previousState().getTimestamp())
logDebug("heating.rules", "Buero previous state true " + Thermostat_buero_1_SetTemperature.previousState(true).state + " datetime: " + Thermostat_buero_1_SetTemperature.previousState(true).getTimestamp())
logDebug("heating.rules", "Buero historic state " + Thermostat_buero_1_SetTemperature.historicState(now.minusMinutes(70)).state + " datetime: " + Thermostat_buero_1_SetTemperature.historicState(now.minusMinutes(70)).getTimestamp())

here is the log output

2018-12-21 20:27:09.579 [INFO ] [smarthome.model.script.heating.rules] - Heating contact alert

2018-12-21 20:27:09.587 [DEBUG] [smarthome.model.script.heating.rules] - Buero status 21.00 °C

2018-12-21 20:27:09.602 [DEBUG] [smarthome.model.script.heating.rules] - Buero previous state  21.0 datetime: Fri Dec 21 19:37:41 CET 2018

2018-12-21 20:27:09.620 [DEBUG] [smarthome.model.script.heating.rules] - Buero previous state true 21.0 datetime: Fri Dec 21 19:37:41 CET 2018

2018-12-21 20:27:09.644 [DEBUG] [smarthome.model.script.heating.rules] - Buero historic state 20.0 datetime: Fri Dec 21 18:40:44 CET 2018

So as you can see both previousState commands return the wrong state. it is the current state they return. But querying the persisted seems to work correctly with the historicState function.

here is the persistence config.

Strategies {
  default = everyChange

Items {
  * : strategy = everyChange, restoreOnStartup

All items in question were created with paper ui.

Anyone an idea whats going on? I used previousState(true) with openHab 2.3 successfully.

One thing comes to my mind tough. I had to update or better said I had to set up all my MAX heater items again after the update because the channel for setting the temperature had changed from type number to number:temperature. Might this be the problem? But I already deleted all items and MAX things and started over. I also let openhab jdbc create a complete new persistence database.

are you using multiple persistence services or only 1 (the jdbc:sqlite)?

if multiple: which one is set as default?

Thanks for your reply. jdbc is indeed the default and only persistence service I am using


You seem to know what you are doing, so my only suggestion would be: open up a github issue here: (check if one exists already) with all the info that would be required for a developer to reproduce this.

I don’t see any mistake in your configs… (and I don’t remember any change from 2.3 to 2.4 that would affect this previousState behavior)

Also: UoM (number:temperature) should have no effect on this.

I can’t find a issue or solution, but I’ve the same problem as @0x2a has (or had?) . I’m using OH 2.5M3:

	logInfo("rule","current value " + LivingRoom_Heating_Setpoint_Current.state.toString)
	logInfo("rule","PreviousState true "+LivingRoom_Heating_Setpoint_Current.previousState(true,"influxdb").state.toString+" time: "+ LivingRoom_Heating_Setpoint_Current.previousState(true,"influxdb").getTimestamp)
	logInfo("rule","PreviousState false "+LivingRoom_Heating_Setpoint_Current.previousState(false,"influxdb").state.toString+" time: "+ LivingRoom_Heating_Setpoint_Current.previousState(false,"influxdb").getTimestamp)
2019-10-16 22:56:52.634 [INFO ] [.eclipse.smarthome.model.script.rule] - current value 23.0 °C
2019-10-16 22:56:52.668 [INFO ] [.eclipse.smarthome.model.script.rule] - PreviousState true 23.0 time: Wed Oct 16 22:50:10 CEST 2019
2019-10-16 22:56:52.706 [INFO ] [.eclipse.smarthome.model.script.rule] - PreviousState false 23.0 time: Wed Oct 16 22:50:10 CEST 2019
InfluxDB shell version: 1.7.8
> select * from LivingRoom_Heating_Setpoint_Current
name: LivingRoom_Heating_Setpoint_Current
time                value
----                -----
1571224706134000000 22
1571256470189000000 24
1571256520091000000 23
1571257395713000000 18
1571257525769000000 22
1571257716368000000 19
1571259010181000000 23

Does anybody know if this is a bug?
If needed I’ll issue it, but I’m a newbie so please tell me how (or show me a guide which tells me how :wink: )