MongoDB Persistence with OpenHAB 2

How to use MongoDB with OpenHAB 2. I m not getting way around it. Plese help me on this.


did you configure your cfg and persist parameters?

Thanks for your response Dim, Actually I did that but I m not getting how to and where to add the jar file. and where will i find mongodb connector for openhab 2. It is not showing up in paper UI persistenece.

oops… you are right. I also don’t have this option in my PaperUI (to install the MongoDB persistence service).

Maybe we need to open up an issue on the distro repo?

Download the latest *.jar manually from:

and place it in /usr/share/openhab2/addons

I just need to add the jar file to the addon folder and configure the persist and cfg thats only right or anyhing else hs to be done to make it work…

that should be it

After you place the *.jar in the addons folder, check if the bundle has been loaded correctly within openHAB2 by using the openHAB console:

bundle:list -s |grep -i mongo

(it should show Active state)

Thnks a lot Dim,

1 Like

Still no luck. Its not hppening. FYI: My persist file is like this

// persistence strategies have a name and a definition and are referred to in the “Items” section
Strategies {
everyHour : "0 0 * * * ?"
everyDay : “0 0 0 * * ?”

// if no strategy is specified for an item entry below, the default list will be used
default = everyChange



  • Each line in this section defines for which item(s) which strategy(ies) should be applied.

  • You can list single items, use “" for all items or "groupitem” for all members of a group

  • item (excl. the group item itself).
    Items {
    // persist all items once a day and on every change and restore them from the db at startup

    • : strategy = everyChange, everyDay, restoreOnStartup

    // additionally, persist all temperature and weather values every hour
    Temperature*, Weather* : strategy = everyHour

nd mongodb.config file is

Even my MongoDB server is running.

.cfg ? (/etc/openhab2/services/mongodb.cfg)

Ps: use code fences. it makes it easier to read :slight_smile:

content goes here

@kai is this normal? (was mongodb removed for some reason from the addon options for persistence services?)
or we should open up a new issue? (where does this belong to? distro, 1x-addons, paperui within esh?) :slight_smile:

sorry for the code. I didn’t know. and actually I have the extension .cfg only. i mistyped it in the post.

does the bundle show up as Active or Installed in the console?

Try to enable a higher log level for the bundle (from the console) and check the logs (/var/log/openhab2/openhab.log):

log:set TRACE org.openhab.persistence.mongodb

You might need to enable the OH 1.x compatibility layer. See:

thnks everone it finlly worked.

And if all is working well, don’t miss creating a PR to add it to the official distro, so that other users won’t have to go through these manual steps!

1 Like

What is the openHAB2 version that you are running? (2.0 stable, 2.1 stable, some snapshot build?)
How did you finally solve the issue at the last step? Was the compat1x bundle missing and after installation the persistence service bundle started?
Do you see any warnings or errors in your log or the service is stable?

I want to update the issue on github :slight_smile: openhab/openhab-distro/Issue#487

As mentioned by @rlkoshak I copied the .jar file for the mongoDB from the link to the addons folder and created the .persist and .conf file and it worked. I was having another issue also in my .conf file that’s what made it complex. Anymay that was my mistake. Sorry for late response as I was out of station fro couple of weeks.

1 Like

FWIW, you may want to add an index like so too:

rs0:PRIMARY> db.openhab.ensureIndex({"item":1,"timestamp":-1})

I’ve been running mongo persistence for quite a while but have just recently noticed that state restoration doesn’t work. This is the only suspicious thing I’ve noticed in the log:

2018-02-06 20:14:33.432 [ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file '/home/openhab/openhab2/conf/persistence/mongodb.persist': No enum constant org.openhab.core.library.types.OpenClosedType.ON.
java.lang.IllegalArgumentException: No enum constant org.openhab.core.library.types.OpenClosedType.ON
        at java.lang.Enum.valueOf([:1.8.0_144]
        at org.openhab.core.library.types.OpenClosedType.valueOf([176:org.openhab.core.compat1x:]
        at org.openhab.persistence.mongodb.internal.MongoDBPersistenceService.query([215:org.openhab.persistence.mongodb:1.9.0]
        at org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate.query([176:org.openhab.core.compat1x:]

Anyone else experiencing that, or have any success fixing it?

I found the Contact item that I had configured to be restored and disabled it, and now state is restored correctly.