MongoDB Persistence with OpenHAB 2

(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

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 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([: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?

(Alec Kloss) #20

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

(Gianluca Petralia) #21

I’m trying just today to use OH2 with mongodb.
I followed the guide to configure oh1 to oh2, configuring addons,cfg and runtime.cfg as explained in
I imported the jre and see the bundle active in openhab karaf container,
I created a mongodb.cfg in conf/services folder to config the server, database and collection.
But unfortunately I receive the following warn:
16:02:21.603 [WARN ] [ig.dispatch.internal.ConfigDispatcher] - Could not parse line ‘mongodb://<>:2701’
I don’t know what I’ve to do to fix it.
Can you help me?

(Angelos) #22

add the following line as the first line in your mongodb.cfg:


and then fix correctly the config parameters as described here:

(Angelos) #23

I added your issue in

(blackpi) #24

Hello, I am trying to install the MongoDB in Openhab but I can’t find the *.jar file, could anyone tell me where to find or download the *.jar file?

Blockquote Download the latest *.jar manually from:

This link does not work anymore,

Thank you

(Angelos) #25

(blackpi) #26

Thank you very much

(blackpi) #27

Hello again, I have placed de *.jar file, I have configured the .cfg and the .persist files and I have seen with the OH console that the service is active, but, where does the data get storaged? How can I acccess to it?

Thank you

(Angelos) #28

did you install and configure the Mongo Database?
Why mongodb by the way?
what do you want to do with a persistence db?

(blackpi) #29

Yes I have installed de mongodb and I have read that the data is stored in the path /data/db but I cant see anything there, what configurations have to be done? I have installed it, created the path /data/db and then used it to configure the port in the same place that in the .cfg of openhab using this:

sudo mongod --port 27017 --dbpath /data/db/ --fork --logpath /data/mongodb1.log

I have installed mongodb because I want to have a database to store the information of my sensor in my rasp. I am still a begginer and if I dont get it I have thougth to install a MySQL database instead of the MongoDB. What is the problem with a persistence db?

(Angelos) #30

There is no problem (on the contrary…). There are many options and some fit better to each cause.
What is your goal? To store only (for restoreOnStartup)? To display in graphs? To replicate/export data to another system?

In any case, if you go ahead with Mongo, you need to read:

Keep in mind that:

  1. Not many OH2 users use MongoDB as a persistence storage destination
  2. The binding is not “officially” checked for compatibility with OH2
  3. There is maintenance involved with each DB

Describe your goal and we can give some better options

Read also:

(blackpi) #31

My goal is to restoreOnStartup, to display in graphs and to maybe in a future to replicate/export data to another system. I want a system that is the most flexible as possible. After your comment, I think that a MySQL database is better, I don’t know if it is easy to make the graphs with it but maybe I can use another tool as ThingSpeak or Xively.

(Angelos) #32

Now we are talking :slight_smile:

best option (by far): mapdb
MySQL is way slower than MapDB for this purpose

one of the best options: InfluxDB+Grafana persistence and graphing

You can go with a 3rd one here: MySQL or use Influx. MySQL is more flexible here (export/replicas)

You can also achieve all 3 goals with MySQL as your persistence service. Grafana can also use MySQL as the backend DB and you can also do restoreOnStartup from MySQL.

If you want to use only 1 persistence service, go with MySQL using the JDBC driver.

For your setup, I would recommend a triple persistence configuration: Map + Influx + MySQL
Make sure that your host has enough RAM (~2G) to support all 3 :slight_smile:

(blackpi) #33

Well, I am using a Rasp 3 b+ so my RAM is 1GB. So I think after reading you that the best option is to install MySQL with JDBC driver. That driver that you linked me is the same that we can find in the paper UI / add-ons / persistence, “JDBC Persistence MySQL” ?

do I have to download MySQL from the official page and later configure the JDBC driver ?

Then I can use the Grafana to graph the data

And what about the storage in the cloud, what would you recommend me?

Thank you very much

(Angelos) #34

Yes to all 3 :slight_smile:

Directly from OH2 (configuring the persistence service to connect to a Cloud DB): I wouldn’t recommend this due to latency. It can be done but it’s not fast enough and you may experience problems. It’s better to have a local DB.
It also depends if you want to have DB Access on the Cloud or just a backup destination.
For simple backup: Write a script that exports daily the local MySQL DB and ships it over to the cloud destination.
If you want DB Access on the Cloud you can take a look at:
Export MySQL->Import in Azure