Getting mapdb persistence to work with openhab2

mapdb
openhab2
persistence
Tags: #<Tag:0x00007fd31040fc28> #<Tag:0x00007fd31040fa48> #<Tag:0x00007fd31040f890>

(Dan) #1

Hi,

My transition to openhab2 has hit a roadblock getting persistence services to work.

I have mapdb installed (and running) and set as the default.

the mapdb.persist file reads:

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

I then have a bunch of items in the (startpersist) group.

In openhab 1.8 this worked fine. However in 2.0 my items are not being persisted. I see no errors in the log. Not sure how to turn on debug logging for mapdb - if anyone knows how to do that then that would be really helpful

thanks,

Dan


(SiHui) #2

Try on the karaf console:

log:set DEBUG org.openhab.persistence.mapdb


(Dan) #3

Thanks - I now have debug logging working. Unfortunately that gives no hint of what is wrong - the logs look fine as I start, stop and restart openhab2, although I would think I’d see log entries as items change and there don’t seem to be any:

2016-12-11 12:01:36.330 [INFO ] [core.karaf.internal.FeatureInstaller] - Installed 'openhab-persistence-mapdb'
2016-12-11 12:05:51.691 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
2016-12-11 12:05:55.394 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTING - org.openhab.persistence.mapdb
2016-12-11 12:05:55.396 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTED - org.openhab.persistence.mapdb
2016-12-11 12:05:55.411 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is being activated
2016-12-11 12:05:55.702 [DEBUG] [pdb.internal.MapDBPersistenceService] - Scheduled Commit-Job with interval 5sec.
2016-12-11 12:05:55.703 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is now activated
2016-12-11 12:05:55.709 [DEBUG] [org.openhab.persistence.mapdb       ] - ServiceEvent REGISTERED - {org.openhab.core.persistence.PersistenceService}={service.pid=org.openhab.mapdb, commitinterval=5, component.name=org.openhab.persistence.mapdb, component.id=189, commitsamestate=false, service.id=304, service.bundleid=185, service.scope=bundle} - org.openhab.persistence.mapdb
2016-12-11 12:08:27.795 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STOPPING - org.openhab.persistence.mapdb
2016-12-11 12:08:27.804 [DEBUG] [org.openhab.persistence.mapdb       ] - ServiceEvent UNREGISTERING - {org.openhab.core.persistence.PersistenceService}={service.pid=org.openhab.mapdb, commitinterval=5, component.name=org.openhab.persistence.mapdb, component.id=189, commitsamestate=false, service.id=304, service.bundleid=185, service.scope=bundle} - org.openhab.persistence.mapdb
2016-12-11 12:08:27.804 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service deactivated
2016-12-11 12:08:27.812 [DEBUG] [pdb.internal.MapDBPersistenceService] - Found 1 MapDB-Jobs to delete from DefaulScheduler (keys=[MapDB_SchedulerGroup.Commit_Transaction])
2016-12-11 12:08:27.814 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STOPPED - org.openhab.persistence.mapdb
2016-12-11 12:08:52.375 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
2016-12-11 12:08:56.358 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTING - org.openhab.persistence.mapdb
2016-12-11 12:08:56.360 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTED - org.openhab.persistence.mapdb
2016-12-11 12:08:56.362 [DEBUG] [org.openhab.persistence.mapdb       ] - ServiceEvent REGISTERED - {org.openhab.core.persistence.PersistenceService}={service.pid=org.openhab.mapdb, commitinterval=5, component.name=org.openhab.persistence.mapdb, component.id=189, commitsamestate=false, service.id=304, service.bundleid=185, service.scope=bundle} - org.openhab.persistence.mapdb
2016-12-11 12:08:56.376 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is being activated
2016-12-11 12:08:56.603 [DEBUG] [pdb.internal.MapDBPersistenceService] - Scheduled Commit-Job with interval 5sec.
2016-12-11 12:08:56.603 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is now activated

Any help gratefully received - having been very comfortable with openhab 1.8 I’m rapidly feeling out of my depth here…


(SiHui) #4

I remember reading somewhere that a “Strategy” has to be defined, regardless of using it or not, so try to change your file to:

Strategies {
        default = everyUpdate
}
Items {
// persist all items once a day and on every change and restore them from the db at startup
startpersist* : strategy = everyChange, restoreOnStartup
}

(Dan) #5

brilliant - thank you. I’ll edit the wiki to make that point


(Karen Mitchell) #6

I’m trying to use mapdb persistence, but my virtual buttons keep turning off.

I have this in my runtime.cfg:

org.eclipse.smarthome.persistence:default=mapdb

This is my mydb.persist:

Strategies {
        default = everyUpdate
}

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

My items file has below:

Group StartPersist
Switch Daylight 		"Daylight" 		<sun> 			(Virtuals, StartPersist)
Switch Christmas 		"Christmas" 	<christmas> 	(Virtuals, StartPersist)
Switch Summer 			"Summer" 		<temperature> 	(Virtuals, StartPersist)

If I turn on my virtual switches in the app, then reboot my RPi, the switches are set to off again.


(SiHui) #7

Looks all good to me.
Do you have any errors when saving your persist config file in openhab.log?
You should only see something like
Refreshing model 'mydb.persist'


(Karen Mitchell) #8

Yes.

2018-05-24 15:21:01.511 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mydb.persist'

(SiHui) #9

Then I have no idea what is wrong.
Before restarting openHAB, did you switch your virtual items several times?
The first trigger will be from null to ON or OFF, maybe that one is not persisted. A second trigger then should store the actual state on everyChange.


(Karen Mitchell) #10

Hmm, that still didn’t work. I can see the virtuals in the log being set to OFF and ON, but after I reboot, it still doesn’t keep the switches set to ON.


(Wouter Born) #11

There is an issue where the first update of an item is not saved. Only when an item that already has state is updated the database is committed.

I’ve created a fix for it in this PR:


(Jonas) #12

I have serious issues getting this to work as well.
I installed it via the addons.cfg where i added mapdb to the persistence line.
Also i modified the runtime.cfg to contain: org.eclipse.smarthome.persistence:default=mapdb

After a restart the mapdb.cfg-File is generated but the mapdb.perist is not.
Only after i deleted the mapdb.config file from the user-folder and reinstalled again it worked.
(strange behaviour though …).
now when i store a value via rest for example i get a log message that sais: stored.
but if i restart now it does not recover the old state but says NULL …

is this the same issue described here?

I’d like to try the fix but i don’t know where to copy the files to.

Thank you


(SiHui) #13

First: it is mapdb.persist (typo!) and no, it is not generated automatically, you need to add that file with your own content manually:

Don’t mess with the *.config files, those are automatically generated and not to be edited manually.


(Juan) #14

Hi guys,

I am trying to implement the persistence without succes.

Step followed:

  • mapdb installed in PAPER UI
  • file runtime.cfg added the org.eclipse.smarthome.persistence:default=mapdb
  • rule within mapdb.persist file. Is everyUpdate or everyChange?
Strategies {
        default = everyUpdate
}

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

I have tried as well that without success. All switches are in NULL.

And the more curiouse thing is that I have a sonoff DUAL where the status is ON and OFF, and I see properly the status in the sitemap, but other sonoff bassic which is in ON, the actual status is NULL in sitemap, should be ON. The rest os switches are NULL

I have restarted with sudo systemctl restart openhab2.service

Any suggestion? Better if I work with rules?
Thank you.


(Juan) #15

I have solved my issue after restart with the NULL status, with some rules. because mapdb did not work for me. So I used the HTTP binding, easier to check up the POWER of each switch :smiley: