Rule for how long something runs

@rlkoshak

I have a rule to run my pool pump for 8 hrs at night. Sometimes, on the weekends, I run the pump when we are in it, which could be an hour or more. I need to write a rule that subtracts the manual runtime from the rule runtime. Can someone please help guide me?

i would assume that i would use proxy items, one that gets get to say 0 when the rule ends, then if the pump item gets updated to ON between the hours that the pump doesnt run, it keeps track of how long the pump runs and sets the proxy item value to this number. but,i could be wrong

Heyho,
you can go at this many ways. As I believe 8 hours is not a strict requirement but rather a round-about-value how about this solution:

  • Hold on to your current rules (ON at midnight, OFF at 8:00 am) as a fallback (e.g. if your openHAB system gets reset and loses its knowledge from the following points)

  • Define an Item to count the hours the pump was running per day e.g. Pool_Daily_Hours

  • Define a rule to reset the Item to 8 hours once per day, e.g. at 9 am

  • Define a rule that is executed hourly with the following logic:

if (Pool_Daily_Hours.state > 0) Pool_Daily_Hours.postUpdate(Pool_Daily_Hours.state - 1)
else Pool_Pump_Power.sendCommand(OFF)

Of course you’ll need to tweak the details but that should be it. For the example I chose a time resolution of full hours. Of course you can increase the resolution to 30min, 10min or as far as you want to push it.

Happy Hacking!

thx thom. so in my initial rule, shouldnt i use pool dsy hours for the time to run, then on sytem startup set pool dsy hours to 8? sorry for the typos,on mobile…

or can i keep those rules like you said, but only trigger them if pool daily hours is less than 8? and i could persist it too

The original rule I mentioned as first bullet point is not really linked to the rest but would have two tasks

  1. automatically start the pump at 0:00
  2. stop the pump at 8:00 (this will be covered by the later rules and would serve as a fallback in case e. g. openHAB was restarted during night)

@Branden_Smale did you find a solution?

honestly, im doing 12 hrs days and weekends in my job, so havent had time to mess with it…thanks for checking though.

1 Like