Persistence with OH2

with OH1 i just used rrd4j as persistence. Nearly all worked out of the box. Used it for “EveryChange”, “EveryMinute” (for charts) and “restoreOnStartup”.

With OH2 this works ok for all kind of Number-Items but either anymore for Switches. OH1 stored switches as on=100 and off=0, thats seemed to be changed. So charts from switches are no more possible. Also restoreOnStartup can’t work for non-number-items.

My solution for charts from switch-items is to use another rule, where an fake-number-item writes the 0 or 100 if the switch change status. Kind of uncool. More rules, more items … unnecessary.

So am i right i need a second persistence service?!

What’s “standard” out there? Using more services … only one service for everything?! I need charts from number and switch items, also restoreOnStartup vor any kind of item.


I can’t answer what the standard is as I don’t think there is one. I also don’t use OH 2 so can’t comment on any changes. But if OH 2 no longer saves the state of switches as numbers that would be a problem and I have no suggestions beyond what you have already done.

I always recommend using two or three persistence setups.

  1. MapDB for restoreOnStartup. It can handle all Item types and since it only saves the most recent value it never grows.

  2. rrd4j for numerical data for which you only care about relatively recent data for historical queries and charting. Like MapDB it never grows but it does stuff to old data and can only save numerical data.

  3. an external DB (e.g. MySQL, InfluxDB, etc.) for Items you want to study and have exactly accurate data for long periods of time. For this case, db4o may be a good case to save the Switches but that won’t help with the charting. You can’t chart non-numerical data.

To assign Items to these different strategies I use Groups.

Again you :stuck_out_tongue_winking_eye: … Very useful guy!

So i’ll better stay with rrd4j as it is. Because thats accurate enough for my needs. Using my fake-number-item-workaround for the switch-charts (for now).

For restoreOnStartup i’ll completing that with mapDB only logging switches and string items… Splitting that: Numbers > rrd4j, anything else > mapDB. Sounds good?

Group grrd4j (member are all number-items)

grrd4j* - means that every member in that group get logged right? Should… Like it does with Charts right know :D.

grrd4j* : strategy = everyChange, restoreOnStartup
gChartsA*, gChartB*, gChartC* : strategy = everyMinute

gmapDB* : strategy = everyChange, restoreOnStartup

Something missing?


Looks good.

Rules have to changed to that than?

AvgOut = (Wetter_Temperatur.averageSince(now.minusDays(5), “rrd4j”))


postUpdate(Wetter_Temp_Max, Wetter_Temperatur.maximumSince(startOfDay, “rrd4j”).state as Number)

If rrd4j is still configured as the default in openhab.cfg (or where ever that is defined in OH 2) you do not need to specify the rrd4j. If you changed the default o mapdb then you do.

Don’t know where to configure that … Good advice :smiley:
I’ll find something about that.

Having the same number item in rrd4j group and also in a charts group (both logged by rrd4j) don’t produce any conflict right? Because sorting out whats already in a chart group but not in rrd4j group will get really confusing.

I don’t know but I suspect the answer is no. Having it in multiple groups shouldn’t matter. It will just applyand additional strategies listed for that group.

rrd4j and mapDB with this “group setup” working fine the last 3 days. Splitting the Number items and the “others” (DateTime, Switch, String …) to one of both persistence services works perfectly. Reboots feeling much cleaner right now. UI is always in perfect state since all items get there status back (restorOnStartup). No more missing switches or rules that stuck because of missing states.

The only thing still missing is that switches-as-chart-thing. Unbelievable that this isn’t working out of the box.

Like you said, it was working in OH 1. Not sure what changed in OH 2, if anything, to make it not work nor why it changed.

This sounds to me like and, is that what you are looking for?
In ESH, there is now a generic ChartServlet that works for any persistence service and not just for RRD4j - this is why you are seeing this regression.

Sounds good. But if there are an documentation how to use it? Don’t know how to start.
Just using the same Chart item but another persistence service?

Well, you can’t use it as long as it isn’t fully implemented and merged… But maybe you can comment on the issue and tell @chris that there is interest in getting this working ( so far, nobody really asked for it, thus it had a very low prio).

updated the system to latest snapshot #455. All graphs from group-items are empty right now.
Only graphs from single items are working as always.

Maybe this is a bug or are there major changes in den code and i have to change something?

Okay, the data are still written.
I can call the graphs within a web browser on my pc.
Also the web view off basic ui is working finde.

But they are empty in the openHAB app on my iphone.

The same here for the android app… (2.0 stable)