How to keep item values between page refreshes?

Hey there -

I’m relatively new to OpenHAB and I’ve Googled all over the place for this. Maybe I just don’t get it. Anyways, I have some zwave door sensors hooked up to my Wink hub. When the door opens, the Wink hub sends an MQTT message saying “OPEN”, and when it’s closed, it says “CLOSED”. I’m storing this in a String item, and it’s displayed in my sitemap.

My problem is, that when my browser is opened up to OpenHAB, it gets the updates and it works great. If I hit F5 and reload it, the values disappear and the Strings go blank. If I open it up in a new tab, same thing: blank Strings.

I set up MySQL for persistence, but it doesn’t seem to immediately solve my problem. Still blank when I load it up. I opened up the database, and it is indeed getting every update logged into it.

How the heck do I make it load the last value in the database when I load the page for every item? Can someone give me an example please? I feel like this is stupid-easy, but I just don’t get it. I saw that there is an .previousState(), but I don’t know how to use it.

Thanks for the help!

In fact, there should be no need to do extra work. openHAB does an update to items only if it receives an update or command through a binding or through the UI.

Which version do you use? What is your item definition? Your Sitemap? Any rules belonging to the item?

Weird. Okay, I’ll give you my confs (there isn’t too much) I’m running Openhab 2.0 Beta 3. The other thing to note is that I’m also running my.openhab on there. On the my.openhab website, everything is mirrored perfectly, but same problem. When I reload, the String/Text items disappear. As I’m typing this, I’m realizing that they’re not just String/Text items, they’re also being populated through MQTT. I wonder if that has something to do with it?

I should note that the switch and the dimmer states all persist, just not the String/Text/MQTT items.

Thanks again!


rule "Milk Dash Button"
	Item milk received update
	publish ("pi","home/ac","power")

rule "Chunky Dash Button"
	Item chunky changed


Switch 	AC 	"AC" 		{mqtt=">[pi:home/ac:command:ON:power],>[pi:home/ac:command:OFF:power]"}
Switch 	AV	"AV Power"

String 	milk	"Dash - Milk"	{mqtt="<[pi:home/dash/milk:state:default]" }
String	chunky	"Dash - Chunky"	{mqtt="<[pi:home/dash/chunky:state:default]" }

String PlexTVStatus     "Status [%s]"   <video>     (plex) {plex="1e229444-7dc6-413f-ada9-5a76e2ba2dd0#state"}

Dimmer LinkLight_Bath1   	"Bathroom1 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/14/2/set:state:*:default]"}
Dimmer LinkLight_Bed1   	"Bed1 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/16/2/set:state:*:default]"}
Dimmer LinkLight_Bed2   	"Bed2 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/15/2/set:state:*:default]"}
Dimmer LinkLight_Table1   	"Table1 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/13/2/set:state:*:default]"}
Dimmer LinkLight_Kitchen1   	"Kitchen1 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/4/2/set:state:*:default]"}
Dimmer LinkLight_Kitchen2   	"Kitchen2 [%d %%]"  	<switch> (Wink) {mqtt=">[pi:home/5/2/set:state:*:default]"}

String FrontDoor	"Front Door" 		{mqtt="<[pi:home/6/7:state:default]"}
String Kitchen		"Kitchen Motion"	{mqtt="<[pi:home/7/7:state:default]"}

String Temp		"Temperature"		{mqtt="<[pi:home/7/43:state:default]"}


sitemap home label="My Home"{
 	Frame {
  		Switch item=AC
		Switch item=AV
  		Text item=milk
		Text item=PlexTVStatus
		Text item=chunky
	Frame {
		Slider item=LinkLight_Kitchen1
		Slider item=LinkLight_Kitchen2
		Slider item=LinkLight_Bed1
		Slider item=LinkLight_Bed2
		Slider item=LinkLight_Bath1
		Slider item=LinkLight_Table1
	Frame {
		Text item=FrontDoor
		Text item=Kitchen
	Frame {
		Text item=Temp

mysql.persist (same as myopenhab.persist)

Strategies {
    default = everyChange

Items {
    * : strategy = default, restoreOnStartup

Maybe it’s this known: issue
As I’m not very familiar with OH2 yet… no other idea :frowning:

I don’t think so :confused: It looks like that is just the items losing their formatting, rather than the value itself. Do you know how I would force a poll from mysql on page load? Or maybe every 2 seconds or something like that?

I don’t think constant polling of your persistence backend is going to solve your problem. As Udo mentioned, item values in OH should not be changing unless they are updated by the device. You should be able to see in the logs when an item changes.

What browser are you using? Have you tried a different one? Is the behaviour consistent in both Classic UI and Basic UI?

Yeah, I checked the events log and everything looks good. Here is a snippet:

2016-08-22 08:12:14.076 [ItemStateChangedEvent     ] - Kitchen changed from TRUE to FALSE
2016-08-22 08:28:18.059 [ItemStateChangedEvent     ] - Kitchen changed from FALSE to TRUE
2016-08-22 08:31:27.979 [ItemStateChangedEvent     ] - Kitchen changed from TRUE to FALSE
2016-08-22 09:34:49.721 [ItemCommandEvent          ] - Item 'AC' received command ON
2016-08-22 09:34:49.774 [ItemStateChangedEvent     ] - AC changed from OFF to ON
2016-08-22 09:35:35.719 [ItemCommandEvent          ] - Item 'AC' received command OFF
2016-08-22 09:35:35.758 [ItemStateChangedEvent     ] - AC changed from ON to OFF
2016-08-22 09:35:42.137 [ItemCommandEvent          ] - Item 'LinkLight_Kitchen1' received command 0
2016-08-22 09:35:42.178 [ItemStateChangedEvent     ] - LinkLight_Kitchen1 changed from 59 to 0
2016-08-22 09:35:42.543 [ItemCommandEvent          ] - Item 'LinkLight_Kitchen1' received command 0

But when I open up a browser, all of the text fields are blank. :frowning: Like I said before, all the sliders and switches values persist, and all of the data is in MySQL. One of the big things I need is to be able to open up OpenHAB and see the values of my sensors, ie: if I left a door open. I can’t wait until a new MQTT command is sent to find that out (since that will be when I come back home and close the door).

Behavior is consistent in Classic and Basic UI. I’ve been using Chrome, but I just tried Safari and it is exhibiting the same behavior. The reason I suggested the constant polling is because although ghetto and resource intensive, at least I’d be able to see them.

I’ve been thinking about having my Wink hub broadcast all of the MQTT values once every 10 seconds or so, but it’s not too powerful and I don’t want to put a strain on it.

Thanks again,