Simplifying With Timers
Using timers in home automation rules, can really assist in simplifying tasks. Below I will explain how to use timers in OpenHAB rules to either create a type of scheduled task/automation, or to automate the flicking of a switch multiple times.
A good use case of timers in my case is for my garden irrigation, which consists of three zones. Running all zones at once would reduce the water pressure to much for all zones. In order to run each zone individually, I either do a 5 min or a 10 min watering per zone. To do this, the rule would turn zone 1 on, and the timer starts for 5 minutes, then zone 1 is switched off and zone 2 is activated and the timer starts for 5 min again and the same for zone 3. Below is the code sample on how my irrigation is controlled. In the below snippet, the 'sendNotification' part is added for sending a push notification to my phone to alert me the cycle has started and when it has ended. The first line is just declaring the timer object which can be used anywhere in that rule file.
var Timer SprinklerCycleTimer = null
//Water each sprinkler zone for 10min individually
rule "10 Minute Manual Cycle"
when
Item SprinklerCycle received command ON
then
sendNotification("username", "SPRINKLER SYSTEM:\n10 Minute Cycle Started", "water", "low")
Zone1.sendCommand(ON)
SprinklerCycleTimer = createTimer(now.plusMinutes(10)) [|
Zone1.sendCommand(OFF)
Zone2.sendCommand(ON)
SprinklerCycleTimer = createTimer(now.plusMinutes(10)) [|
Zone2.sendCommand(OFF)
Zone3.sendCommand(ON)
SprinklerCycleTimer = createTimer(now.plusMinutes(10)) [|
Zone3.sendCommand(OFF)
sendNotification("username", "SPRINKLER SYSTEM:\n10 Minute Cycle Finished", "water", "low")
SprinklerCycle.sendCommand(OFF)
]
]
]
end
The most recent (at the time of this post) use of timers was added to make the process of adding chemicals to the pool easier. Besides having scheduled announcments on my google speakers reminding me when to add the chemicals, the job itself pretty much has a flow as follows:
- Open the weir, empty the leaf basket and replace basket.
- Walk to the pump and open the box, turn the multiport valve to the 'Backwash' position.
- Walk to my DIY keypad about 5 meters away and enter the pool pump code to turn it on.
- Count to 15 seconds in my head.
- Turn the pump off on the keypad.
- Walk to the pump box and turn the multiport valve to the 'Rinse' position.
- Walk back to the keypad and put the pump on.
- Count to 15 seconds in my head and turn the pump off again.
- Walk back to the pump box and turn the port to 'Filter' position again and clost the pump box cover.
- Walk to the keypad and put the pump on again then walk to the wier
- Add the chemicals in the weir, pump is running so it can suck the chemicals through the filter
- Walk back to keypad and switch off the pump
- Walk back to the weir and replace the Vac lid, and plug in the Kreepy
- Walk back to the keypad and start the pump again.
Wow, sounds bad when you write out all the steps, but not all that bad. How ever, what if I could just enter one pin code in the keypad and automate this whole flow with timers, my only duty would be to make sure I am at the right place at the right time. Well I done just that, and have tested it.... It works for me, but this is just an example of what you could do with timers.
So my timer rules would handle the on and off settings of the pump and all I need to do is enter one pin code and then just stay by the pump, and then move to the weir. This is how my process works now.
- Still clean the leaf basket and then at the pump box flip it to ''Backwash"
- Enter the new pin code in at the keypad and then wait by the pool pump.
- From here the pump will run 15 seconds, then switch off for 5 seconds, since I am not leaving the pump box any more, in those 5 seconds I flip the valve to 'Rinse'.
- The pump auto starts again and runs for 15 seconds again, and again is switched off for 5 seconds so I can return to the 'Filter position' and close the pump box cover.
- The pump will turn on again for 30 sec, allowing me to walk to the weir and add the chemicals, and run long enough to suck them in. Then the pump auto stops for 10 seconds while I replace the Vac lid and Kreepy, and then the pump auto starts again.
So my own movements of walking back and fourth have been drastically reduced. to just being by the pump and the weir.
That is the whole purpose of automations.... to make tasks easier or in some cases take over those tasks for you if possible. Below is the code I use to run all these timers.
var Timer BackwashPoolCycleTimer = null
case "myPin code here" : {
SwimmingPoolPump.sendCommand(ON)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(15)) [| //Backwash for 15 sec
SwimmingPoolPump.sendCommand(OFF)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(5)) [| //Off for 5 sec
SwimmingPoolPump.sendCommand(ON)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(15)) [| //Rinse for 15 sec
SwimmingPoolPump.sendCommand(OFF)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(5)) [| //Off for 7 sec
SwimmingPoolPump.sendCommand(ON)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(30)) [| //Filter for 30 sec
SwimmingPoolPump.sendCommand(OFF)
BackwashPoolCycleTimer = createTimer(now.plusSeconds(10)) [| //Off for 10 sec
SwimmingPoolPump.sendCommand(ON)
]
]
]
]
]
]
}