Replicating rrdj4 default persistence via UI configuration

Hi Folks,

The docs refer to default persistence here: Persistence | openHAB

I’ve been using the default persistence for some time now and it works perfectly. However, I now would like to add MapDB as a second persistence config for a specific item. This is where the docs and the config gets confusing.

If you follow the UI > Settings > Add On Settings > RRDJ4 Persistence > Persistence Configuration and press save - this seems to override the default persistence settings. It seems to do this by creating a new file

/userdata/jsondb/org.openhab.core.persistence.PersistenceServiceConfiguration.json

configurations: []
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * ? * *
  - name: everyHour
    cronExpression: 0 0 * * * ?
  - name: everyDay
    cronExpression: 0 0 0 * * ?
defaultStrategies:
  - everyChange
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

At this point, persistence is broken - and RRDJ4 seems to save nothing.

Now the documentation continuously refers to persist config files “Persistence Strategies are configured in a file named .persist, stored in $OPENHAB_CONF/persistence. Replace “persistenceservice” with the name of your persistence add-on (e.g. rrd4j.persist).”. However, these steps to do create such a file.

If I now go back into the UI and “Edit persistence configuration” I can add a configuration for a group, restart openhab and I seem to be able to get persistence working again… All without .persist files.

configurations:
  - items:
      - Local_Sun*
    strategies:
      - everyChange
    filters: []
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * ? * *
  - name: everyHour
    cronExpression: 0 0 * * * ?
  - name: everyDay
    cronExpression: 0 0 0 * * ?
defaultStrategies:
  - everyChange
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

The documentation seems to refer to similar config but .persist files must have different formats and rules than the UI configured config but the docs don’t make this clear.

Now if I would like to have my /userdata/jsondb/org.openhab.core.persistence.PersistenceServiceConfiguration.json exactly replicate the default persistence the thing to do would be to add * for all items like the documentation suggest right? However, if I add * for items in the code (I can’t select in UI) it does not let me save - it gives me a validation error

Produces error on save: “YAMLReferenceError: Aliased anchor not found:”

configurations:
  - items:
      - *
    strategies:
      - everyChange
    filters: []
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * ? * *
  - name: everyHour
    cronExpression: 0 0 * * * ?
  - name: everyDay
    cronExpression: 0 0 0 * * ?
defaultStrategies:
  - everyChange
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

The alternative seems to be to select every item group but if I create new groups they won’t persist by default.

Questions I have

  1. Is there a way to replicate the default persistence via the UI config for RRDJ4? I can’t seem to find a way
  2. Is the documentation up-to-date? Should advice to beginners be use UI based config only if you want to get specific about each item/group. If you want to express default persistence for all items, you must use .persist files, not the UI config?

The ultimately goal I’m trying to achieve here is

  1. Retain RRDJ4 default persistence strategy and approach for all existing items, and all new items I will ever add - once I get that working, I want to then add
  2. MapDB persistence for specific string items that I want restored on startup.

MapDB config is in the same file as RRDJ4 config (/userdata/jsondb/org.openhab.core.persistence.PersistenceServiceConfiguration.json) so I’m getting stuck at point 1.

Thanks for your help!

I’ve just found a related post which might reveal the solution: Mapdb persist all items

The * needs to be wrapped in quotes. Will give this a try and report back if it works and if it does we will have a thread that recommends to the community how to configure rrdj4 and MapDB together using UI led configuration together.

Yes that is what I have been using for ages.
Seems to work.

configurations:
  - items:
      - "*"
    strategies:
      - everyChange
      - restoreOnStartup
    filters: []
cronStrategies: []
defaultStrategies: []
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

Thanks Greg - just test it and it works a treat.

I’m happy to volunteer to re-write parts of this documentation to better help users configuring persistence via the UI instead of the .persist files. Having to go to the code tab, and add quotes on * is a bit of an unintuitive hack!

