Rrd4j works for some item and does not work for calculated ones

Hi, I set up rrd4j charting with OH2 on raspberry pi
I can chart sensor data which is coming to oh via mqtt.
but when I calculate a new item in OH rule, the new Item can not be charted.
my Item is like this:

Number  h4        "[%.1f]"
Number  t1        "[%.1f]"

rrd4j.cfg:


openhab.def=GAUGE,90,0,3,60
openhab.archives=MAX,.5,1,1440:MAX,.5,5,2016:MAX,.5,15,2668
openhab.items=*

persistence:

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

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

t1 is coming from temperature sensor and can be charted
but h4 is calculated by t1 …and can not be charted,


the formula which calculate h4 is sth like this:

val edw = [ t |
        var denominator = 240.97 + t
        var numerator = 17.502 + t
        var exponent = numerator / denominator
        var pow = Math.pow(Math.E, exponent)
        return 6.112 * pow
    ]
    val Number t2Var = t2.state as Number
    val Number t1Var = t1.state as Number    

    val ed44 = edw.apply(t2Var)
    val ew44 = edw.apply(t1Var)

    val numeratora = 1 + .00115*ew44
    val numeratorb = ed44-ew44
    val numerator = edw44 - 0.6687451584 * numeratora * numeratorb
    val div = numerator / ed44
    h4.postUpdate(div * 100)

check if it’s persisted log:set debug org.openhab.persistence.rrd4j (from memory).
You can also add h4.persist

1 Like

Have you restarted OH2 since you created your Items? Persistence strategies are only acted on at startup.

1 Like

when I type this command, return -bash: log:set: command not found
but I have these in /var/lib/openhab2/persistence/rrd4j :

I also restart oh2 and restart system
edit: for memory thing, i disabled logging, I dont know it is related or not

Use REST API Docs to inspect your Item. Does it have a state?

If you changed the Item type at some time, that will mess up its persistence. You would need to delete h4.rrd so that it creates a new one.

“memory thing”?
Having no logging leaves you unable to solve problems.

1 Like

The command I gave must be issued on the (Karaf) console.
Since you don’t know that, please get your basics right before asking for help.
It’s all in the docs so go read those next.

1 Like

thanks
I logged in to console, check the tail:

it is persisting
@rossko57
I deleted rrd file and it generates again, but same result and also change the rule and change type to number and delete rrd file again, same thing happes, t1 appears but not the calculated one:

rule "cadd4dd"
when
      Time cron "0 0/1 * 1/1 * ? *"
then
        ex1 = (17.502 * t3.state as Number) / (240.97 + t3.state as Number)
        ed444 = 6.112 * Math.pow(Math.E, ex1)
        ex2 = (17.502 * t1.state as Number) / (240.97 + t1.state as Number)
        ew444 = 6.112 * Math.pow(Math.E, ex2)
        minus = (t3.state as Number - t1.state as Number)
        part1 = 1+0.00115*t1.state as Number
        h4.sendCommand((((ew444 - 0.6687451584 * (part1) * (minus)) / ed444)) * 100)
end

and about the memory, i disable the log to extend my sd card age!

Bad idea. Get openHABian and use zram.

1 Like

So in fact everything is persisting fine, but your chart doesn’t work.
Time to show how you request the chart.

2 Likes

thanks, here is the sitemap:

Switch item=h44 label="timefram" mappings=[0="1D", 1="1W", 2="1M"]
    Chart refresh=60000 period=D visibility=[h44==0, h44=="Uninitialized"] item=h4
    Chart refresh=60000 period=W visibility=[h44==1] item=h4
    Chart refresh=60000 period=M visibility=[h44==2] item=h4

Out of curiosity, I check HABMin panel for charting! when selecting item to chart, there is no h4 in there, but t1 exists!
the only difference between the two is the way they created, t1 is created via paperUI and h4 is defined in item file.
so, I add an item via paperui for calculating humidity to see if it works or not.
when I create new item in paperui, and calculate humidity via rule file.
now charting works! :grinning:
but strangely, new item can not be shown in sitemap! :neutral_face:
I mean the value doesnt show up in sitemap:

Text item=h4 icon="humidity" label="humidty"

I can postUpdate two items for charting and showing them, no problem here. but it is strange!

You haven’t asked for a value to be shown.

Text item=h4 icon="humidity" label="humidty [%d]"

or add [state description] to your Item label