Sitemap and Persistence Not Working As Expected


I’m just getting started with openHAB2. Please forgive me if these questions have already been addressed in another post. I’ve spent a few days searching through the forum and haven’t come up with any answers.

I’ve managed to get my onkyo receiver set up to send power on/off and volume commands. Now, I’m working to set up a z-wave door sensor. I purchased an aeon labs z-wave stick and an ecolink door sensor.

First, I’d like to get one point of confusion out of the way.
I added the Onkyo, z-wave stick, and z-wave door sensor as Things through PaperUI. As I activated the Channels I want to use, I also chose to link the channels to new Items. So my Items are also defined in PaperUI. With this in mind, is there any need to also define the item in a .items text file? From what I’ve seen in my testing, it doesn’t look like I have to define them in a text file. But I’m wondering what the best practice is. If the item is defined in a text file AND PaperUI, do I now have two items linked to the same channel, or is openHAB smart enough to know that the same item is defined in two places?

Regarding the sitemap file, I have the following:

sitemap main label="Main" {
	Frame label="Living Room TV"{
		Switch item=TXNR709_Zone1_Power label="Receiver Power" icon=switch 
		Setpoint item=TXNR709_Zone1_Volume label="Receiver Volume" icon=soundvolume
	Frame label="Security"{
		Text item=FrontDoorSensor_BinarySensor label="Front Door Sensor" icon=door
		Text item=FrontDoorSensor_BatteryLevel label="Front Door Battery" icon=battery

I’ve changed the default sitemap in BasicUI to use my main.sitemap file. The onkyo items work as expected. When I load the webpage, I see the current state of power and volume. However, the door sensor items do not report state when the page first loads. If I open or close the door, the webpage updates with the correct sate. But when I refresh the page, the sate is lost. As for the battery state, I can’t figure out any pattern as to when it will display the battery percent. Occasionally it’s there but most of the time I just have an icon of a green battery.

I thought my sitemap problems might be an issue with persistence, so I added mapdb through PaperUI and created the following mapdb.persist file from an interesting post I found here:

Strategies {
	 default = everyUpdate

Items {
	// persist all items on every change and restore them from the db at startup
	* : strategy = everyChange, restoreOnStartup

This has not solved the problem with the sitemap.

Also, I enabled debug logging for mapdb so I could see what’s going on. I can see it storing the state when the door is opened or closed:

2017-01-19 07:47:03.796 [DEBUG] [pdb.internal.MapDBPersistenceService] - store called for FrontDoorSensor_BinarySensor
2017-01-19 07:47:03.811 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'FrontDoorSensor_BinarySensor' with state 'OFF' in mapdb database

Should I also be able to see the restore on startup being logged when openHAB is started? I’m not seeing that in the log. I only see that mapdb is started and has been activated.


No need to define your items also in a text file.
You can use Paper UI for working with items and you can run OH2 without any .items flat text configuration file.
Many people who use “older” bindings that don’t use the ESH Thing concept or are migrating from OH1 are using config files for items.

If it has the same name, the one from the .items file will take precedence and you won’t be able to modify it from Paper UI (only from the file). If you have an existing item defined and try to create a new one in Paper UI with the same name, you will get a warning: “Item name already exists”.

If the item has a different name, openHAB will use both items (the one defined in Paper UI and the one from the .items file). In this case, you can link the 2 items to the same channel of a Thing if you want.

Keep in mind that Z-Wave battery based devices will need some time after OH2 restarts to report their status.
If you perform an action on the device (like open/close the door), you will “force” it to report immediately.
Refreshing the page shouldn’t lose the state of the item. The state is stored internally within OH2 and you don’t really need persistence (mainly used for storing and reporting states over time) for the sitemap to be able to display the state of an item.

What means “the state is lost”? Example: You open the door, the sensor reports to OH2 the new state as “Open” (for example), the sitemap updates correctly to show that the door is open and then when you refresh the page (which UI and with which Broswer?) the state is showing closed?

If I am not wrong, you won’t see any specific restore messages for the persistence service that you use (mapdb in this case) on startup. You will see “ItemStateChangedEvent” entries in your events.log file. If you use persistence, OH2 will read the status of the items from the persistence service.

Thank you Dim. This is great information.

If I open the door, the sensor reports to OH2 the new state. The sitemap does update correctly to show that the door is open. When I refresh the page, the state is blank/empty. I’m using Chrome to access the basicui with my custom main.sitemap.

I have started to notice that sometimes, the closed event isn’t passed to OH2. When this happens, the light on the door sensor goes solid red for several seconds. I wonder if there’s something wrong with the sensor. I’m in an open room with maybe 20ft between the sensor and the z-stick.

OK. Thanks. I do see the ItemStateChangedEvent as well as a debug event from mapdb indicating that the value was stored in the database.

==> /var/log/openhab2/events.log <==
2017-01-19 14:10:29.748 [ItemStateChangedEvent     ] - FrontDoorSensor_BinarySensor changed from OFF to ON

==> /var/log/openhab2/openhab.log <==
2017-01-19 14:10:29.752 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'FrontDoorSensor_BinarySensor' with state 'ON' in mapdb database