Problem with using persisted values in a rule

Hello,
I have written a rule that is based on some astro-binding items (azimuth, elevation). The set point values of these items can be controlled via my sitemap. In order to having a defined state for these values after a restart of OpenHAB I have persisted the values with InfluxDB. My problem is that InfluxDB returns the values with a decimal point, e.g. “70.0” instead of only the value “70”. The result is that the rule is not working after a restart of OpenHAB until I have newly “clicked” and thus correctly “reactivated” the set point again in the sitemap. How can I solve the problem? Of course I could use fixed values for the items directly in the rule but that is not the solution I prefer because I would loose the comfort and flexibility the sitemap solution offers to me.
I would be happy if someone could give me a hint how to overcome that problem.

Thanks and best regards.

If you only want to persist values for a restart, you could switch to MapDB.
I think that would be the best solution. If you don’t want to draw charts over a time, InfluxDB is a bit of overkill:

Hi Sascha,

Thanks for the hint. I want to further use InfluxDB for charting (as I already do from the past). Do you know whether it is possible to use MapDB and InfluxDB in parallel without conflicts?

Yes, that’s possible. I’m running both

1 Like

Is there something special I have to take care about in the setup? How do I have to set it up best?
BR

Nope. Only one can be the default persistence service of course, so you may need to take care about specifying which service to use in e.g. charts

OK, does it mean, that

  • I can continue to use my existing InfluxDB persistence?
  • I can easyly install and use MapDB in parallel?
  • I have to designate the items I want to persist in MapDB within the mapdb.persist file? and
  • can keep the items I want to further persist in InfluxDB unchanged in my influxdb.persist file?
  • when I did the above things do I have to set MapDB as new default persistence or can I leave InfluxDB as default persistence like before and the things will work properly by individual designation of items in the two *.persist files only?

Here’s my Setup:

InfluxDB Persistence:

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

Items {
    gPersistence*       :   strategy=everyUpdate, everyChange, restoreOnStartup
}

MapDB Persistence:

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

Items{
	gRestoreOnStartup*  :   strategy=everyChange, restoreOnStartup
}

So each Item which should be only peristed for keeping the old value after reboot is put into the group gRestoreOnStartup and thus it will automatically use MapDB
All other items whose values should be persisted over a longer time are put into the group gPersistence

InfluxDB is my default persistence

1 Like

Perfect, Thanks for your help. Am I right, that it is not strictly necessary to do it by groups only but it would also be possible to use the individual items in the both *.persist files?

yes, you can also define individual items.
since i do have a lot of devices, it was simpler to group them and do the persistence group based.

Thank you very much for your help. I will consider the group approach too as the number of my items is also growing.
BTW: Do you know how to check whether the MapDB persistence works correctly? Is it possibe to see / check the stored value anyhow / anywhere?

Please be aware that you have to use the name of the persistence service if querying a persistence service from a rule other than the default persistence service:
mapdb as default:

// query from mapdb:
myPersistedItem.previousState(true).state
// query from influxdb:
myPersistedItem.previousState(true,"influxdb").state

This is a not working example, as mapdb is not able to answer the query correctly, but you get the point anyway…

Hello Udo,

Thanks for that hint. Is it obligatory to use the „true“ statement too or will it also work without, i.e. by

myPersistedItem.previousState("mapdb").state

in case InfluxDB would be the default persistence service?

previousState(true) and previousState() do slightly different things as described here

I don’t think either will work with mapdb, because there is no previous state in mapdb, it only stores one “current” state.