Good Tutorial On Persistence (RRD4J and JDBC-MYSQL)?

I’m no expert on ON2 nor have I actually set up MySQL. I’m afraid I have no advice to offer.

I think you can put MySQL into a mode where it logs all the commands set to it.

Thanks Rich,

I’ve gotten a bit further. The items table with two fields gets created at startup, but no data or additional tables ever show up. When I uncommented a bunch of the optional stuff in jdbc.cfg I got additional errors in the logs. Doesn’t seem like persistence is triggering for jdbc.

I’ve also noticed, that the log is running two hours fast from EDT in my location. Looking for a time zone setting next…

Make sure that you have enabled NTP on both the OH server, and MySQL box if they are separate, and of course set the right TZ :wink:

Thanks Rob.

The pi’s date is correct, but the OH log is off by 4h.

pi@pi-openhab:~/openhab/userdata/logs $ cat openhab.log

2016-04-01 11:20:00.287 [INFO ] [.eclipse.smarthome.model.script.Test] - successful gettemps.py
pi@pi-openhab:~/openhab/userdata/logs $ date
Fri 1 Apr 07:20:18 EDT 2016

the MySQL server is in a VM and seems to drift even with NTP running. Not sure why.

Hi @rlkoshak

Your approach looks good.
Is there an easy way to include ALL items into MapDB like you suggested above?
I guess I don’t nee to put in one by one?
Thanks.

See the following:

By using Groups you don’t have to put any Items into the persist files at all and controlling which Items get persisted to which Tier is controlled by Group membership in the Items files.

So you mean i just need to put the groups into the mapdb.persist file like I did in my rrd4j ?
Like the one below? Same syntax? Or is there another more conveniet way to edit it in Paper UI or habmin?
If I put all the same Groups into rrd4j AND mapdb - OH will just store the numerical values in rrd4j and in mapdb the last state of each single item in those groups?
Or do I neccessarily need to create new separate groups for all the items?

// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
    // for rrd charts, we need a cron strategy
    everyMinute : "0 * * * * ?"
}

Items {
    // which data to be stored
    G_Harmony*, G_Lights*, G_WLAN*, G_Mobiles*, G_Fritz*, G_Strega*, G_Irrigation*, G_Wetter*, G_Netatmo*, G_Abus*, G_Windows*, G_Melder*, G_Sonne*, G_Wecker*, G_Location_Enzio*, G_Location_Dona*, G_Loc_mqtt_Dona*, G_Loc_mqtt_Enzio*, G_Mobiles*, G_Presence*, G_Homecoming*, G_System*, G_Netzwerk*, G_All_OFF* : strategy = everyMinute, everyChange, restoreOnStartup
}

Yes, or you can just put * to represent ALL Items. If you look at the mapdb.persist file on the link I provided you will see that is what I did.

* : strategy = everyChange, restoreOnStartup

That means save every change to all Items and restore their values on startup.

Every minute is way overkill for MapDB. All you really need is everyChange.

However, if there are Items you want to exclude from restoreOnStartup you will need to list each of your groups separately.

All persist files use the same syntax.

That is correct. MapDB doesn’t have the same limitation to numerical data that rrd4j does.

The main point of the post I linked to above is to create three or four new groups, one for each of the different ways you want to persist. For example:

gRestoreOnStartup
gChart
gHistoric
gAnalysis

Then just put those Groups into your .persist files where appropriate (e.g. mapdb.persist would be gRestoreOnStartup* : everyChange, restoreOnStartup and rrd4j would be gChart* : everyChange, everyMinute and so on). Then just assign your Items to the different groups as needed. If you want to do a blanket restoreOnStartup on all Items you don’t need the first Group name, just put * in the mapdb.persist file.

1 Like

Thanks for your detailed desciption.
That helps a lot to setup a new (and better) persistence handling than I used to have.

I’m having a problem that seems related to this thread, but I’m not sure that it is.

I have some MQTT items set up and can send a value to them. It displays the value just fine if I am looking at the page, but it won’t retain it for future display (e.g. if I navigate off the page and come back, it will not be displayed).

Is this a persistence thing? A MQTT QOS thing? I don’t get it.

Which openHAB, 1.8 or 2.0?

This is a sitemap thing and not related to persistence or MQTT.

It is OH2, and this thread seems to be mostly about persistence. Maybe you are replying to multiple threads tonight, in the helpful way you always do?

Oops - I just reread and clearly misunderstood. Yes, my issue may be a sitemap problem, as it doesn’t seem to be able to get the value of the item.

and I figured it out. I think.

And my apologies if I sounded rude - trying to code in a noisy household with a sick dog can be unproductive and frustrating!

@alfista2600:
HOw did you figure the root cause out?
Could you please share, because I struggle with the same behavior
Thanks in advance.

It had to do with the formatting of the values, I believe.

For example. If I had:

Switch switch_office_lamp             "Office" <switch> {some binding}

it would temporarily show the value but if I had:

Switch switch_office_lamp             "Office [%s]" <switch>  {some binding}

It would work as expected.

Hi @rlkoshak,

since migration to OH2 I am struggling with persistence and tried to follow your path. Especially because I would like to use “previousState”.

However, rrd4j (in your Tier 2) does not work on switches (e.g. previousState == OFF), right?
How do you manage to get those previousStates then?

Thanks!!

Rrd4j does work for Switches, at least it used to. Are you not getting the right value or are you getting null?

This was the case for OH 1 (switches have been stored as 0 or 1).
In OH 2 this is not the case anymore - rrd4j is working for numbers only - right?

At least this is the “common understanding” I have read about so far…