No persistence with MapDB

Hey, I have problems getting my persistency work with mapDB.
I installed the binding, edited the mapdb.cfg and set up the mapdb.persist file, but nothing gets persisted.

Also I have set it up under System.

Do I miss something?

A Restart maybe

doesn’t seem to work. is it possible to check a file or something else?

Please post your config and .persist files.

Are there any errors in the logs?

Very noob question here, im trying go get MapDB running, but the runtime.cfg shoud that be:

org.eclipse.smarthome.persistence:default=mapdb

or

# org.eclipse.smarthome.persistence:default=mapdb

:slight_smile:

or is it:

persistence:default=mapdb ?!!?!?

If you are truly a noob, you should set this in PaperUI and not use runtime.cfg to configure your system.

The # indicates a commented out line.

Your first example is the correct one.

2 Likes

Hello ! Im new here !

I have a similar problem. Here is the log file. I am looking for Persistence on switch IN1, IN2, IN3, IN4

21:35:19.469 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = c645e534-8051-43cc-a991-aecac3a59fcb, base URL = http://localhost:8080)
21:35:31.906 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.items'
21:35:33.294 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
21:35:40.735 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
21:35:40.836 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'TemperaturaBsAs-yahooweather:weather:BuenosAires:temperature' has been added.
21:35:40.845 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_Mobile_Luis-network:device:10_180_0_229:online' has been added.
21:35:40.850 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_DVR-network:device:10_180_0_252:online' has been added.
21:35:40.855 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_Mobile_Sabri-network:device:10_180_0_239:online' has been added.
21:35:40.860 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_TV_Samsung-network:device:10_180_0_243:online' has been added.
21:35:41.601 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.things'
21:35:44.227 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://10.180.0.232:8080
21:35:44.230 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://10.180.0.232:8443
21:35:44.789 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
21:35:45.940 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
21:35:46.053 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
21:35:47.018 [INFO ] [marthome.event.ItemStateChangedEvent] - IN2 changed from NULL to ON
21:35:48.480 [INFO ] [marthome.event.ItemStateChangedEvent] - IN1 changed from NULL to ON
21:35:48.498 [INFO ] [marthome.event.ItemStateChangedEvent] - IN4 changed from NULL to ON
21:35:48.506 [INFO ] [marthome.event.ItemStateChangedEvent] - IN3 changed from NULL to ON
21:35:48.557 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTING - org.openhab.persistence.mapdb
21:35:48.564 [DEBUG] [b.internal.MapDBPersistenceActivator] - MapDB persistence bundle has been started.
21:35:48.606 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is being activated
21:35:48.829 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_229' has been added.
21:35:48.909 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_229' changed from UNINITIALIZED to INITIALIZING
21:35:48.938 [INFO ] [rvice.dhcp.ReceiveDHCPRequestPackets] - DHCP request packet listener online
21:35:48.954 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_252' has been added.
21:35:48.991 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_252' changed from UNINITIALIZED to INITIALIZING
21:35:49.001 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_239' has been added.
21:35:49.032 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_239' changed from UNINITIALIZED to INITIALIZING
21:35:49.041 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_243' has been added.
21:35:49.074 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_243' changed from UNINITIALIZED to INITIALIZING
21:35:49.433 [DEBUG] [pdb.internal.MapDBPersistenceService] - Scheduled Commit-Job with interval 5sec.
21:35:49.435 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is now activated
21:35:49.472 [DEBUG] [org.openhab.persistence.mapdb       ] - ServiceEvent REGISTERED - {org.openhab.core.persistence.PersistenceService}={component.name=org.openhab.persistence.mapdb, component.id=175, service.id=296, service.bundleid=186, service.scope=bundle} - org.openhab.persistence.mapdb
21:35:49.480 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTED - org.openhab.persistence.mapdb
21:35:49.845 [WARN ] [.weather.internal.bus.WeatherBinding] - Unable to find any configuration settings for weather binding. Check openhab.cfg.
21:35:53.931 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_229' changed from INITIALIZING to ONLINE
21:35:53.942 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_252' changed from INITIALIZING to ONLINE
21:35:53.945 [INFO ] [marthome.event.ItemStateChangedEvent] - Presence_DVR changed from NULL to ON
21:35:54.086 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber 'org.eclipse.smarthome.core.thing.link.ThingLinkManager@1a49971' takes more than 5000ms.
21:35:58.945 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_243' changed from INITIALIZING to ONLINE
21:35:58.956 [INFO ] [marthome.event.ItemStateChangedEvent] - Presence_Mobile_Luis changed from NULL to OFF
21:35:58.961 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber 'org.eclipse.smarthome.core.thing.link.ThingLinkManager@1a49971' takes more than 5000ms.
21:35:58.963 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_239' changed from INITIALIZING to ONLINE
21:35:59.111 [INFO ] [marthome.event.ItemStateChangedEvent] - Presence_Mobile_Sabri changed from NULL to OFF
21:35:59.115 [INFO ] [marthome.event.ItemStateChangedEvent] - Presence_TV_Samsung changed from NULL to OFF
21:36:49.351 [INFO ] [marthome.event.ItemStateChangedEvent] - Presence_Mobile_Luis changed from OFF to ON
21:37:14.491 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'IN1' received command OFF
21:37:14.497 [DEBUG] [pdb.internal.MapDBPersistenceService] - store called for IN1
21:37:14.524 [INFO ] [marthome.event.ItemStateChangedEvent] - IN1 changed from ON to OFF
21:37:14.556 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'IN1' with state 'OFF' in mapdb database
21:38:30.891 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'
21:38:31.433 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'
21:38:34.386 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'
21:38:34.857 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'
21:38:35.294 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'```

