Persist mqtt in rrd4j

Hey folks, first of all i am quiet new to the OpenHAB community. I read a lot of topics and saw that the pros here :wink: are very helpfull IF we newbies read the docs but i actually cant find a solution for my problem.

I would like to show the Temperature and the Humidity from my ESP8266 with a DHT22 Sensor in a chart on my Sitemap and in the Android App.

I Installed the MQTT Broker on OpenHAB and Mosquitto as a Server on the Pi (OpenHAB and Mosquitto server are the same Pi). I can see the values ​​in MQTT.fx and on my Sitemap.

Now i want to make a chart for day, week, month and year. But i think mqtt is not saving the data in rrd4j.

rrd4j.persist:

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

Items {
        gDHT22_Sensor* : strategy = everyMinute, everyChange, restoreOnStartup
}

graph.items

Group gDHT22_Sensor "Chart Group"

Number chart period

Number FilaBox_Luftfeuchte "Humidity Filabox [% ​​.1f %%]" <humidity> (gDHT22_Sensor) {mqtt="<[mosquitto:/esp8266/sensor2_humidity_1]"}
Number FilaBox_Temp "Filabox temperature [% .1f °C]" <temperature> (gDHT22_Sensor) {mqtt="<[mosquitto:/esp8266/sensor2_temperature_1]"}

At this point i am not sure exactly what do i need to input for the broker name (called here mosquitto). Is mosquitto the right one here or is it a specific name or maybe localhost for the same System?

default.sitemap

        Frame label = "Filament Box" {
                Text item = ESP8266_DHT22_temperature label = "Temperatur [% .1f ° C]" icon = "temperature"
                Text item = ESP8266_DHT22_humidity label = "Humidity [% .1f %%]" icon = "humidity"

                Frame label = "Graphic of the values" icon = "chart" {
                        Switch item = chartPeriode label = "Period" mappings = [0 = "Day", 1 = "Week", 2 = "Month", 3 = "Year"]
                        Chart item = gDHT22_Sensor period = D refresh = 60000 service = "rrd4j" visibility = [chartPeriode == 0]
                        Chart item = gDHT22_Sensor period = W refresh = 60000 service = "rrd4j" visibility = [chartPeriode == 1]
                        Chart item = gDHT22_Sensor period = M refresh = 60000 service = "rrd4j" visibility = [chartPeriode == 2]
                        Chart item = gDHT22_Sensor period = Y refresh = 60000 service = "rrd4j" visibility = [chartPeriode == 3]
                }
        }

And finally some details from the REST API

GET / persistence / items / {itemname}

Curl

curl -X GET --header "Accept: application / json" "http://192.168.xxx.xxx:8080/rest/persistence/items/FilaBox_Temp?serviceId=rrd4j"

Request url

http://192.168.xxx.xxx:8080/rest/persistence/items/FilaBox_Temp?serviceId=rrd4j

Response body

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

is that correct that the mqtt does not safe any data to rrd4j and i can saw that at the zero datapoints?

i appriciate any help
Greetings Hendrik

Welcome fo the openHAB forum :wave:

Your topic title gives your final goal, however you are not there yet. I suggest you go step by step.

You can see your MQTT devices report temperature and humidity via MQTTfx, so your problem is concerning openHAB and its connection to MQTT.
I have to assume you are using a openHAB version 2.5.xxx, hence you are using the MQTT binding version 2, however this one needs a different syntax to link items to thing channels ( which you probably haven’t created).
Most users use such devices flashed with Tasmota, so there are a lot of tutorials reflecting such, see Here

I would also recommend going the Tasmota route, and using the V2 version of the MQTT binding: your Item configurations are for the V1 version of the MQTT binding. The following might also help:

not exactly. i can see the values in my sitemap too, not only in MQTTfx.

Yes. i am using 2.5.10 OpenHAB and the MQTT binding V2

