No rrd4j persistence items available via REST access (and in HABdroid)

Hi,

I have some persistence items defined in the following way:

Strategies {
    everyMinute : "0 * * * * ?"
}

Items {
    WeatherChart*, ThermostatSetTempChart*, TemperatureChart*, HumidityChart*, ThermostatValvePosChart* : strategy = everyMinute
}

However, when I try to access them via REST API, I only get an empty array: []

This is the exact result from the openHAB Rest UI:


          Curl
          curl -X GET --header "Accept: application/json" "http://raspberrypi:8080/rest/persistence/items?serviceId=rrd4j"
          Request URL
          http://raspberrypi:8080/rest/persistence/items?serviceId=rrd4j
          Response Body
          []
          Response Code
          200
          Response Headers
          {
  "date": "Fri, 16 Sep 2016 19:26:39 GMT",
  "content-type": "application/json",
  "content-length": "2",
  "server": "Jetty(9.2.14.v20151106)"
}

HABdroid also shows an empty graph.
But then again, if I access the classic UI from my PC, I can see the chart with data.
Also the log confirms that rrd4j is working:

2016-09-16 21:52:00.080 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Aeon_CO_Humidity' with state '54' in rrd4j database
2016-09-16 21:52:00.092 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Thermostat_WZ_SetTemp' with state '4.5' in rrd4j database
2016-09-16 21:52:00.104 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Thermostat_BR_Valve' with state '0' in rrd4j database

Any idea why this isn’t working? Do I need to install something else? I am using the OH2 snapshot of a few days ago.

Okay, I just checked the implementation.
The entry point for the REST call is apparently org.eclipse.smarthome.io.rest.core.persistence.PersistenceResource.httpGetPersistenceServiceItems() which seems to call org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate.getItemInfo().
This method again just returns an empty Set.

If I got this right, then that’s the reason why the rest call returns an empty array.

A GET call for a specific persistence item ( /persistence/items/{itemname}) actually works.

Still no clue why the chart shows up on classic UI but not on HABdroid though…

Okay, I just realized that my group items itself are not persisted anymore.
All items inside the group are persisted (I can see rrd4j files in userdata/persistence/rrd4j) but the group item itself doesn’t have a rrd4j file anymore. This has been working before as I have old rrd4j files for the group items.
Did anything change recently regarding this? I didn’t change my persistence configuration in a long time, just updated to the latest OH2 snapshot and the latest rrd4j binding recently.

Any ideas?

The only change to the persistence part that I am aware of is https://github.com/eclipse/smarthome/pull/1962. I don’t know, if this could be related.

And on group items, there was this change: https://github.com/eclipse/smarthome/pull/1963

I currently don’t have the time to investigate this myself, but maybe this helps you to identify the cause…

@Kai, thanks for the hint. I believe I found the issue but I don’t know what change triggered it:

