mpdb only saves one value. There is no history in mapdb. The value stored in mapdb is almost always going to be the Item’s current state. MapDB doesn’t have any other information.
The docs should make this clear.
The **MapDB (opens new window)**persistence service is based on a simple key-value store that only saves the last value. MapDB is useful for restoring items that have the restoreOnStartup strategy because other persistence options have some drawbacks if only the last value is needed on restarts.
Some disadvantages of other persistence services compared to MapDB are that they:
- grow in time
- require complex installs (
influxdb, jdbc, jpa)
rrd4j cannot store all item types (only numeric types)
It is only possible to query the last value and not other historic values because the MapDB persistence service can only store one value per item.
Bolding is mine.
You can’t query MapDB for your location yesterday becuase it doesn’t have it. It only knows your current location and that’s what it gives you.
Persistence need not be a struggle.
At a the highest level, persistence is a log consisting of a timestamp and an Item’s state. If you were to print one out for a Switch it might look something like:
| Timestamp |
State |
| 1781710620000 |
“OFF” |
| 1781710680000 |
“ON” |
| 1781710800000 |
“OFF” |
That’s it. That’s all persistence is. A log of timestamps and states indicating that at that timestamp the Item was in that state.
This log gets saved in a special format to make both storage and retrieval of the data effecient. And there is special software used to read and write to this special format. Those are the persistence add-ons.
There are more than one persistence add-ons because there are advantages and disadvantages to each one. Some require installation of an external software service (e.g. InfluxDB), others manipulate the data over time (rrd4j decimates the data as it ages in order to maintain a fixed size), do not support all Item types (rrd4j only supports numbers and numeric Item types), and others have other limitations (e.g. MapDB only saves one entry).
Not all persistence add-ons are suitable for all purposes. You can’t draw a chart with MapDB. You can’t store a Location Item in rrd4j. You have to perform maintenance on databases that grow forever to keep them from filling up your disk.
Depending on what you need, you must set up a suitable persistence for that purpose. You will likely need more than one as no one persistice is best at everything.
- restoreOnStartup: MapDB is the best choice as it’s embedded (nothing separate to install and run), fast, never grows since it only saves one state, and it supports all Items.
- charting: rrd4j is the best choice because it supports all chartable Item types yet never grows on disk
- analysis: InfluxDB, PostgreSQL, etc depending on what external tools you want to use to analyze the data; data is not decimated as it ages
- for use in rules: rrd4j and/or SQLite depending on the Item types; SQLite is also an embedded database and unlike rrd4j it supports all Item types but unlike rrd4j it will grow forever so it comes with long term maintenance
- forecast/future values: In Memory which, as the name implies, doesn’t write data out to the disk and only holds the forecast data in RAM.
You have a Location Item. You can’t use rrd4j because rrd4j doesn’t support it. You can’t use MapDB because it only saves one value. So you must use something else to save the history for these Items. I’d recommend SQLite unless you think at some future date you might want to analyze your historic data using external tools. If so, InfluxDB, MariaDB, or PostgreSQL would be my recommendation depending what external tools you want to use for analysis (I know that InfluxDB is installable through openHABian).
When you configure the persistence, a good approach is:
- MapDB configured to save every Item on everyChange with restoreOnStartup (you only want one persistence responsible for restoreOnStartup)
- rrd4j configured to save every Item (unsupported Items will be ignored) everyMinute, and everyChange
- SQLite (or what ever you choose) configured to save only those Items you need historic data from that are not supported by rrd4j on everyChange.
However, be aware that having the location values stored in persistence won’t help you put them on a map in MainUI. The MainUI map widgets have no access to persistence data. They might help with a rule to populate Items put on the map though.