For those who are looking at persistence config for the same goal I shared above - that is my config

  • rrd4j > all items, everyChange, everyMinute. This means all number items and switches are persisted everytime they change and at least once a minute (same as default). However, I turn off restoreOnStartup (see mapDB) which varies from default.
  • mapdb > all items, everyChange, restoreOnStartup. This means all item values (numbers, strings, switches) are persisted everytime they change. When the system restarts, all item states are restored even string values (this is key for me and some of my rules). For a new user, I think the above feels like a better “default” setup.

My rrd4j config looks like this (very similar to Greg’s). If you want this to be exactly the same as default persistence settings for rrd4j you just have to also select restoreOnStartup.

configurations:
  - items:
      - "*"
    strategies:
      - everyChange
      - everyMinute
    filters: []
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * ? * *
  - name: everyHour
    cronExpression: 0 0 * * * ?
  - name: everyDay
    cronExpression: 0 0 0 * * ?
defaultStrategies:
  - everyChange
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

My mapDB config looks like this

configurations:
  - items:
      - "*"
    strategies:
      - everyChange
      - restoreOnStartup
    filters: []
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * ? * *
  - name: everyHour
    cronExpression: 0 0 * * * ?
  - name: everyDay
    cronExpression: 0 0 0 * * ?
defaultStrategies:
  - everyChange
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

The resulting file generated from the UI changes looks like this /userdata/jsondb/org.openhab.core.persistence.PersistenceServiceConfiguration.json

{ 
  "mapdb": {
    "class": "org.openhab.core.persistence.dto.PersistenceServiceConfigurationDTO",
    "value": {
      "serviceId": "mapdb",
      "configs": [
        {
          "items": [
            "*"
          ],
          "strategies": [
            "everyChange",
            "restoreOnStartup"
          ],
          "filters": []
        }
      ],
      "defaults": [
        "everyChange"
      ],
      "cronStrategies": [
        {
          "name": "everyMinute",
          "cronExpression": "0 * * ? * *"
        },
        {
          "name": "everyHour",
          "cronExpression": "0 0 * * * ?"
        },
        {
          "name": "everyDay",
          "cronExpression": "0 0 0 * * ?"
        }
      ],
      "thresholdFilters": [],
      "timeFilters": [],
      "equalsFilters": [],
      "includeFilters": [],
      "editable": false
    }
  },
  "rrd4j": {
    "class": "org.openhab.core.persistence.dto.PersistenceServiceConfigurationDTO",
    "value": {
      "serviceId": "rrd4j",
      "configs": [
        {
          "items": [
            "*"
          ],
          "strategies": [
            "everyChange",
            "everyMinute"
          ],
          "filters": []
        }
      ],
      "defaults": [
        "everyChange"
      ],
      "cronStrategies": [
        {
          "name": "everyMinute",
          "cronExpression": "0 * * ? * *"
        },
        {
          "name": "everyHour",
          "cronExpression": "0 0 * * * ?"
        },
        {
          "name": "everyDay",
          "cronExpression": "0 0 0 * * ?"
        }
      ],
      "thresholdFilters": [],
      "timeFilters": [],
      "equalsFilters": [],
      "includeFilters": [],
      "editable": false
    }
  }

1 Like

Thats to be expected. You press save on an empty persistence config. That empty config overrides the default that gets used when there is no persistence config at all.

All managed configs get saved to the userdata/jsondb folder.

As with Items, Things, sitemaps, transformations and everything else in OH you can use managed configs (i.e. you do the configuration through MainUI) or you can create text based config files yourself (e.g. .persist, .items, .rules, .things, etc).

There might be a bug. The ability to select * through the UI config is relatively new.

Based on the error it’s not liking the *. As @ubeaut points out, the asterisk should be in quotes. If the UI is not putting it in quotes by default that’s a bug that needs to be fixed.

Either way, file an issue on the openhab-webuis repo.

To get the quotes on the asterisk I had to select the code tab on the mapdb UI settings page as I couldn’t do it from the design tab.