[SOLVED] Persistence

I have a requirement to store 4x persistent variables, for 4x user selectable (using a habpanel widget/item combo) values. These values need to persist including through power cycles of the host (raspberry Pi).

The persistence addon seems an overkill for this reqt., so Is there anyway in HA/habpanel to store / retrieve these values say in a JSON within a file in area? or any area?

Why, that’s exactly one of the main use cases for why persistence exists.

If all you need is the one value, no charting or anything, use the MapDB which only stores one value per Item and configure those Items with the restoreOnStartup strategy. It’s an embedded database so all you need to do is install the add-on and configure the .persist file and you are done.

It doesn’t get too much more light weight than that

No, because this is the job provided by Persistence.

1 Like

erm, search.“mapdb” , on the forums, and you will see why I’m nervous about that! nothing but probs

Did you at least give it a try?
I am using MapDB since 2.4 without any issues in parallel with Influx.

MapDB is being used for all items whose values I want to restore on startup and all items that should be displayed in a chart are stored in Influx.

How does one “try” it?
Doc is poor, no synopsis, examples, or guide:

?

The first part of the article is the synopsis. There’s nothing more to tell about MapDB persistence.
Both configurational parameters are optional and that’s it. There’s nothing more to document. You just install it and for everything else regarding persistence you need the following

Have a look at my mapdb.persist: Besides installing that’s all I need. Every item i want to use i put into the group gRestoreOnStartup

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
    default     = everyChange
}

Items{
	gRestoreOnStartup*  :   strategy=everyChange, restoreOnStartup
}

Of course if you still don’t want to use it, create a rule that writes values to a file and after that use the systemstarted trigger to read those values. You then create a much less capable persistence that behaves like MapDB but you will have to struggle with creating and parsing files. And for every item you want to add, you need to change your code.

Sorry but i can’t see the what keeps you from using MapDB

2 Likes

I’ve used it since OH 1.6. Never had a problem with it.

@tillykeats, And I’m not aware of any problems you are finding on posts on the forum. Are you finding anything more recent than about three years ago? Can you site any “nothing but probs” more recent than a few years ago in specific? There were problems with MapDB back in the pre OH 2.0 time frame where MapDB was used instead of JSONDB.

If your data is numerical, you can use rrd4j instead. It too is embedded, limits itself in size.

It’s very simple.

  1. Install the MapDB add-on.
  2. Populate the mapdb.persist file according to the the first link above.
  3. Optionally, set it as the default persistence which you can do from Configuration → System in PaperUI.

Done.

There is an example .persist file showing how to do restoreOnStartup at Persistence | openHAB.

2 Likes

ok.

so I installed the mapDB Addon,

then

added org.eclipse.smarthome.persistence:default=mapdb to /etc/openhab2/services/runtime.cfg

then

created /etc/openhab2/persistence/mapdb.persist ::

Strategies {
  default = everyUpdate
}

Items {
  i_TRV_Lounge_Set_Temperature  ,
  i_TRV_Dad_Set_Temperature     ,
  i_TRV_Summer_Set_Temperature  ,
  i_HVAC_CH_Switch  ,
  i_HVAC_HW_Switch
  : strategy = everyChange, restoreOnStartup
}

Blow me down, it only WORKS. It’s ttoo easy !!! I was expecting to have to do more.

THANK YOU guys

1 Like

Just to head off a common mistake a lot of new users make. * is not a wild card. SomeItemName* does not mean “All Items that start with 'SomeItemName`”. It means “all members of the Group ‘SomeItemName’”.

It’s in the docs but a lot of users apparently miss it.

1 Like

I listed them explicitly, there was just 5 off in the end.

Very good. Working fine. Cheers [again] Ritch.

Daz