Rrd4j chart size, max min values

Hi, I have installed openhab2 on raspberry pi 3b+, hooked up arduino mega board and setup serial data communication. All working well, but now want to fine tune Basic UI interface. I have set up rrd4j environment and got chart plots to display simple data, power usage, voltage e.t.c. I’m still using/modifying demo files to get concept working so I have several questions:

  1. How to resize plot as it is quite small when working from PC:
  2. How to get max and min data from rrd4j database, I tried an example found in here on other topic, however I’m facing with the same issue user had - Max data following current data. Rule I have been using:

sitemap file:

	Frame label="Power"{
	    Text item= Grid_Power valuecolor=[>5000="red",>1500="orange",<=1500="green"]{
				Text item=Power_Watt_Max valuecolor=[>5000="red",>1500="orange",<=500="green"]
				Text item=Power_Watt_Min valuecolor=[>5000="red",>1500="orange",<=500="green"]
				Text item=Power_LastUpdate visibility=[Power_LastUpdate>30] valuecolor=[Power_LastUpdate>120="orange", Power_LastUpdate>300="red"]		
		    Frame {
				Switch item=Power_Chart_Period label="Chart Period" icon="chart" mappings=[0="Hour", 1="Day", 2="Week", 3="Month", 4="Year"]
				Chart item=Grid_Power period=h refresh=60000 visibility=[Power_Chart_Period==0, Power_Chart_Period=="NULL"]
				Chart item=Grid_Power period=D refresh=60000 visibility=[Power_Chart_Period==1]
				Chart item=Grid_Power period=W refresh=60000 visibility=[Power_Chart_Period==2]
				Chart item=Grid_Power period=M refresh=60000 visibility=[Power_Chart_Period==3]
				Chart item=Grid_Power period=Y refresh=60000 visibility=[Power_Chart_Period==4]
	    Text item= Arduino_gvol valuecolor=[>250="red",>170="green",>150="orange",<=150="red"]{
			    Text item= Arduino_gvol valuecolor=[>250="red",>170="green",>150="orange",<=150="red"]
		        Chart item=Arduino_gvol label="Grid Voltage" period=h refresh=60

item file:

Group Grid_Power_Chart
Number Grid_Power               "Power [%.0f W]"                <energy>      (Power, Power_Chart)
Number Power_Watt_Max           "Todays Maximum [%.0f W]"       <energy>      (Power, Power_Chart)
Number Power_Watt_Min           "Todays Minimum [%.0f W]"       <energy>      (Power, Power_Chart)
Number Power_Chart_Period       "Chart Period"
DateTime Power_LastUpdate       "Last Update [%1$ta %1$tR]"     <clock>

rules file:

rule "Set daily max and min power"
	Item Grid_Power changed or
	Time cron "0 0 0 * * ?" or
	System started
    val max = (Grid_Power.maximumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue
	val min = (Grid_Power.minimumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue
    if( max != null && min != null) {

rrd4j.persist file:

// 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 {
    Grid_Power, Arduino_gvol, DemoSwitch, NoOfLights, Window_GF_Toilet, Heating* : strategy = everyChange, everyMinute, restoreOnStartup
    // let's only store temperature values in rrd
    Grid_Power*, Arduino_gvol*, Temperature*, Weather_Chart* : strategy = everyMinute, restoreOnStartup

// vim: syntax=Xtend

Don’t forget how rrd4j works. By design, it compresses older data … meaning you wouldn’t get accurate max/min over the long term anyway. I’ve no idea if it gives you a reasonable answer for today only.

If that doesn’t suit you, consider persisting to another database, there are lots of choices.

For today’s max/min, I wouldn’t bother with persistence.
At midnight, reset to zero.
Every time source data changes, compare to “max”. If bigger, copy. If not, don’t.

1 Like

Thanks for reply Rossko, yes, I guess so too about rrd4j database. What about resizing charts, is it problematic too?

Rossko, thank you so much!!!

just copying solution here:

Chart size can be set on the paperUI interface Configuration -> System -> Charts

1 Like