Simple HVAC Runtime Rule

Need a bit of help or a second set of eyes. In Summary, I have 2 rules one changes a counter between 0 and 1 depending on if the HVAC runs or not. The Counter is persisted in RR4DJ via the chartValues group. The second rule updates items that get charted for different time period.
However the Problem I’m running in to is the items for the different time periods are stuck at 1.

Items {
chartValues* = everyMinute

// Change HVAC Counter
rule "Change HVAC Counter"
when Item NestFamily_room_hvac_state changed
if (NestFamily_room_hvac_state.state!=“off”){
logInfo (“Nest”,“HVAC Counter set to 1”)
else {
logInfo(“Nest”,“HVAC Counter set to 0”)

// Record Total Daily HVAC runtimes
rule "Record HVAC Runtime"
Time cron "0 0/1 * * * ?"

I really have no idea why this wouldn’t work. Assuming everything is correctly set up as you say (i.e. HVACRuntimeC is a member of chartValues) you should get a 1 or a zero saved to the DB every minute and the sumSince calls should then give you pretty close to the number of minutes the HVAC has been ON (NOTE: as the data gets older rrd4j replaces yours 1’s and 0’s with the average of them over a certain time period, so your number of minutes will become less and less precise as you move from weeks to months to years in your time periods.)

I do note that your conditional may be wrong. Assuming NestFamily_room_hvac_state is a Switch it should be

if(NestFamily_room_hvac_state.state != OFF) {

The Rules language will not automatically convert the string “off” to the ONOFFType OFF.

Nest returns a string for the running state. Usually off, cooling, heating. It’s a string item.
The rule compares a literal string.
So that one actually works. I have it set to loginfo just to see when it changes the counter and it does show in the logs.

Here is the items file for the charting items.
Group HVACvsTemp
Group chartValues

Number HVACRuntimeC (chartValues,HVACvsTemp)
Number HVACRuntimeD “Minutes:[%s]” (chartValues,HVACvsTemp)
Number HVACRuntimeW “Minutes:[%s]” (chartValues,HVACvsTemp)
Number HVACRuntimeM “Minutes:[%s]” (chartValues,HVACvsTemp)

Please try to compare the String as a string:

if (NestFamily_room_hvac_state.state.toString != "off"){

I figured it out,

Thanks Guys but like I said the string compare isn’t the problem.
As RRD4J is only numerical I had db4o to capture and restore all my previous states and it was set as the default persistence in my OH.cfg.
I had to explicitly tell the sumsince to use “rrd4j”. It explains why it was stuck at 1 as the db4o only keeps last state.
The Persistence wiki needs some more clarification, for layman’s the use syntax isn’t listed. I had to dig through the git to see how it was implemented.

HVACRuntimeD.postUpdate(HVACRuntimeC.sumSince(now.minusHours(24))) had to be changed to HVACRuntimeD.postUpdate(HVACRuntimeC.sumSince(now.minusHours(24),

Also as Rich pointed out rrd4j by default averages the values and I’m still very confused on how to configure it to use COUNTER. I was hoping that 1 week and month wouldn’t be too much for the rrd4j before the values start getting inaccurate at a month it was already happening.
I’ve rewritten the code to stop persisting the Week and Month values in rrd4j and use db4o and some quick rules to sum the values to new items.

From the wiki page in the “Persistence Extensions in Scripts and Rules”:

These extensions use the default persistence service that is configured
in openhab.cfg. If the default service should not be used, all
extensions accept a String as a further parameter for the persistence
service to use (e.g. “rrd4j” or “sense”).

How did you configure this? I don’t use db4o but I was under the impression that only MapDB saved the most recent value only and that db4o (and all the rest for that matter) saved every value and require manual cleanup over time.

I’m attempting to add this to my set up but, as a novice, I’m having some problems. Designer is throwing some errors and I’m not sure what to do to resolve it:

I’ve added the items to my items list and updated my rrd4j settings as well though I’m thinking that has nothing to do with the rules error. Can someone be so kind as to point out what I’m doing wrong?

I’ve seen at least one other person report this problem. Designer can’t resolve references to “now” all of a suddenly. I wonder if there was an update that introduced a bug in Designer. If I have time I’ll check.

In the mean time, this should work just fine when run in OH. Run it and see if any errors are thrown. I bet there won’t be.

1 Like

@dinki: Please close the Designer, backup %USERPROFILE%.eclipse and remove
everything in that directory. Open Designer and open your configuration.
This fixed it for me. This behaviour is with Eclipse (not Openhab Designer).

[edit: This applies to Designer running on a Windows system; %USERPROFILE% ~ C:\Users<UserName>.eclipse]

1 Like

I couldn’t find the directory you specified. Looked in app data and other places too. Strangely, closing the program and reopening it and the files cleared the issue.

I’m certainly unintentionally hijacking this thread. The values are being recorded fine, but I’m having trouble displaying them on a chart in a useful fashion. I’d hope to be able to display a daily graph showing the total number of minutes run per day. I tried using this:

Chart item=HVACRuntimeD service="rrd4j" period="W" refresh="6000"

but this is what’s displayed:

Also, is there a way to turn off refresh altogether so that charts are only displayed once from the data that exist at that time? I keep seeing refreshes no matter the value I use for refresh. I’m assuming that value is in seconds.

The refresh is in milliseconds so 6000 is six seconds.

The chart will just show what is in the DB and there is little to nothing you can do to customize, tweak, or adjust the chart. So what you are currently seeing is what is actually being stored/calculated in the sumSince.

I can’t tell you why it is storing data like that. The first thing I would try is to swap over to db4o and see if the chart still looks like that. This will eliminate rrd4j weirdness as the cause of the problem. Otherwise there is something subtle about the code.

Instead running a postUpdate on all your Items every minute why not just when HVAC_RuntimeC changes? The .persist file handles the everyMinute part for you. Perhaps there is some weird edge case you are hitting causing you to miss out on some values when you run sumSince. It will be more efficient to boot.

I’m really just blindly copying the code as I thought it was working. Perhaps it isn’t. From the looks of it it is doing what you said but uses cron to update the values used for creating the graphs.

That’s what happens with my original code. I did mention a few posts back I had to revise it. I’ll post it when I get home.

1 Like

Just a reminder if you could post this it would be most appreciated! Thanks again.