MongoDB Persistence with OpenHAB 2


(Bikash Panda) #1

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

Thanks,
Bikash


(Angelos) #2

did you configure your cfg and persist parameters?

http://docs.openhab.org/addons/persistence/mongodb/readme.html
http://docs.openhab.org/configuration/persistence.html


(Bikash Panda) #3

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.


(Angelos) #4

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:
https://openhab.ci.cloudbees.com/job/openHAB1-Addons/lastSuccessfulBuild/artifact/bundles/persistence/org.openhab.persistence.mongodb/target/

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


(Bikash Panda) #5

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…


(Angelos) #6

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)


(Bikash Panda) #7

Thnks a lot Dim,


(Bikash Panda) #8

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
url=mongodb://localhost:27017
database=openhab
collection=perist

Even my MongoDB server is running.


(Angelos) #9

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

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

content goes here


(Angelos) #10

@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:


(Bikash Panda) #11

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


(Angelos) #12

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

(Rich Koshak) #13

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

http://docs.openhab.org/tutorials/migration.html#installing-unofficially-supported-openhab-1x-add-ons


(Bikash Panda) #14

thnks everone it finlly worked.


(Kai Kreuzer) #15

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!


(Angelos) #16

@oksbwn
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


(Bikash Panda) #17

As mentioned by @rlkoshak I copied the .jar file for the mongoDB from the link http://docs.openhab.org/tutorials/migration.html#installing-unofficially-supported-openhab-1x-add-ons4 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.


(Alec Kloss) #18

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

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

(Alec Kloss) #19

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(Enum.java:238)[:1.8.0_144]
        at org.openhab.core.library.types.OpenClosedType.valueOf(OpenClosedType.java:1)[176:org.openhab.core.compat1x:2.1.0.201702051222]
        at org.openhab.persistence.mongodb.internal.MongoDBPersistenceService.query(MongoDBPersistenceService.java:285)[215:org.openhab.persistence.mongodb:1.9.0]
        at org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate.query(QueryablePersistenceServiceDelegate.java:47)[176:org.openhab.core.compat1x:2.1.0.201702051222]

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


(Alec Kloss) #20

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