Generating Charts using rrd4j

Hi,
I’m running Openhab on a RaspberryPi3 and im logging temperature and humidity using a DHT11 sensor. Reading the sensor data using a python script and displaying it in the BasicUI works fine but no I also want to generate charts using rrd4j persistence.

What I already did:

  • Installing RRD4j persistence
  • Setting RRD4j as the default persistence in configuration - system
  • Configured the rrd4j.cfg and rrd4j.persist file

This is my items-file: balcony.items

Group gTemperatur

Number Weatherstation_Temperature "Temperatur [%.1f °C]" <temperature> (gTemperature) 
Number Weatherstation_Humidity    "Luftfeuchtigkeit [%.1f %%]" <humidity> (gTemperature)

String temperature_out { channel="exec:command:weatherstation_temperature:output" }
String humidity_out    { channel="exec:command:weatherstation_humidity:output" } 

This is my persist-file: rrd4j.persist

Strategies {
    // for rrd charts, we need a cron strategy, every Minute is a must have.
    everyMinute : "0 * * * * ?"
    // get the data reduced for older values to keep database small
    everyHour : "0 0 * * * ?"
    everyDay : "0 0 0 * * ?"

    default = everyChange
}

Items {
    // additionally persist Items
    gTemperature : strategy = everyMinute

}

This is my rules-file: balcony.rules

rule "Weatherstation Temperature"
  when
     Item temperature_out received update
  then
      Weatherstation_Temperature.postUpdate(
          ( ( Float::parseFloat(temperature_out.state.toString) as Number ) * 10 ) / 10
      )

end

rule "Weatherstation Humidity"
  when
     Item humidity_out received update
  then
      Weatherstation_Humidity.postUpdate(
          ( ( Float::parseFloat(humidity_out.state.toString) as Number ) * 10 ) / 10
      )
end

This is the rrd4j.cfg file:

# configure specific rrd properties for given items in this file.
# please refer to the documentation available at
# https://www.openhab.org/addons/persistence/rrd4j/
#
# default_numeric and default_other are internally defined defnames and are used as
# defaults when no other defname applies

#<defname>.def=[ABSOLUTE|COUNTER|DERIVE|GAUGE],<heartbeat>,[<min>|U],[<max>|U],<step>
#<defname>.archives=[AVERAGE|MIN|MAX|LAST|FIRST|TOTAL],<xff>,<steps>,<rows>
<defname>.items=weatherstation_temperature, weatherstation_humidity 

This is the sitemap-file: balcony.sitemap

// Name of file and name of sitemap has to be the same
sitemap weatherstation label="Raspberry Pi Wetterstation"
{
        Frame label="Temp+RH" {
            Text item=Weatherstation_Temperature
            Text item=Weatherstation_Humidity            
        }

    Frame label="Chart" {
        Chart item=gTemperature label="test" period=W refresh=1000

    }

}

And finally this is the things -file: balcony.things

Thing exec:command:weatherstation_temperature "Temperatur"    [command="python 
/etc/openhab2/scripts/dht11-raspberrypi/dht11_example.py temperature", transform="REGEX((.*?))", 
interval=60, timeout=10, autorun=true]
Thing exec:command:weatherstation_humidity "Luftfeuchtigkeit" [command="python 
/etc/openhab2/scripts/dht11-raspberrypi/dht11_example.py humidity",    transform="REGEX((.*?))", 
interval=10, timeout=10, autorun=true]     

So the question is what I am doing wrong? Did I set the wrong items in the rrd4j.persist and rrd4j.cfg file? Do I have do create the graph in the .sitemap file in another way?

Any help and suggestions is highly appreciated!

If you want to save each member of gTemperature, you need to use gTemperature* in your .persist file.

Additionally to Richs hint I suggest to comment out the .items line in your rrd4j.cfg file. You did not specify the .Def and .archives, that way the defaults would be used anyhow and I am not sure if the sole use of the .items line would cause problems.

Thanks for your suggestions.

I changed the rrd4j.persist file to:

Strategies {
    // for rrd charts, we need a cron strategy, every Minute is a must have.
    everyMinute : "0 * * * * ?"
    // get the data reduced for older values to keep database small
    everyHour : "0 0 * * * ?"
    everyDay : "0 0 0 * * ?"

    default = everyChange
}

Items {
    // additionally persist Items
    gTemperature* : strategy = everyMinute

}

and the rrd4j.cfg file to:

# configure specific rrd properties for given items in this file.
# please refer to the documentation available at
# https://www.openhab.org/addons/persistence/rrd4j/
#
# default_numeric and default_other are internally defined defnames and are used as
# defaults when no other defname applies

