Hi all, I have the following rule for my irrigation system:
rule "Irrigation run"
when
Time cron "0 0 0 * * ?" or
Item IrrigationTimeHour changed or
Item IrrigationTimeMinutes changed
then
lock1.lock()
try {
var String msg = ""
logInfo("rules","Watering start hour has been changed.")
// Copy the Alarm-Time from the UI to local variables
var hour = IrrigationTimeHour.state as DecimalType
var minute = IrrigationTimeMinutes.state as DecimalType
// Combine the hour and minutes to one string to be displayed in the
// user interface
if ((hour as Number) < 10) { msg = "0" }
msg = msg + IrrigationTimeHour.state.format("%d") + ":"
if ((minute as Number) < 10) { msg = msg + "0" }
msg = msg + IrrigationTimeMinutes.state.format("%d")
postUpdate(Irrigation_StartTime, msg)
logInfo("rules","New watering time: "+msg)
// get the scale factor - used to reduce the run times across the board
var Number scaleFactor = Irrigation_ScaleFactor.state as DecimalType
// convert our start time to a joda.time.DateTime for today
var DateTime startTime = parse(now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T" + Irrigation_StartTime.state + ":00")
var DateTime endTime
// get the raw run times for each zone (in mins)
var Number Z1Mins = Irrigation_Z1Mins.state as DecimalType
var Number Z2Mins = Irrigation_Z2Mins.state as DecimalType
var Number Z3Mins = Irrigation_Z3Mins.state as DecimalType
var Number Z4Mins = Irrigation_Z4Mins.state as DecimalType
var Number Z5Mins = Irrigation_Z5Mins.state as DecimalType
var Number Z6Mins = Irrigation_Z6Mins.state as DecimalType
// convert to the actual run times (by applying the scale factor)
var int Z1Time = ((Z1Mins * scaleFactor) / 100).intValue
var int Z2Time = ((Z2Mins * scaleFactor) / 100).intValue
var int Z3Time = ((Z3Mins * scaleFactor) / 100).intValue
var int Z4Time = ((Z4Mins * scaleFactor) / 100).intValue
var int Z5Time = ((Z5Mins * scaleFactor) / 100).intValue
var int Z6Time = ((Z6Mins * scaleFactor) / 100).intValue
logInfo("rules","New watering time scheduled")
// turn on each zone in turn (with a minute gap between each zone activation)
if (Z1Time > 0) {
if(Timer1start!=null)
{
Timer1start.cancel()
Timer1start = null
}
if(Timer1end!=null)
{
Timer1end.cancel()
Timer1end = null
}
endTime = startTime.plusMinutes(Z1Time)
Timer1start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z1, ON)
//callScript("startWatering")
}
]
Timer1end = createTimer(endTime) [| sendCommand(Irrigazione_Z1, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (Z2Time > 0) {
if(Timer2start!=null)
{
Timer2start.cancel()
Timer2start = null
}
if(Timer2end!=null)
{
Timer2end.cancel()
Timer2end = null
}
endTime = startTime.plusMinutes(Z2Time)
Timer2start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z2, ON)
}
]
Timer2end = createTimer(endTime) [| sendCommand(Irrigazione_Z2, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (Z3Time > 0) {
if(Timer3start!=null)
{
Timer3start.cancel()
Timer3start = null
}
if(Timer3end!=null)
{
Timer3end.cancel()
Timer3end = null
}
endTime = startTime.plusMinutes(Z3Time)
Timer3start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z3, ON)
}
]
Timer3end = createTimer(endTime) [| sendCommand(Irrigazione_Z3, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (Z4Time > 0) {
if(Timer4start!=null)
{
Timer4start.cancel()
Timer4start = null
}
if(Timer4end!=null)
{
Timer4end.cancel()
Timer4end = null
}
endTime = startTime.plusMinutes(Z4Time)
Timer4start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z4, ON)
}
]
Timer4end = createTimer(endTime) [| sendCommand(Irrigazione_Z4, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (Z5Time > 0) {
if(Timer5start!=null)
{
Timer5start.cancel()
Timer5start = null
}
if(Timer5end!=null)
{
Timer5end.cancel()
Timer5end = null
}
endTime = startTime.plusMinutes(Z5Time)
Timer5start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z5, ON)
}
]
Timer5end = createTimer(endTime) [|
sendCommand(Irrigazione_Z5, OFF)
]
startTime = endTime.plusMinutes(1)
}
if (Z6Time > 0) {
if(Timer6start!=null)
{
Timer6start.cancel()
Timer6start = null
}
if(Timer6end!=null)
{
Timer6end.cancel()
Timer6end = null
}
endTime = startTime.plusMinutes(Z6Time)
Timer6start = createTimer(startTime) [|
day = now.getDayOfWeek()
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON)))) {
sendCommand(Irrigazione_Z6, ON)
}
]
Timer6end = createTimer(endTime) [|
sendCommand(Irrigazione_Z6, OFF)
//callScript("endWatering")
]
startTime = endTime.plusMinutes(1)
}
}finally{
lock1.unlock()
}
end
I found that the timers I have fire either when they’re created and when they expire. I just want that they fire when they expire. Can you help me? Thanks in advance and merry Christmas to all!!!