[SOLVED] Cant get persistence for Location item working

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: raspian
    • Java Runtime Environment: 1.8.0_191
    • openHAB version: 2.3.0
  • Issue of the topic:
    I use the icloud binding to populate location data of my iphone to OH (coordinates, accurancy, last update, etc).
    Now I would like to add the location item SimonsIPhoneICloud_Location to the rrd4j DB I am running since ever to persist my item states.
    Unfortunately it doesn´t persist them.
    Strategies {
    everyMinute  : "0 * * * * ?"
    every5Mins   : "0 0/5  * * * ?"
    everyHour    : "0 0 * * * ?"
    everyDay     : "0 0 0 * * ?"
    default = everyChange
    }


Items {
...
   SimonsIPhoneICloud_Location : strategy = everyMinute, restoreOnStartup
}

I can easily visualize the position on a map :

sitemap map  {
Frame label="Location" {
Text item=SimonsIPhoneICloud_LastLocationUpdate label="letztes update:[%1$ta %1$tR]"
        Mapview item=SimonsIPhoneICloud_Location label="Da ist er!" height=8
        }
}

Checking the REST API tells me that there are no datasets available:
http://192.168.1.10:8080/rest/persistence/items/SimonsIPhoneICloud_Location
response body:

{
  "name": "SimonsIPhoneICloud_Location",
  "datapoints": "0",
  "data": []
}

For other items persistency works well - can it be related to the items type location?
Thanks.

Yes it wont work with Location. You can persist it manually, by persisting altitude latitude and longitude

Thanks - that was quick! I evetually split it up and persist them separately.

The reason behing that is that rrd4j only store Numbers!!
As explained in the documentation here:

Introduction NOTE:

NOTE: rrd4j is for storing numerical data only. Attempting to use rrd4j to store complex datatypes (e.g. for restore-on-startup) will not work.

However Location is only a set of float Numbers as well, right?

I know that is because the DB doesn’t know that and it just tries to store it as a whole ‘data’, but maybe some hack could be introduced in OH, where if you want to store a Location data it stores automatically in 3 value:
ItemName_Latitude, ItemName_Longitude, etc…
Also this could work vice-versa, if you want to get a persisted Location element, OH should look for this 3 db value and it could build a Location item from it.

I know you can do it simply via rules, but it can be good…

a set of numbers, not a number

1 Like

For restoreOnStartup, it is recommended to use madDB:

First line of the intro paragraph

Hey there,

how can I persist the altitude, latitude and longtitude separately if I have one Location item?

Thanks,
Viktor

Split it up into three items

Right.
Simply by accessing myLocationItem.latitude?

The other thread incudes a rule extracting lat long values.

Hi,

seems I’m not getting it. In the other thread for me it looks like they get two separate values for mqtt and do not extract anything from a single Location item.

You’re right, that was a rubbish reference from me

I think you can do
var lat = (myLocationItem.state as PointType).latitude
var lon = (myLocationItem.state as PointType).longitude

Have a look at my post here.

Thanks, guys. I’m gonna have a look. I think it helps :slight_smile:
Cheers