the mqtt thing file is already created:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
        host="127.0.0.1", 
        secure=false, 
        clientID="openHAB2"
]
{
        // DHT22 Luftfeuchtigkeitssensor fuer FilamentBox mit ESP8266
        Thing mqtt:topic:ESP8266_DHT22  "Filament Box" @ "Keller" {
                Channels:
                        Type number : Luftfeuchtigkeit "Luftfeuchtigkeit" [ 
                                stateTopic="/esp8266/sensor2_humidity_1"
                        ]
                        Type number  : Temperatur "Temperatur" [
                                stateTopic="/esp8266/sensor2_temperature_1"
                        ]
        }
}

Tasmota looks nice but i would like to try first the way i am already going. I think its just a little mistake anywhere.

If i cant go further i definetly try tasmota

@hafniumzinc i saw that link already but as i say i would like to go first the way i said. Where is the difference between the V1 and V2 items binding? On the Documentation site from MQTT V2 are no examples or anything about items

In case you are using the actual MQTT binding the above posted item definition are wrong (version 1 mqtt syntax!).
Check on PaperUI for the correct channel syntax in order to create a valid link.

Are the items you see on the sitemap members of the defined
gDHT22_Sensor group?
Did you check whether any .rrd files are created?

As we mentioned, your Items are using the V1 syntax. For V2 it should say something like channel=... instead of mqtt=.... Check the links provided for the correct syntax.

Yes, annoys me too. Perhaps check this:

The above link will also show you that you have a minor syntax error in your Thing definition too, although it should still work! Just sort the Items out!

1 Like

I linked the “FilaBox_Luftfeuchte” and “FilaBox_Temp” to the group “gDHT22_Sensor” as you see in the graph.items file and then i used the group name in the .sitemap file, or do you mean something else?

.rrd file are created. I delete them after any change for a clear initialisation

@hafniumzinc
ahh its the channel thing for V2 thats good to know ^^

The GitHub link look good, i will try it

:+1:

Get your Items sorted, then make sure your Items display properly on your Sitemap/BasicUI, and only then concentrate on the rrd4j persistence!

1 Like


and when done with the correct items definition please post the respective lines and post which .rrd files ( names) are created. That will help looking into the persistence problem.

my chart shows finally both data from the sensor :+1: the problem was the V1 Syntax :wink:

changed

Number FilaBox_Luftfeuchte "Humidity Filabox [% ​​.1f %%]" <humidity> (gDHT22_Sensor) {mqtt="<[mosquitto:/esp8266/sensor2_humidity_1]"}
Number FilaBox_Temp "Filabox temperature [% .1f °C]" <temperature> (gDHT22_Sensor) {mqtt="<[mosquitto:/esp8266/sensor2_temperature_1]"}

to

Number FilaBox_Luftfeuchte "Luftfeuchtigkeit Filabox [%.1f %%]" <humidity> (gDHT22_Sensor) {channel="mqtt:topic:ESP8266_DHT22:Luftfeuchtigkeit"}
Number FilaBox_Temp "Temperatur Filabox [%.1f °C]" <temperature> (gDHT22_Sensor)  {channel="mqtt:topic:ESP8266_DHT22:Temperatur"}

i know i have Celsius and percentage values in one chart, but for me is it perfect.
Now there is one problem left. I cant see the chart on the Android App. I think its because i need to click the “TAG” “WOCHE” “MONAT” or “JAHR” to see the chart, but i cant see the buttons on the App. The only thing the App shows me is “Grafik der Werte” nothing else.

oh and @opus the .rrd files wich one are created are the both item values (FilaBox_Luftfeuchte.rrd and FilaBox_Temp.rrd)

1 Like

So you have solved the persistence problem.

On the problem with missing buttons on the android app:

You need a initial selection in order to show a chart because you haven"t set a chart for the case that the selection hasn’t been made ( ==“NULL”). Put that one additionally to a present case.
I can’t say why the buttons do not show, my sitemap looks like yours exempt that I don’t have the frame with the charts in another frame, mine is a following frame.
Unless you have changed the above posted sitemap.

1 Like

Got it! I add the

chartPeriode=="Uninitialized"

parameter to the first Chart.

The Problem with the buttons was the Frame in the Frame. I Put it into one single Frame now and it is working well

Thanks for all your help @opus @hafniumzinc this chart and the persistence took me a couple of days, but i learned a lot :slight_smile: