I have been trying to create a pool pump timer, which basically uses the rule system in openhab, to turn the “FF_Pool_Pump” item to ON, everyday, at 10am, then turning it off at 2pm. That’s it, I thought I woulda have been a rather easy task. But I just can’t get it to function! One of the main problems I’m having is that, I can’t figure out how to get the current time and then based on that time, have openhab turn on or off, the Pool pump, I’m not sure if this is an easy thing to do, but I would really value some assistance. Thank You.
Here is a working rule that runs the main and the booster pump.
rule “Pool startup”
when
System started or
Time cron “0 0 0 * * ?”
then
postUpdate(Pool_Operation, ON)
postUpdate(PoolOp_StartTime, “8:00”)
postUpdate(PoolOp_CycleMins, “120”)
end
rule “Pool run”
when
Time cron "0 0 0 * * ?"
then
if (Pool_Operation.state==ON) {
var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + PoolOp_StartTime.state + ":00")
var DateTime endTime
var Number poolRunTime = PoolOp_CycleMins.state as DecimalType
var int pool_Run_Time = poolRunTime.intValue
if (poolRunTime > 0 ) {
endTime = startTime.plusMinutes(pool_Run_Time)
createTimer(startTime)[|sendCommand(Pool_Main_Pump, ON);
val message = "Starting Pool Water re-cycling Main Pump ...";
sendMail(mailTo, mailSubject, message);
Thread::sleep(60000);
sendCommand(Pool_Cleaner, ON);
val message2 = "Starting Pool Cleaner Booster Pump ...";
sendMail(mailTo, mailSubject, message2)
]
createTimer(endTime) [| sendCommand(Pool_Cleaner, OFF);
sendCommand(Pool_Main_Pump, OFF);
val message = "Pool Water re-cycling/cleaning operation has ended ...";
sendMail(mailTo, mailSubject, message)
]
}
}
end
When does this run, at what time, does it run everyday?
Is it possible to check the system time and then use that to start the pump?
It runs everyday at 8:00 AM for 120 minutes.
Could you show me how to make openhab turn on something at a certain time?
As you can see, I have two rules, one " Pool Startup" sets the schedule ( 8:00 AM) and the cycle time of 120 minutes. The second rule - “run Pool” executes that schedule. For your pool operation just change the start time and cycle time to whatever you’d like.
Thank You
@Adam_Nemati’s solution is nice in that it lets you set the start time and run time in an Item which can be very convenient. It is certainly a very thorough solution and I suggest you use it.
However, there is indeed a simpler way to do this using a Time cron triggers. The cron trigger uses the same syntax as the “cron” daemon on Linux/Unix based machines and it is used to trigger a rule at a given time. It is very flexible to the point where you can trigger a rule to run every third Thursday of the month only on leap years, but most people do a simple every day at this time or every so many seconds, minutes, or hours.
The first item in the cron is seconds, the second is minutes, the third is hour, … So a trigger of “0 0 14 * * ?” will trigger the rule to run every day at 14:00 hours (i.e. 2 pm). The trigger of “0 0 0 * * ?” causes the rule to run every day at midnight.
For completeness this simpler solution using cron triggers is as follows:
rule "Start pump at 10 am"
when
Time cron "0 0 10 * * ?"
then
FF_Pool_Pump.sendCommand(ON)
end
rule "Stop pump at 2 pm"
when
Time cron "0 0 14 * * ?"
then
FF_Pool_Pump.sendCommand(OFF)
end
That, was really informative and useful!
Have you ever used the GCAL binding? To schedule the Pump based on a google calendar?
I don’t use the GCAL binding. I control my lights based on sunrise and sunset and the weather. See this posting for how I do it.