[SOLVED] Chart is a straight line - Persistence issues?

Hi there,

I’ve been setting up an OpenHAB2 install to possibly migrate my OH1 in the near future.
I set up a group number item (SUM) to add power from items that are on, and rules to define these values according to when they are ON or OFF. From the logs I can see values and sums are stored correctly, but I tried to plot a chart on the sitemap and all I get are straight lines.

So I have a gPotencia group which contains 3 group number items for each phase - gPotencia1, gPotencia2, gPotencia3. gPotencia is also a part of gHistorico group, which is defined in the RRD4J persistence file, as well as gPotencia (just in case).

In the persistence folder I have a persistence file for mapdb and another one from rrd4j, copied straight out of my OH1.x install, and persistence seems to be working for switch items, but I would say the straight line is a symptom that rrd4j persistence isn’t working, or am I missing something?
Also default persistence is set in PaperUI as mapdb.

mapdb.persist:

Strategies {
        default = everyUpdate
}

Items {
        // persist all items on every change and restore them from the db at startup
        * : strategy = everyChange, restoreOnStartup
}

rrd4j.persist

Strategies {
        // for rrd charts, we need a cron strategy
        everyMinute : "0 * * * * ?"

        default = everyChange
}

Items {
        // additionally persist weather info every minute
        gHistorico* : strategy = everyUpdate, everyMinute
        gPotencia* : strategy = everyMinute, everyChange, restoreOnStartup
}

Items:

Group           gHistorico                  "Histórico"					<chart>     	   	(Box)

Group						gPotencia					"Potências"							<chart>				(gHistorico)	
Group:Number:SUM			gPotencia1					"Potência F1  [%.1f] Watts"			<energy>			(gPotencia)
Group:Number:SUM			gPotencia2					"Potência F2  [%.1f] Watts"			<energy>			(gPotencia)
Group:Number:SUM			gPotencia3					"Potência F3  [%.1f] Watts"			<energy>			(gPotencia)

And the resulting chart:

chart%20(4)

The lines change according to the values at the time, but it’s as if it isn’t storing past values.
Any clues? Thanks!

You show no items only groups, are they defined elsewhere?

What do you say by that? You see the green, blue or red line change its value? I don’t understand.

Hi Jurgen,

If I turn something ON or OFF, the SUM value for the corresponding group changes accordingly, and the line on the graphic changes to that value. So the last value and the ones before that aren’t being stored I think, because I only ever see a line with the current value.

Hope I explained it better. Thank you!

Please show the actual items that make up the groups!

I have several, they are all defined like this:

Number		Watts_LuzGab			"Pot. Luz Gabinete [%.0f W]"					<energy>		(gPotencia2)

And a rule to set the value. It’s not the most efficient way to do this, but until I install actual meters, I can get pretty close with this.

rule "potencias estimadas LuzGab"
when
	Item LuzGabinete changed
then
	if(LuzGabinete.state==ON)
		Watts_LuzGab.postUpdate(18)
	else
	if(LuzGabinete.state==OFF)
		Watts_LuzGab.postUpdate(0)
end

There are several similar items, and logs show the values for for each group changing as each item is changed.

2019-02-06 17:54:00.163 [vent.ItemStateChangedEvent] - Watts_ExtEstacion changed from 0 to 200

2019-02-06 17:54:00.167 [GroupItemStateChangedEvent] - gPotencia1 changed from 354 to 554 through Watts_ExtEstacion

2019-02-06 17:54:00.180 [vent.ItemStateChangedEvent] - Watts_ExtCartaz changed from 0 to 100

2019-02-06 17:54:00.183 [GroupItemStateChangedEvent] - gPotencia3 changed from 750 to 850 through Watts_ExtCartaz

But these changes aren’t stored. All I get is a line at the value it is currently.

How is the chart defined?

If I understand correctly the actual change of a group to the value xx is shown as line on value xx for the whole time?
Does this actual value correspond with the values written in the log?

As you use rrd4j, you must also apply the everyMinute persistence strategy. everyUpdate is NOT sufficient for rrd4j.

How is the chart defined?

Chart item=gPotencia period=D refresh=10000 visibility=[CHART_PERIOD==0, CHART_PERIOD=="Uninitialized"]

If I understand correctly the actual change of a group to the value xx is shown as line on value xx for the whole time?
Does this actual value correspond with the values written in the log?

