Hi all,
I am having issues with my rule and need help.
for some reason I can’t get the code below to work. I am building an irrigation system and want to define startTime but can’t get it working.
Can you help?
rule "Irrigation run"
when
Time cron "0 0 0 * * ?"
then
if (Irrigation_Master.state == ON) {
// 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" + "13:00" + ":00")
var DateTime endTime
// get the raw run times for each zone (in mins)
var Number lawnMins = Irrigation_LawnMins.state as DecimalType
var Number vegeMins = Irrigation_VegeMins.state as DecimalType
var Number backMins = Irrigation_BackMins.state as DecimalType
var Number frontMins = Irrigation_FrontMins.state as DecimalType
// convert to the actual run times (by applying the scale factor)
var int lawnTime = ((lawnMins * scaleFactor) / 100).intValue
var int vegeTime = ((vegeMins * scaleFactor) / 100).intValue
var int backTime = ((backMins * scaleFactor) / 100).intValue
var int frontTime = ((frontMins * scaleFactor) / 100).intValue
// turn on each zone in turn (with a minute gap between each zone activation)
if (lawnTime > 0) {
endTime = startTime.plusMinutes(lawnTime)
createTimer(startTime) [| sendCommand(Irrigation_Lawn, ON) ]
createTimer(endTime) [| sendCommand(Irrigation_Lawn, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (vegeTime > 0) {
endTime = startTime.plusMinutes(vegeTime)
createTimer(startTime) [| sendCommand(Irrigation_Vege, ON) ]
createTimer(endTime) [| sendCommand(Irrigation_Vege, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (backTime > 0) {
endTime = startTime.plusMinutes(backTime)
createTimer(startTime) [| sendCommand(Irrigation_Back, ON) ]
createTimer(endTime) [| sendCommand(Irrigation_Back, OFF) ]
startTime = endTime.plusMinutes(1)
}
if (frontTime > 0) {
endTime = startTime.plusMinutes(frontTime)
createTimer(startTime) [| sendCommand(Irrigation_Front, ON) ]
createTimer(endTime) [| sendCommand(Irrigation_Front, OFF) ]
startTime = endTime.plusMinutes(1)
}
}
end