What is the problem?
In the log that you posted, it seems that the status of item IN1 gets persisted correctly in mapdb.

Post your IN1-4 items config as well as your persist file

Hi ! Thanks for your help.

The problem is that when I restart the system the switch start with the default status ( all ON )

I dont understand why this --> 21:35:48.480 [INFO ] [marthome.event.ItemStateChangedEvent] - IN1 changed from NULL to ON

//default.items 
Group G_all
Group G_arriba (G_all)


Number TemperaturaBsAs 	"Temperatura Buenos Aires" { channel="yahooweather:weather:BuenosAires:temperature" }

Switch Presence_Mobile_Luis <network> { channel="network:device:10_180_0_229:online" }
Switch Presence_DVR <switch> { channel="network:device:10_180_0_252:online" }
Switch Presence_Mobile_Sabri <network> { channel="network:device:10_180_0_239:online" }
Switch Presence_TV_Samsung <television> { channel="network:device:10_180_0_243:online"}

Switch IN1 <light> (G_arriba) { gpio="pin:26 activelow:yes"}
Switch IN2 <light> (G_arriba) { gpio="pin:13 activelow:yes" }
Switch IN3 <light> (G_arriba) { gpio="pin:6 activelow:yes" }
Switch IN4 <light> (G_arriba) { gpio="pin:5 activelow:yes" }```


// mapdb.persist
Strategies {
default = everyUpdate
}
Items {
G_arriba* : strategy = everyChange, restoreOnStartup
}

This means that your restoreOnStartup strategy is working fine. I also see in your log that the state for all 4 items gets restored correctly upon startup.

By default, all items will come up with state NULL when OH2 boots up.
The persistence will retrieve the last state and restore it for each persisted item.
It seems that the state of these 4 items was ON when OH2 was stopped the last time.

After boot -> NULL -> persistence restore -> item state will be updated based on its configuration (binding will read the state and update the item). Also a rule may fire and update the state at this point in time -> then persistence will store the new state in the DB.

mapDB will store only the last state of each persisted item (no further historical states are kept… only 1 state value per item). Other persistence services can store also historical values for states (to be used for graphing and/or more advanced rules with historicState)

To check the state that is stored in mapDB you can use:

http://<OH2_IP>:8080/rest/persistence/items/IN1?serviceId=mapdb

This is the state that will be restored on Startup.

You need the misc-restdocs addon installed for this.

Tips & Tricks:
Create a new file named gGroups where you store all your group definitions (only) and within that, a group named gMapDB.
Example Groups.items:

/* Control Groups */
Group				gAll
Group				gMapDB
Group:Switch		gPresence	(gAll)
Group:Switch		gArriba		(gAll,gMapDB)

Then, per binding, use a separate items file like:
GPIO.items:

Switch IN1 <light> (gArriba) { gpio="pin:26 activelow:yes"}
Switch IN2 <light> (gArriba) { gpio="pin:13 activelow:yes" }
Switch IN3 <light> (gArriba) { gpio="pin:6 activelow:yes" }
Switch IN4 <light> (gArriba) { gpio="pin:5 activelow:yes" }

and another file: Network.items (with your presence Switches which use the network binding)

Switch	Presence_Mobile_Luis	<network>		(gPresence)	{ channel="network:device:10_180_0_229:online" }
Switch	Presence_DVR			<switch>		(gPresence)	{ channel="network:device:10_180_0_252:online" }
Switch	Presence_Mobile_Sabri	<network>		(gPresence)	{ channel="network:device:10_180_0_239:online" }
Switch	Presence_TV_Samsung		<television>	(gPresence)	{ channel="network:device:10_180_0_243:online"}

and then use the gMapDB in your mapdb.persist file:

Strategies {
	default = everyChange
}
Items {
	gMapDB* : strategy = everyChange, restoreOnStartup
}

And of course, another file for your weather bound items :stuck_out_tongue:

It makes it easier to manage the persistence service (as well as your configs) :slight_smile:
By adding a subgroup to the gMapDB group (in the Groups.items file), you will persist its members.

Dim thanks for the detailed information ! I have a cleaner Openhab config.

:hushed: I am having the same problem, but with more information.

The information is stored in MapDB

09:13:02.243 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'IN3' received command OFF
09:13:02.249 [DEBUG] [pdb.internal.MapDBPersistenceService] - store called for IN3
09:13:02.254 [DEBUG] [pdb.internal.MapDBPersistenceService] - Stored 'IN3' with state 'OFF' in mapdb database
09:13:02.261 [INFO ] [marthome.event.ItemStateChangedEvent] - IN3 changed from ON to OFF
09:13:02.265 [INFO ] [ome.event.GroupItemStateChangedEvent] - gArriba changed from ON to UNDEF through IN3

When I restart the system MapDB load properly

openhab> log:display 
08:56:54.748 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://10.180.0.232:8080
08:56:54.783 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://10.180.0.232:8443
08:57:00.133 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = c645e534-8051-43cc-a991-aecac3a59fcb, base URL = http://localhost:8080)
08:57:10.620 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'GPIO.items'
08:57:10.832 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'SWITCH.items'
08:57:10.914 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Groups.items'
08:57:12.185 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
08:57:19.898 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
08:57:20.023 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_Mobile_Luis-network:device:10_180_0_229:online' has been added.
08:57:20.055 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_DVR-network:device:10_180_0_252:online' has been added.
08:57:20.059 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_Mobile_Sabri-network:device:10_180_0_239:online' has been added.
08:57:20.063 [INFO ] [home.event.ItemChannelLinkAddedEvent] - Link 'Presence_TV_Samsung-network:device:10_180_0_243:online' has been added.
08:57:20.841 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.things'
08:57:24.913 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
08:57:25.054 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
08:57:25.216 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
08:57:26.153 [INFO ] [marthome.event.ItemStateChangedEvent] - IN2 changed from NULL to ON
08:57:26.159 [INFO ] [ome.event.GroupItemStateChangedEvent] - gArriba changed from NULL to UNDEF through IN2
08:57:26.617 [INFO ] [marthome.event.ItemStateChangedEvent] - IN1 changed from NULL to ON
08:57:27.615 [INFO ] [marthome.event.ItemStateChangedEvent] - IN4 changed from NULL to ON
08:57:27.627 [INFO ] [marthome.event.ItemStateChangedEvent] - IN3 changed from NULL to ON
08:57:27.632 [INFO ] [ome.event.GroupItemStateChangedEvent] - gArriba changed from UNDEF to ON through IN3
08:57:27.938 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_229' has been added.
08:57:28.003 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_229' changed from UNINITIALIZED to INITIALIZING
08:57:28.015 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_229' changed from INITIALIZING to ONLINE
08:57:28.031 [INFO ] [rvice.dhcp.ReceiveDHCPRequestPackets] - DHCP request packet listener online
08:57:28.045 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_252' has been added.
08:57:28.092 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_252' changed from UNINITIALIZED to INITIALIZING
08:57:28.096 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_239' has been added.
08:57:28.104 [INFO ] [ome.event.GroupItemStateChangedEvent] - gPresence changed from NULL to UNDEF through Presence_DVR
08:57:28.134 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_239' changed from UNINITIALIZED to INITIALIZING
08:57:28.143 [INFO ] [smarthome.event.ThingAddedEvent     ] - Thing 'network:device:10_180_0_243' has been added.
08:57:28.186 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_243' changed from UNINITIALIZED to INITIALIZING
08:57:28.190 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTING - org.openhab.persistence.mapdb
08:57:28.194 [INFO ] [me.event.ThingStatusInfoChangedEvent] - 'network:device:10_180_0_243' changed from INITIALIZING to ONLINE
08:57:28.196 [DEBUG] [b.internal.MapDBPersistenceActivator] - MapDB persistence bundle has been started.
08:57:28.200 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTED - org.openhab.persistence.mapdb
08:57:28.240 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is being activated
08:57:28.931 [DEBUG] [pdb.internal.MapDBPersistenceService] - Scheduled Commit-Job with interval 5sec.
08:57:28.932 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is now activated


But for some reason it doesn’t load the config from Mapdb and apply It. I start the system, the Switch came up from NULL to ON and MapDB still have the correct value ( OFF) but the OFF value is not applied to the Switch.

{"name":"IN3","datapoints":"1","data":[{"time":1502194382250,"state":"OFF"},{"time":1502194382250,"state":"OFF"}]}

So… in this case, the (ON) state is being retrieved at that moment not from the persistence service but from the item binding(?). Is the GPIO pin 6 low (OFF) or high (ON) when you start up OH2?

I haven’t found yet a way to properly debug the restore on startup behavior of mapDB… I have some strange cases also in my system… Data not restored at startup from MapDB

Thanks again !
How can I know the status of Gpio 6 on startup ?

Now I made another test, I didnt shutdown the raspberry, I stop openhabian2 service and start it again.
Result, didnt work again :thinking:

19:06:01.343 [INFO ] [marthome.event.ItemStateChangedEvent] - IN2 changed from NULL to ON
19:06:01.362 [INFO ] [ome.event.GroupItemStateChangedEvent] - gArriba changed from NULL to UNDEF through IN2
19:06:02.461 [INFO ] [marthome.event.ItemStateChangedEvent] - IN1 changed from NULL to ON
19:06:02.969 [INFO ] [marthome.event.ItemStateChangedEvent] - IN4 changed from NULL to ON
19:06:03.472 [INFO ] [ome.event.GroupItemStateChangedEvent] - gArriba changed from UNDEF to ON through IN3
19:06:03.495 [INFO ] [marthome.event.ItemStateChangedEvent] - IN3 changed from NULL to ON
19:06:03.546 [DEBUG] [org.openhab.persistence.mapdb       ] - BundleEvent STARTING - org.openhab.persistence.mapdb
19:06:03.551 [DEBUG] [b.internal.MapDBPersistenceActivator] - MapDB persistence bundle has been started.
19:06:03.565 [DEBUG] [org.openhab.persistence.mapdb       ] - ServiceEvent REGISTERED - {org.openhab.core.persistence.PersistenceService}={component.name=org.openhab.persistence.mapdb, component.id=177, service.id=298, service.bundleid=186, service.scope=bundle} - org.openhab.persistence.mapdb
19:06:03.588 [DEBUG] [pdb.internal.MapDBPersistenceService] - mapdb persistence service is being activated

And MapDB is storing the right information, also after the service restart, but it isnt restoring this information to the item.

http://X.X.X.X:8080/rest/persistence/items/IN3?serviceId=mapdb
{"name":"IN3","datapoints":"1","data":[{"time":1502194382250,"state":"OFF"},{"time":1502194382250,"state":"OFF"}]}```