Yes, that is correct, and the values are correct. There are 3 lines, one for each of the sums of powers from each phase stored by gPotencia1, gPotencia2, gPotencia3 which all belong to group gPotencia which is set in the rrd4j persistence file as everyUpdate and everyMinute.

Should I set the default persistence on PaperUI to rrd4j? I thought it wasn’t recommended. On my OH1.x, I believe mapdb is used for every item state, apart from the numbers that belong to the gHistorico group, which is specified in the rrd4j persistence file and therefore handled differently.

As you use rrd4j, you must also apply the everyMinute persistence strategy. everyUpdate is NOT sufficient for rrd4j.

This is the exact same setup (albeit for temperatures) that I have on my OH1.9 system, and it works fine there. I copied the persistence files from there, and the rrd4j strategy is specified for groups gHistorico and gPotencia are everyMinute and everyUpdate.

If you do not specify the persistence in the Chart Definition, the Default persistence will be used! That might be mapDB in your case. Either set the used persistence in the Chart Definition or set rrd4j as the Default.

Hi Jurgen,

No luck. Added the service="rrd4j" to the chart definition, and now there is nothing showing up, just the blank chart.

Switch item=grafPotPeriod label="Período Gráfico" icon=line mappings=[0="Hora", 1="Dia", 2="Semana"]
       							Chart item=gPotencia period=h refresh=300000 service="rrd4j" visibility=[grafPotPeriod==0, grafPotPeriod=="Uninitialized"]
       							Chart item=gPotencia period=D refresh=300000 service="rrd4j" visibility=[grafPotPeriod==1]
       							Chart item=gPotencia period=W refresh=300000 service="rrd4j" visibility=[grafPotPeriod==2]

chart%20(5)

Any ideas on how to get to the bottom of this? I’ve been reading other threads and trying other things but so far no luck.

1 Like

You solved one problem ( mapdb does store the last value only, hence the line). Now the problem is that the rrd4j database might not be storing (yet).
If you have REST Docs installed you could check if there are any values stored at all.
It migth only need a restart of openHAB to resolve, but let’s do one step after the other.

Is there any file called gPotencia1.rrd in your database folder?
In linux: /var/lib/openhab2/persistence/rrd4j

I don’t have REST Docs installed but I will look in to it.

Is there any file called gPotencia1.rrd in your database folder?
In linux: /var/lib/openhab2/persistence/rrd4j

Yes, I have rrd files for each of the 3 groups, and each of the items within each group.

-rw-rw-r--  1 openhab openhab    116408 Feb  8 08:37 gPotencia1.rrd
-rw-rw-r--  1 openhab openhab    116408 Feb  8 08:37 gPotencia2.rrd
-rw-rw-r--  1 openhab openhab    116408 Feb  8 08:37 gPotencia3.rrd
-rwxrwxr-x  1 openhab openhabian     32 Dec 17 08:01 Readme.txt
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_356.rrd
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_478.rrd
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_ExtCartaz.rrd
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_ExtEstacion.rrd
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_LuzDispRC.rrd
-rw-rw-r--  1 openhab openhab     28280 Feb  8 09:12 Watts_LuzGab.rrd

And it could be working. Just as I pasted this code I realized the gPotencia1, 2 & 3 rrd files weren’t being updated every minute.
So I added a strategy for each number group item:

Strategies {

        everyMinute : "0 * * * * ?"

        default = everyChange
}

Items {

        gHistorico* : strategy = everyMinute, everyUpdate, everyChange
        gPotencia* : strategy = everyMinute
        gPotencia1 : strategy = everyMinute, everyUpdate, everyChange
        gPotencia2 : strategy = everyMinute, everyUpdate, everyChange
        gPotencia3 : strategy = everyMinute, everyUpdate, everyChange
        //, everyChange, restoreOnStartup
        undefined : strategy = everyMinute
}

May be overkill but the files are getting updated every minute now, and chart data has begun showing up. Need a few more hours to check wether it’s working properly, but so far so good!

Maybe because the items themselves are group. That maybe caused the issue.
You could change the file to:

        gHistorico* : strategy = everyMinute, everyUpdate, everyChange
        gPotencia* : strategy = everyMinute
        gPotencia1, gPotencia2, gPotencia3 : strategy = everyMinute, everyUpdate, everyChange

Yes, for now it is working.
I changed the code like you said to make it a little better. Thanks!