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

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…

That is correct. rrd4j is just for numbers. If Switches (and presumably Contacts) are no longer stored as 1 and 0 then rrd4j won’t work. You can look at SQLite which is also an embedded DB (i.e. no separate server to set up) though others have had some problems getting JDBC working and I’ve yet to figure out why people are having problems or how to help. I’m personally pretty happy with InfluxDB, though I’m having a problem with the recent change where calls to maximumSince and minimumSince are failing with an error.

I’m not sure I have a good solution to recommend.

Yes, I am one of them - see here:

I followed your recommendation about (3 Tier aproach).
I even tried H2 with the same result. :frowning:
Thanks for your help, though.

Well, I can say that the InfluxDB tutorial worked very well for me. It isn’t embedded but it seems to work.

The issue with SQLite, at least for me, is that there is a bug in the 3.8.11.2 version of sqlite_jdbc. Updating this to a more recent version allowed the persistence to start up without error. This was on a Raspberry Pi and as far as I can tell the bug is related to the arm platform though that is not certain. I wasn’t able to figure out how to update it properly so just copied a newer version of the library overtop of the existing one with the old name.

In my case it was wrong config file name. I wanted to have jdbc-sqlite based persistence and put config as sqlite.persist to /etc/openhab2/persistence. It was enough just to rename config to jdbc.persist and everything worked fine.

I think it’s must be mentioned somewhere in documentation that config file names must match service names.

1 Like

Hi,
it would be of great help if the “one minute” restriction as well as the string restriction were a comment in the rrd4j.persist file (see below).
Finally it is not clear if Switch or Contact items can be stored or not.
I would be happy if you could add this to the repository so that the demo files will include this hint in the future.
Kind regards,
Axel

// 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 of one minute (mandatory to make rrd charts work)
	everyMinute : "0 * * * * ?"
}

Items {
	// storable items have to be of type Number
	// rrd does not store strings !!!
	DemoSwitch,NoOfLights,Window_GF_Toilet,Heating* : strategy = everyChange, everyMinute, restoreOnStartup
	
	// let's only store temperature values in rrd
	Temperature*,Weather_Chart* : strategy = everyMinute, restoreOnStartup
}

I second that, BUT: it is always a good idea to follow the docs where you can find:

For rrd4j to work, the strategy everyMinute has to be used

and

NOTE: rrd4j is for storing numbers only.

1 Like

Thanks man. I was going nut with postgresql.persist! :slight_smile:

I think that sometimes openhab is so powerful and flexible that you don’t know what to do. Some more examples would be great.