// https://community.openhab.org/t/design-pattern-expire-binding-based-timers/32634 // https://community.openhab.org/t/design-pattern-expire-binding-based-countdown-timer/49225 var Debug_Mode = false var Timer timer_Watering_Vorne = null var Timer timer_Watering_Seite = null var Timer timer_Watering_Hinten = null var Timer timer_Watering_Droeppler = null var Timer timer_Watering_Ende = null var duration_Watering_Vorne = 0 var duration_Watering_Seite = 0 var duration_Watering_Hinten = 0 var duration_Watering_Droeppler = 0 val duration_Watering_Pause = -1 val start_delay = 0 var now_plus_duration = 0 var TriplePlay = false rule "System started gardena.rules" when System started then logInfo("started", "Started model 'irrigation.rules'") Ventilverteiler_Valves_Duration.members.forEach [ item | sendCommand(item,0) ] Ventilverteiler_Valves_commands_Duration.members.forEach [ item | sendCommand(item,0) ] end rule "Switch 1 ON" when // Item Ventilverteiler_Valve_1_Duration changed from "0.0 min" to "33.0 min" Item Ventilverteiler_Valves_Switch_1 changed to ON then logInfo("Switch 1", "Started TriplePlay ON") Thread::sleep(5000) Ventilverteiler_Valve_1_commands_Duration.sendCommand(22) Ventilverteiler_Valve_1_commands_start_seconds_to_override.sendCommand(ON) logInfo("Switch 1", "Started TriplePlay 2") TripePlay = true end rule "Switch 1 OFF" when // Item Ventilverteiler_Valve_1_Duration changed from "0.0 min" to "33.0 min" Item Ventilverteiler_Valves_Switch_1 changed to OFF then logInfo("Switch 1", "Stopped TriplePlay 1") Thread::sleep(5000) Ventilverteiler_Valve_1_commands_stop_until_next_task.sendCommand(ON) logInfo("Switch 1", "Stopped TriplePlay 2") TripePlay = false end rule "TriplePlay ON" when Item Ventilverteiler_Valve_1_Duration changed from "0.0 min" to "33.0 min" or Item Ventilverteiler_Valves_Switch_2 changed to ON then logInfo("TriplePlay", "Started TriplePlay Rule - Debug Mode: " + Debug_Mode.toString) if (Debug_Mode == true) { duration_Watering_Vorne = 2 duration_Watering_Seite = 2 duration_Watering_Hinten = 2 duration_Watering_Droeppler = 2 } else { duration_Watering_Vorne = 30 duration_Watering_Seite = 30 duration_Watering_Hinten = 45 duration_Watering_Droeppler = 20 } Ventilverteiler_Valves_commands_stop_until_next_task.members.forEach [ item | sendCommand(item,ON) ] if (timer_Watering_Vorne !== null && timer_Watering_Vorne.isRunning == true) { timer_Watering_Vorne.cancel timer_Watering_Vorne = null } if (timer_Watering_Seite !== null && timer_Watering_Seite.isRunning == true) { timer_Watering_Seite.cancel timer_Watering_Seite = null } if (timer_Watering_Hinten !== null && timer_Watering_Hinten.isRunning == true) { timer_Watering_Hinten.cancel timer_Watering_Hinten = null } if (timer_Watering_Droeppler !== null && timer_Watering_Droeppler.isRunning == true) { timer_Watering_Droeppler.cancel timer_Watering_Droeppler = null } if (timer_Watering_Ende !== null && timer_Watering_Ende.isRunning == true) { timer_Watering_Ende.cancel timer_Watering_Ende = null } // Schritt 1 - Bewässerung Vorne starten now_plus_duration = start_delay logInfo("irrigation", "timer_Watering_Vorne is starting at " + now.plusMinutes(now_plus_duration).toString + " for " + duration_Watering_Vorne.toString + " min.") timer_Watering_Vorne = createTimer(now.plusMinutes(now_plus_duration), [ | logInfo("irrigation", "timer_Watering_Vorne activated at " + now.toString + " for " + duration_Watering_Vorne.toString + " mins. until " + now.plusMinutes(duration_Watering_Vorne).toString) Pumpe_Valve_commands_Duration.sendCommand(duration_Watering_Vorne + 5) Pumpe_Valve_commands_start_seconds_to_override.sendCommand(ON) Ventilverteiler_Valve_3_commands_Duration.sendCommand(duration_Watering_Vorne) Ventilverteiler_Valve_3_commands_start_seconds_to_override.sendCommand(ON) ]) // Schritt 2 - Bewässerung Seite starten now_plus_duration = start_delay + duration_Watering_Vorne + duration_Watering_Pause logInfo("irrigation", "timer_Watering_Seite is starting at " + now.plusMinutes(now_plus_duration).toString + " for " + duration_Watering_Seite.toString + " min.") timer_Watering_Seite = createTimer(now.plusMinutes(now_plus_duration), [ | logInfo("irrigation", "timer_Watering_Seite activated at " + now.toString + " for " + duration_Watering_Seite.toString + " mins. until " + now.plusMinutes(duration_Watering_Seite).toString) Pumpe_Valve_commands_Duration.sendCommand(duration_Watering_Seite + 5) Pumpe_Valve_commands_start_seconds_to_override.sendCommand(ON) Ventilverteiler_Valve_4_commands_Duration.sendCommand(duration_Watering_Seite) Ventilverteiler_Valve_4_commands_start_seconds_to_override.sendCommand(ON) ]) // Schritt 3 - Bewässerung Hinten starten now_plus_duration = start_delay + duration_Watering_Vorne + duration_Watering_Pause + duration_Watering_Seite + duration_Watering_Pause logInfo("irrigation", "timer_Watering_Hinten is starting at " + now.plusMinutes(now_plus_duration).toString + " for " + duration_Watering_Hinten.toString + " min.") timer_Watering_Hinten = createTimer(now.plusMinutes(now_plus_duration), [ | logInfo("irrigation", "timer_Watering_Hinten activated at " + now.toString + " for " + duration_Watering_Hinten.toString + " mins. until " + now.plusMinutes(duration_Watering_Hinten).toString) Pumpe_Valve_commands_Duration.sendCommand(duration_Watering_Hinten + 5) Pumpe_Valve_commands_start_seconds_to_override.sendCommand(ON) Ventilverteiler_Valve_2_commands_Duration.sendCommand(duration_Watering_Hinten) Ventilverteiler_Valve_2_commands_start_seconds_to_override.sendCommand(ON) ]) // Schritt 4 - Bewässerung Dröppler starten now_plus_duration = start_delay + duration_Watering_Vorne + duration_Watering_Pause + duration_Watering_Seite + duration_Watering_Pause + duration_Watering_Droeppler logInfo("irrigation", "timer_Watering_Droeppler is starting at " + now.plusMinutes(now_plus_duration).toString + " for " + duration_Watering_Droeppler.toString + " min.") timer_Watering_Hinten = createTimer(now.plusMinutes(now_plus_duration), [ | logInfo("irrigation", "timer_Watering_Droeppler activated at " + now.toString + " for " + duration_Watering_Droeppler.toString + " mins. until " + now.plusMinutes(duration_Watering_Droeppler).toString) Pumpe_Valve_commands_Duration.sendCommand(duration_Watering_Droeppler + 5) Pumpe_Valve_commands_start_seconds_to_override.sendCommand(ON) Ventilverteiler_Valve_6_commands_Duration.sendCommand(duration_Watering_Droeppler) Ventilverteiler_Valve_6_commands_start_seconds_to_override.sendCommand(ON) ]) // Schritt 5 - Alles beenden now_plus_duration = start_delay + duration_Watering_Vorne + duration_Watering_Pause + duration_Watering_Seite + duration_Watering_Pause + duration_Watering_Hinten + duration_Watering_Pause + duration_Watering_Droeppler logInfo("irrigation", "TriplePlay ends at " + now.plusMinutes(now_plus_duration).toString) timer_Watering_Ende = createTimer(now.plusMinutes(now_plus_duration), [ | logInfo("irrigation", "TriplePlay ended at " + now.toString) TriplePlay = false Ventilverteiler_Valves_Switch_2.sendCommand(OFF) ]) logInfo("TriplePlay", "Ended TriplePlay Rule") TriplePlay = true end rule "TriplePlay OFF" when Item Ventilverteiler_Valve_1_Duration changed from "0.0 min" to "44.0 min" or Item Ventilverteiler_Valves_Switch_2 changed to OFF then logInfo("TriplePlay Stop", "Started TriplePlay") if (timer_Watering_Vorne !== null) { timer_Watering_Vorne.cancel timer_Watering_Vorne = null } if (timer_Watering_Seite !== null) { timer_Watering_Seite.cancel timer_Watering_Seite = null } if (timer_Watering_Hinten !== null) { timer_Watering_Hinten.cancel timer_Watering_Hinten = null } if (timer_Watering_Droeppler !== null) { timer_Watering_Droeppler.cancel timer_Watering_Droeppler = null } if (timer_Watering_Ende !== null) { timer_Watering_Ende.cancel timer_Watering_Ende = null } // Schritt 1 - Alle Ventile schliessen Ventilverteiler_Valves_commands_stop_until_next_task.members.forEach [ item | sendCommand(item,ON) ] // Schritt 2 - Pumpe stoppen Pumpe_Valve_commands_stop_until_next_task.sendCommand(ON) logInfo("TriplePlay Stop", "Stopped TriplePlay") TriplePlay = false end