The REST call (http://raspberrypi:8080/rest/items?recursive=false) returns all group items with type “Group”:

{
    "members": [],
    "link": "http://raspberrypi:8080/rest/items/TemperatureChart",
    "state": "UNDEF",
    "type": "Group",
    "name": "TemperatureChart",
    "tags": [],
    "groupNames": [
      "Temperature"
    ]
  }

However, the android client compares the type with “GroupItem” in order to determine the URL for the rrd4j chart.
Because the type is Group, and not GroupItem, the android client uses the rrd4j URL for plain items, which results in an empty chart: http://raspberrypi:8080/chart?items=TemperatureChart&period=4h&random=410744457

So seems to be a mismatch between OH2 and the android client?

And for the other issue (why the group items are not persisted), this is actually normal and is described in the documentation :slight_smile: Don’t know why I have rrd files for the group, they shouldn’t be there.

Ah, good catch! Yes, that is due to a (breaking) fix in the REST API - the Android app has been adapted recently, here.
But it seems that @digitaldan missed the code that you reference above. Could you create a PR for it? @digitaldan planned to push a new release to the Play store soon, so this fix should make it in there!

sure, I’ll try to make a PR later tonight!

Done: https://github.com/openhab/openhab.android/pull/225

one question how do i retrieve data for an item from persistence service ?

i tried: http://openhab:8080/rest/persistence/items/WS444_Sensor9_temperature

but i did not got datasets back, data is stores in rrd4j

thanks in advance

Lars

Try it with
http://openhab:8080/rest/persistence/items/WS444_Sensor9_temperature?serviceId=rrd4j

i tried already…

{
“name”: “WS444_Sensor9_temperature”,
“datapoints”: “0”,
“data”: []
}

but there should be datasets …

iḿ running on OH2

Did you check if the rrd4j files are written at all? (Using a apt-get installation they should be “var/lib/openhab2/persistrnce/rrd4j”)

How does your rrd4j.persist file look like?

an rrd4j files is there, a chart is drawn in habpanel :wink:

root@openhab:~# cd /var/lib/openhab2/persistence/rrd4j/
root@openhab:/var/lib/openhab2/persistence/rrd4j# ls -l
insgesamt 5024
-rw-r–r-- 1 openhab openhab 116408 Nov 13 00:13 GF_Kitchen.rrd
-rw-r–r-- 1 openhab openhab 116408 Nov 13 00:13 gWS444PC_Chart.rrd
-rw-r–r-- 1 openhab openhab 116408 Nov 12 22:55 gWS444PC.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 OH_Sensor9_temperature_AVG.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor0_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor0_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor1_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor1_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor2_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:06 WS444_Sensor2_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor3_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor3_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor4_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor4_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor5_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 12 21:24 WS444_Sensor5_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor6_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor6_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor7_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 12 21:24 WS444_Sensor7_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor8_humidity.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor8_temperature.rrd
-rw-r–r-- 1 openhab openhab 116408 Nov 12 15:35 WS444_Sensor9_forecast.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 17 20:07 WS444_Sensor9_humidity.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor9_pressure.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor9_rain_1d.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor9_rain_1h.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor9_rain_sensor.rrd
-rw-r–r-- 1 openhab openhab 415976 Nov 17 20:07 WS444_Sensor9_temperature.rrd
-rw-r–r-- 1 openhab openhab 28280 Nov 12 15:35 WS444_Sensor9_wind_speed.rrd
root@openhab:/var/lib/openhab2/persistence/rrd4j#

oot@openhab:/var/lib/openhab2/persistence/rrd4j# cat /etc/openhab2/persistence/rrd4j.persist
// persistence strategies have a name and a definition and are referred to in the “Items” section
Strategies {
// for rrd charts, we need a cron strategy
everyMinute : “0 * * * * ?”
}

Items {
// DemoSwitch,NoOfLights,Window_GF_Toilet,Heating* : strategy = everyChange, everyMinute, restoreOnStartup

// let's only store temperature values in rrd

// Temperature*,Weather_Chart* : strategy = everyMinute, restoreOnStartup
gWS444PC* : strategy = everyMinute, everyUpdate
}

// vim: syntax=Xtend syntax=openhab
root@openhab:/var/lib/openhab2/persistence/rrd4j#

So you are only persisting the items in group gWS4444PC.
The one item you tried to get data from seems to be updated when looking at the file date.
So you should have data from within the last day ( which is the default time frame for the REST query.
How do you show the chart in HABPANEL?

Thanks for the picture, but could you post the code that is used to setup this chart?

        {
            "name": "Wohnzimmer",
            "sizeX": 4,
            "sizeY": 2,
            "item": "WS444_Sensor2_temperature",
            "type": "chart",
            "row": 2,
            "col": 0,
            "charttype": "interactive",
            "service": "rrd4j",
            "period": "W",
            "isgroup": false
        },
        {
            "name": "Garten",
            "sizeX": 4,
            "sizeY": 2,
            "item": "WS444_Sensor9_temperature",
            "type": "chart",
            "row": 2,
            "col": 4,
            "charttype": "interactive",
            "service": "rrd4j",
            "period": "h",
            "isgroup": false
        },

Everything looks OK to me, so I’m out of ideas.
You are persisting data (.rrd files get updated, habpanel shows the charts from the rrd4j database).

From where do you try to access the database via the REST or HABDroid, from the local net or from somewhere else (for HABdroid it would be through MyOpenHAB and should work)?