I’m having trouble with a portion of my rule not working. I recently started logging run time on my HVAC system. It is set up to calculate in minutes but I’d like a more readable format. I’m trying to convert to hours:
rule "Record HVAC Runtime"
Time cron "0 0/1 * * * ?"
val twoDays = HVACRuntimeC.sumSince(now.minusDays(1).toDateMidnight))
val today = HVACRuntimeC.sumSince(now.toDateMidnight)
val yesterday = twoDays - today
val todayhr = (today / 60)
The variables ‘twoDays’, ‘today’, and ‘yesterday’ all work as expected, but the variable ‘todayhr’ is either being used incorrectly or it’s not getting a value as I never get a value posted for ‘HVACRuntimeDhr’ item.
Here’s my item definitions:
Number HVACRuntimeC (chartValues,HVACvsTemp,Persist)
Number HVACRuntimeD "Runtime Today[%d min]" <status> (chartValues,HVACvsTemp,Persist)
Number HVACRuntimeDhr "Runtime Today[%.2f hr]" <status> (chartValues,HVACvsTemp,Persist)
I’m still very new at all this and could use any guidance you can offer. Thanks!
Do you see any errors in openhab.log?
How do you know? Did you logout the values or are you assuming they are working because the value that gets assigned to HVACRuntimeY makes sense?
The fact that it is posting something to HVACRuntimeY but HVACRuntimeDhr remains undefined implies that there is an error. Knowing what the error is will help.
Try adding a .0 to the 60 in the divide. That will force it to calculate a floating point value rather than an integer. That could be a problem.
You could also force it to be a Number by defining it as such:
val Number todayhr = today / 60.0 // the parens don't do anything here so I omitted them
You could also try posting it as a String and let OH parse it back into a number.
You may get the feeling that I’m just stabbing in the dark. That is because I am. I’m pretty certain there is an error being printed to the log when this runs which will be helpful.
Apologies. I’m not certain that the variables I list are working as expected. I am seeing the value for yesterday in my sitemap but that’s because I change the way I was logging this. I set a rule to calculate the day’s usage and at 23:59:00 and post it to a separate item which is logged by MySQL.
I am not seeing any errors in openhab.log file and no events for HVACRuntimeDhr updates. I am, however, getting values for HVACRuntimeD and HVACRuntimeW because these values are showing up in the events.log file and are being updated.
Do I need any includes other than the ones I am using:
Also, I did try the things you suggested but still no change.
You would see errors in openhab.log if you didn’t have the right imports.
What about HVACRuntimeY? Is that being updated too or not?