#<defname>.def=[ABSOLUTE|COUNTER|DERIVE|GAUGE],<heartbeat>,[<min>|U],[<max>|U], 
<step>
#<defname>.archives=[AVERAGE|MIN|MAX|LAST|FIRST|TOTAL],<xff>,<steps>,<rows>
#<defname>.items=gTemperature 

But the chart is still not shown…

In this case lets dig deeper.
Please check if there are .rrd files written at all. They should be in var/lib/openhab2/persistence/rrd4j
If there are files, delete them and see if it is working after that.
Checking the log files would help also.
For logging you would need to start the Karaf console and set:
log:set DEBUG org.openhab.persistence.rrd4j

If that doesn’t help we would look into the database using the REST API (the installation of the REST DOCS would be needed).
At a last resort and if nothing helps read Here. This user managed to get rrd4j working only after installing InfluxDB and Grafana. It doesn’t make sense to me but…

Thank you for your hep!

I checked in var/lib/openhab2/persistence/rrd4j and found the following files:
humidity_out.rrd
temperature_out.rrd
Weatherstation_Humidity.rrd
Weatherstation_Chart.rrf
Weatherstation_Temperature.rrd

I deleted all of them, rebooted the system but still no change.

Next I opened the Karaf console

openhab> log:set DEBUG org.openhab.persistence.rrd4j
openhab> log:tail
09:42:53.919 [WARN ] [i.basic.internal.render.ChartRenderer] - Chart cannot be rendered as item 
'gTemperaturee' doe                                                                                                                          s 
not exist.

First I saw this log and saw the typo so I fixed it in the sitemap file to gTemperature

10:07:35.633 [INFO ] [smarthome.event.ItemStateChangedEvent] - humidity_out changed from 64 
to 63
10:07:35.661 [INFO ] [smarthome.event.ItemStateChangedEvent] - Weatherstation_Humidity 
changed from 64.00000000 to 63.00000000
10:07:45.813 [INFO ] [smarthome.event.ItemStateChangedEvent] - humidity_out changed from 63 
to 64
10:07:45.836 [INFO ] [smarthome.event.ItemStateChangedEvent] - Weatherstation_Humidity 
changed from 63.00000000 to 64.00000000
10:07:55.999 [INFO ] [smarthome.event.ItemStateChangedEvent] - humidity_out changed from 64 
to 63
10:07:56.011 [INFO ] [smarthome.event.ItemStateChangedEvent] - Weatherstation_Humidity 
changed from 64.00000000 to 63.00000000
10:08:04.205 [WARN ] [.sitemap.internal.SitemapProviderImpl] - Filename `balcony.sitemap` does 
not match the name `weatherstation` of the sitemap - please fix this as you might see unexpected 
behavior otherwise.
10:08:04.226 [WARN ] [i.basic.internal.render.ChartRenderer] - Chart cannot be rendered as item 
'gTemperature' does not exist.
10:08:36.711 [INFO ] [smarthome.event.ItemStateChangedEvent] - humidity_out changed from 63 to 
62
10:08:36.733 [INFO ] [smarthome.event.ItemStateChangedEvent] - Weatherstation_Humidity 
changed from 63.00000000 to 62.00000000

But I don’t see anything about the rrd4j in the log file. Did I do something wrong?

That looks like rrd4j is not working at all.
Either uninstall and install rrd4j via PaperUI or restart the bundle via Karaf ( use bundle:list to get the number). After that check the logs for the starting rrd4j.

Edit
Additionally your group item is defined as " gTemperatur" without the ending e, in the sitemap you have it wrong!

I uninstalled rrd4j via paperUI und reinstalled it. I also fixed the second typo with gTemperatur to gTemperature in the sitemap :wink:
This is the log from the installation:

