Total daily runtime - displaying total runtime for yesterday/weekly/monthly


I currently monitoring a device total usage during a day at home via simple rule.

Out of this rule I receive time in minutes since device been turned on and total usage during day which gets reset at midnight.

Number MyDevice3_Time_Active  "Heater ON Time [%d]"         <time>            (Restore)
Number MyDevice3_Time_Day     "Heater Daily ON Time [%d]"   <line-increase>   (Restore)

I would like to expand this further and display details of total usage of yesterday, weekly, monthly and perhaps yearly if this would be possible.

Has anyone tried that before? What would be the best way to achieve it.

1 Like

Can you post the rule?

Yes, sure copy of the rule below.

rule "Heater Runtime counter"
  // Every minute, 5 seconds after the minute
  Time cron "5 * * ? * * *"
  if (MyDevice3.state == ON) {
    MyDevice3_Time_Active.postUpdate((MyDevice3_Time_Active.state as Number) + 1)
  if (MyDevice3_Time_Day.state != NULL) {
    MyDevice3_Time_Day.postUpdate((MyDevice3_Time_Day.state as Number) + 1)
  } else {

rule "Reset Daily Counter"
    Time cron "0 0 0 * * ?"  // Fires midnight every day

I have a solution posted on: openHABster 🐹

But you need to set-up persistence

Thanks Vincent. I will look into this.

Hy, i try to use your rule to keep track of a heater runtime…but only the Heater ON Time gets updated then reverts back to 0 as it should, but Heater Daily ON Time never gets any update.
Other then the 2 items and the 2 rules is there anything else ??? or am i mising something?