var Timer irrigationTimer = null rule "When system started" when System started then sendBroadcastNotification("System restarted, Irrigiation system reset") gIrrigation.sendCommand(OFF) end rule "Solar Offline" when Item Irrigation_Online changed to OFF then sendBroadcastNotification("Garden Solar Grid Offline") end rule "Solar Online" when Item Irrigation_Online changed to ON then sendBroadcastNotification("Garden Solar Grid Online") end rule "Irrigation Part 1" when Item Irrigation_Start received command ON then if(Irrigation_Zone_1_Auto.state == ON) { Irrigation_Zone_1.sendCommand(ON) Irrigation_Pump1.sendCommand(ON) Irrigation_Curr.postUpdate(1) val Integer TIME1 = (Irrigation_Zone_1_Time.state as DecimalType).intValue irrigationTimer = createTimer(now.plusMinutes(TIME1), [| Irrigation_Pump1.sendCommand(OFF) Irrigation_Zone_1.sendCommand(OFF) Irrigation_Curr.postUpdate(0) Irrigation_Start_2.sendCommand(ON) ]) } else { Irrigation_Start_2.sendCommand(ON) } end rule "Irrigation Part 2" when Item Irrigation_Start_2 received command ON then if(Irrigation_Zone_2_Auto.state == ON) { Irrigation_Pump1.sendCommand(ON) Irrigation_Zone_2.sendCommand(ON) Irrigation_Curr.postUpdate(2) val Integer TIME2 = (Irrigation_Zone_2_Time.state as DecimalType).intValue irrigationTimer = createTimer(now.plusMinutes(TIME2), [| Irrigation_Pump1.sendCommand(OFF) Irrigation_Zone_2.sendCommand(OFF) Irrigation_Curr.postUpdate(0) Irrigation_Start_3.sendCommand(ON) ]) } else { Irrigation_Start_3.sendCommand(ON) } end rule "Irrigation Part 3" when Item Irrigation_Start_3 received command ON then if(Irrigation_Zone_3_Auto.state == ON) { Irrigation_Pump1.sendCommand(ON) Irrigation_Zone_3.sendCommand(ON) Irrigation_Curr.postUpdate(3) val Integer TIME3 = (Irrigation_Zone_2_Time.state as DecimalType).intValue irrigationTimer = createTimer(now.plusMinutes(TIME3), [| Irrigation_Pump1.sendCommand(OFF) Irrigation_Zone_3.sendCommand(OFF) Irrigation_Curr.postUpdate(0) Irrigation_Start.sendCommand(OFF) ]) } else { Irrigation_Start.sendCommand(OFF) } end rule "Cancel Irrigation" when Item Irrigation_Start received command OFF then gIrrigation.sendCommand(OFF) Irrigation_Curr.postUpdate(0) irrigationTimer?.cancel irrigationTimer = null end rule "Water usage" when Item gIrrigation_Times changed then Water_Use.postUpdate(((gIrrigation_Times.state as Number) * 3.7).intValue) end rule "Daily watering at dusk" when Channel "astro:sun:home:civilDusk#event" triggered START then if ( Irrigation_Auto.state == ON && (RecentRainVolume.state as Number) <= 10 ) { Irrigation_Start.sendCommand(ON) sendBroadcastNotification("Auto Irrigation has commenced") } else logInfo("default.rules", "Irrigation did not start at dusk, either Auto is OFF or Daily rain was more than 10mm") end