14:32:18.244 [DEBUG] [org.openhab.persistence.rrd4j        ] - BundleEvent INSTALLED - 
org.openhab.persistence.rrd4j
14:32:18.538 [DEBUG] [org.openhab.persistence.rrd4j        ] - BundleEvent RESOLVED - 
org.openhab.persistence.rrd4j
14:32:18.555 [DEBUG] [org.openhab.persistence.rrd4j        ] - BundleEvent STARTING - 
org.openhab.persistence.rrd4j
14:32:18.604 [DEBUG] [istence.rrd4j.internal.RRD4jActivator] - RRD4j persistence bundle has 
been started.
14:32:18.639 [DEBUG] [org.openhab.persistence.rrd4j        ] - ServiceEvent REGISTERED - 
{org.osgi.service.cm.ManagedService}={service.id=365, service.bundleid=216, 
service.scope=singleton} - org.openhab.persistence.rrd4j
14:32:18.709 [INFO ] [rsistence.rrd4j.internal.RRD4jService] - Removing invalid definition 
<defname> = null heartbeat = 0 min/max = 0.0/0.0 step = 0 0 archives(s) = [] 1 items(s) = 
[gTemperature ]
14:32:18.715 [DEBUG] [rsistence.rrd4j.internal.RRD4jService] - Created default_other = GAUGE 
heartbeat = 3600 min/max = NaN/NaN step = 1 6 archives(s) = [ MAX xff = 0.999 steps = 1 rows = 
3600 MAX xff = 0.999 steps = 10 rows = 1440 MAX xff = 0.999 steps = 60 rows = 1440 MAX xff = 
0.999 steps = 900 rows = 2880 MAX xff = 0.999 steps = 21600 rows = 1460 MAX xff = 0.999 steps 
= 86400 rows = 3650] 0 items(s) = []
14:32:18.723 [DEBUG] [rsistence.rrd4j.internal.RRD4jService] - Created default_numeric = 
GAUGE heartbeat = 60 min/max = NaN/NaN step = 60 6 archives(s) = [ AVERAGE xff = 0.5 steps 
= 1 rows = 480 AVERAGE xff = 0.5 steps = 4 rows = 360 AVERAGE xff = 0.5 steps = 14 rows = 
644 AVERAGE xff = 0.5 steps = 60 rows = 720 AVERAGE xff = 0.5 steps = 720 rows = 730 
AVERAGE xff = 0.5 steps = 10080 rows = 520] 0 items(s) = []
14:32:18.928 [DEBUG] [org.openhab.persistence.rrd4j        ] - ServiceEvent REGISTERED - 
{org.openhab.core.persistence.PersistenceService}={service.id=366, service.bundleid=216, 
service.scope=bundle, <defname>.items=gTemperature, service.pid=org.openhab.rrd4j, 
component.name=org.openhab.persistence.rrd4j, component.id=219} - 
org.openhab.persistence.rrd4j
14:32:18.983 [DEBUG] [d4j.internal.charts.RRD4jChartServlet] - Starting up rrd chart servlet at 
/rrdchart.png
14:32:19.025 [DEBUG] [org.openhab.persistence.rrd4j        ] - ServiceEvent REGISTERED - 
{javax.servlet.ServletContext}={osgi.web.version=1.13.0, osgi.web.contextpath=/, service.id=369, 
osgi.web.symbolicname=org.openhab.persistence.rrd4j, service.bundleid=216, 
service.scope=singleton, osgi.web.contextname=custom} - org.openhab.persistence.rrd4j
14:32:19.040 [DEBUG] [org.openhab.persistence.rrd4j        ] - ServiceEvent REGISTERED - 
{org.openhab.ui.chart.ChartProvider}={service.id=368, service.bundleid=216, 
service.scope=bundle, component.name=org.openhab.persistence.rrd4j.chartservlet, 
component.id=220} - org.openhab.persistence.rrd4j
14:32:19.047 [DEBUG] [org.openhab.persistence.rrd4j        ] - BundleEvent STARTED - 
org.openhab.persistence.rrd4j
14:32:19.078 [INFO ] [smarthome.event.ExtensionEvent       ] - Extension 'persistence-rrd4j' has 
been installed.

now I get the following message in the log:

14:34:51.246 [WARN ] [rthome.ui.internal.chart.ChartServlet] - Chart generation failed: null

EDIT:
I also followed the instructions from the other thread you linked and installed REST API:

GET/persistence
Accept language:
curl -X GET --header “Accept: application/json” “http://192.xxx.xxx.xxx:8080/rest/persistence

Response Body:
[
{
“id”: “mysql”,
“label”: “mysql”,
“type”: “Queryable”
},
{
“id”: “rrd4j”,
“label”: “rrd4j”,
“type”: “Queryable”
}
]

Response Code:
200

Response Headers:
{
“content-length”: “101”,
“server”: “Jetty(9.4.11.v20180605)”,
“content-type”: “application/json”
}

GET/persistence/items/{itemsname}
serviceID:
rrd4j
Itemname:
gTemperature

Response Body:
{
“name”: “gTemperature”,
“datapoints”: “0”,
“data”: []
}

So I assume rrd4j is installed correctly but no values are stored in the database?

Please do a GET request for the number items not the Group! If such shows no data your last assumption is correct.