Complete watering system based on openHAB

Yes, everything is working on OH3. I didn’t have time to setup persistence yet so I do not know if it is working.
You can find my rules in the post above, I have 4 sprinkler zones, 1 drip hose, mi Flora humidity sensor and rain sensor. I can manually select the water source (drinking water or rain tank), this could be also automatic but I wanted to prevent the rain water polluting my drinking water so to switch the source I need to manually connect the right pipe/hose. My sprinkler valves are connected to rPi zero installed outside and talking to OH via MQTT. I don’t have any sitemaps or widgets (yet), I modify the things via the OH3 UI. What I still need to do i to create some fallback to the rPi that is connected to the sprinklers to close the valves and stop the pump if the communication to the OH is lost.

So the items files is (maybe some things are obsolete):

//Sprinkler system
    Switch                  itmIrrigationSprinklersTerraceCmd               "Sprinklers Terrace"                                        <rain>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationSprinklersTerraceCmd", expire="30m, command=OFF"}
    Switch                  itmIrrigationSprinklersGardenHouseCmd           "Sprinklers Garden House"                                   <rain>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationSprinklersGardenHouseCmd", expire="30m, command=OFF"}
    Switch                  itmIrrigationSprinklersEntranceCmd              "Sprinklers Entrance"                                       <rain>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationSprinklersEntranceCmd", expire="30m, command=OFF"}
    Switch                  itmIrrigationSprinklersFrontCmd                 "Sprinklers  Front"                                         <rain>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationSprinklersFrontCmd", expire="30m, command=OFF"}
    Switch                  itmIrrigationDripHoseCmd                        "Drip Hose"                                                 <rain>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationDripHoseCmd", expire="1h,command=OFF"}
    Switch                  itmIrrigationPumpCmd                            "Pump"                                                      <pump>          (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationPumpCmd",  expire="2h, command=OFF"}
    Switch                  itmIrrigationRainwaterFilterFlushCmd            "Filter Flush"                                              <softener>      (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationRainwaterFilterFlushCmd",  expire="5m, command=OFF"}
    Switch                  itmIrrigationPiRelay8Cmd                        "Relay 8"                                                   <switch>        (grpIrrigation)     ["Switch"]  {channel="mqtt:topic:sensor_reporter:chIrrigationPiRelay8Cmd"}
    Number                  itmIrrigationPiSensorReporterStatus             "Sensor Reporter Status"                                    <status>        (grpIrrigation)                 {channel="mqtt:topic:sensor_reporter:chIrrigationPiHealth"}


    String EventHist  // event history, used with Influxdb persistence 

    // Rain sensor - OPEN=wet, CLOSED=dry
    Switch                  itmIrrigationRainSensor                         "Rain sensor"                                               <rain>          (grpIrrigation)                 ["OpenState"]  
    Switch                  itmIrrigationStartBtn                           "Manual watering start"                                     <switch>        (grpIrrigation, grpSettings)    ["Switch"]   
    Switch                  itmIrrigationAuto                               "Watering automation"                                       <switch>        (grpIrrigation, grpSettings)    ["Switch"]
    Switch                  itmIrrigationFromRainTank                       "Water source is rain tank"                                 <switch>        (grpIrrigation, grpSettings)    ["Switch"]

    // Watering parameter
    String	                itmIrrigationStartTime     		                "Watering hour"	                 				            <calendar>  (grpIrrigation, grpSettings) 
    Number	                itmIrrigationDurationSprinklersTerrace 	    	"Watering duration - sprinklers terrace[%d min]"            <pressure>  (grpIrrigation, grpSettings) 
    Number          	    itmIrrigationDurationSprinklersGardenHouse 		"Watering duration - sprinklers garden house[%d min]"       <pressure>  (grpIrrigation, grpSettings) 
    Number	                itmIrrigationDurationSprinklersEntrance 		"Watering duration - sprinklers entrance[%d min]"           <pressure>  (grpIrrigation, grpSettings) 
    Number	                itmIrrigationDurationSprinklersFront		    "Watering duration - sprinklers front[%d min]"              <pressure>  (grpIrrigation, grpSettings) 
    Number          	    itmIrrigationDurationDripHose  		            "Watering duration - drip hose[%d min]"                     <pressure>  (grpIrrigation, grpSettings) 
    Number	                itmIrrigationDurationFilterFlush 		        "Filter flush duration [%d min]"                            <pressure>  (grpIrrigation, grpSettings) 

    Number	                itmIrrigationScaleFactor			            "Correction coefficient [%d %%]"  		                    <pressure>	                (grpIrrigation, grpSettings) 
    Number                  itmIrrigationMinimumReqRainfallCfg              "Minimum reqired rainfall [%d mm]"                          <pressure>	                (grpIrrigation, grpSettings) 
    String                  itmIrrigationLastDate                           "Last watering date [%s]"   			                    <humidity>                  (grpIrrigation) 
    String                  itmIrrigationNotification_Proxy                                                                                                         (grpIrrigation)     // START - start watering , STOP - stop watering 
    Number	                itmMinimumSoilMoisture			                "Minimum Soil moisture [%d %%]"  		                    <rain>	                (grpIrrigation, grpSettings) 

    //Health  "Sensor reporter Health"             
    Switch                  itmSprinklersPiSensorReporterHealth    "Sprinklers Pi Sensor reporter Health"   <status>        (grpIrrigation, grpHealth)  {expire="5m,command=OFF"}


//Mi Flora sensors
    Number:Illuminance      Miflora_Azalea_Light                            "Light Intensity [%d lx]"                                   <light>        (grpMiFloraAzalea)                   ["Measurement", "Light"]        { channel="mqtt:topic:AzaleaOutside:chLight" }
    Number:Dimensionless    Miflora_Azalea_Battery                          "Battery Charge [%d %%]"                                    <battery>      (grpMiFloraAzalea)                                                   { channel="mqtt:topic:AzaleaOutside:chBattery" }
    Number:Temperature      Miflora_Azalea_Temperature                      "Temperature [%.1f °C]"                                     <temperature>  (grpMiFloraAzalea, grpTemperature)   ["Measurement", "Temperature"]  { channel="mqtt:topic:AzaleaOutside:chTemperature" }
    Number                  Miflora_Azalea_Conductivity                     "Soil Fertility [%d µS/cm]"                                 <lawnmower>    (grpMiFloraAzalea)                   ["Measurement", "Point"]        { channel="mqtt:topic:AzaleaOutside:chConductivity" }
    Number:Dimensionless    Miflora_Azalea_Moisture                         "Soil Moisture [%d %%]"                                     <humidity>     (grpMiFloraAzalea)                   ["Measurement", "Humidity"]     { channel="mqtt:topic:AzaleaOutside:chMoisture" }

    //Mi Flora service health
    Switch  itmSprinklersPiMiFloraServiceHealth                             "Sprinklers Pi Mi Flora health"                             <status>        (grpMiFloraAzalea, grpHealth)  {expire="12h,command=OFF"}


Thanks for sharing, Darko. Will try to get your code working with my MegaD.

i still get
failed: Text ‘2021-7-25T14:00:00.000+01:00’ could not be parsed at index 5 in irriggation

val userStartTime = parse(now.getYear() + "-" + now.getMonthValue().toString() + "-" + now.getDayOfMonth() + "T" + WtrStartTime.state + ":00.000+01:00").withZoneSameInstant(ZoneId.systemDefault())

This is working like a charm

 // Check if actual hour is equal to watering hour and if watering mode is set to automatic
    var NowMonth = String::format("%02d", now.getMonthValue())
    var NowDay = String::format("%02d", now.getDayOfMonth())
    val userStartTime = parse(now.getYear() + "-" + NowMonth + "-" + NowDay + "T" + WtrStartTime.state + ":00.000+01:00").withZoneSameInstant(ZoneId.systemDefault())



    // check hour of watering, watering mode and isWatering

    if ( ( ( userStartTime.hour == now.getHour()  &&  userStartTime.minute == now.getMinute() ) || checkUserStartTime == false )
        && WtrAuto.state == ON && (isWatering == false)

    ) {
        logInfo( "FILE", " ======= Wheather algorithm  ======= ")

So it’s working?

yes and no still one datetime conversion issue:
Script execution of rule with UID ‘irriggation-5’ failed: ‘plusMinutes’ is not a member of ‘DateTime’; line 293, column 13, length 31 in irriggation

caused by:

var DateTime startTime = now
                        endTime = startTime.plusMinutes(wtr1Time)

Hm, maybe it has to do with the Java Time library. I’m using now

import java.util.Date

I had to chenge several things for example:

var NowMonth = String::format("%02d", now.getMonthValue())
	var NowDay = String::format("%02d", now.getDayOfMonth())

	val userStartTime = parse(now.getYear() + "-" + NowMonth + "-" + NowDay + "T" + WtrStartTime.state + ":00.000+02:00[Europe/Brussels]").withZoneSameInstant(ZoneId.systemDefault())
	

Maybe this points you into the right direction.

I had similar issue with plusMinutes and I switched to “plusSeconds”. That worked!

adding var startTime = now() istead of DateTime solved the issue.

 var startTime = now()
                endTime = startTime.plusMinutes(wtr1Time)

Hi, I’am trying to have this nice program running on my OH3 but without luck.
First I got the rules on top, then I modified my items (7 valves + rain sensor) to adapt them to the rule, and last I changed the rule with the last one (the one in original language not translated to english).
After some hour of debug I gave up beacuse I’m too dummy to afford such a work. The error is always the same:
The field Tmp_irrigazioneRules.lastWtrDate refers to the missing type Object
May you address me inthe right direction?
TY!

Hi there
Just read about the hardware - Hunter Valves, MCP23017 etc. But does anyone wants to share their own hardware solutions for irrigation?
I currently need just one zone, probably two, and i’m looking for a simplest way to control the water flow instead of my old Gardena watering computer - like all-in-one solution.

Currently the best idea in my mind is: Hunter water valve + Z-wave relay + 24V Power supply + waterproof box. Looks a bit bulky, so I would like to have something smaller and ideally with less components. For example are there any 230V irrigation valves at the market (pls don’t ask to use one from dishwasher)?

If you don’t find suitable 230VAC valve, that is the easiest way to go. I have 5 zones, so I use rPi zero and 8 channel relay module and Rainbird valves that work on 24VAC (or it was 12VAC I am not sure anymore) which is provided from 230/24V transformer, all in IP66 box. To have extra safety in case some of the zone valves fails open, I have put 1 more extra valve to the main supply to the zone valve distribution box. This extra valve located close to the utility water meter and is controlled by Sonoff mini, and other 24VAC transformer. I have cheap flowmeter installed on the watering line which could be used as a leak alarm, but I didn’t have time to configure it yet.

Check ab-log for their MegaD, that thing costs like any hunter controller, has 14 16A replaceable relays and 20+ dry contact or digital/analog inputs, has binding for Openhab. Valves could be powered by ethernet cat5 cable 30 meters long, so MegaD could be inside your home, that way there is no need of waterproof box. My monoblock controls 5 irrigation zones while dealing at the same time with alarm system, garage gates, lights and other automation.

Please post the code lines and log.

Hi et all,
nice to see the script still alive.
Just wanted to restart my irriagtion system and receveived this error:

Ambiguous feature call.
The methods
	parse(CharSequence) in Duration and
	parse(CharSequence) in ZonedDateTime
both match.
{
	"resource": "/etc/openhab/rules/irrigation.rules",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "org.eclipse.xtext.diagnostics.Diagnostic.Linking",
	"severity": 8,
	"message": "The method or field dateTime is undefined for the type Duration",
	"startLineNumber": 363,
	"startColumn": 136,
	"endLineNumber": 363,
	"endColumn": 144
}

it is related to this line(again!!)

val userStartTime = parse(now.getYear() + "-" + NowMonth + "-" + NowDay + "T" + WtrStartTime.state + ":00.000+02:00[Europe/Brussels]").dateTime.withZoneSameInstant(ZoneId.systemDefault())

Has there been anything changed regarding DateTime or does anyone know what do here?

@Michal_Szymanski have you managed to rewrite the code for OH3? I’m asking for a friend;)

UPDATE:
Found the the solution based on this threat option #5.
So the wokring line looks like this:

val userStartTime = ZonedDateTime.parse(now.getYear() + "-" + NowMonth + "-" + NowDay + "T" + WtrStartTime.state + ":00.000+02:00[Europe/Brussels]").withZoneSameInstant(ZoneId.systemDefault())

Does anyone have actual version of this system for OH3?
@Jacek_Kaczmarczyk maybe You have something with Polish translations?:slight_smile:

@Kamil_Matuszczak hm i have my own fork of this, working ok with openhab. What problem are you trying to solve ?

Evapotranspirations algorithm update for OpenHAB4

Thanks a lot for the ETo algorithm! I tested it on my system with OpenHAB4. Following the code of the rule:

import java.lang.Math

rule "Hargreaves ETo"  //evapotranspiration in mm / day
when
	Time cron "0 59 23 * * ?"		//runs just before midnight
    or Item OneCallAPIweatherandforecast_ForecastToday_Maxtemperature changed
    or Item OneCallAPIweatherandforecast_ForecastToday_Mintemperature changed
   

then
    // logInfo("ETo triggered","ETo triggered")
    val Number solar_const = 0.0820
    val Number latitude = xx.xxx  //Latitude of location in decimal degrees
    val Number tmin = (OneCallAPIweatherandforecast_ForecastToday_Mintemperature.state as Number).doubleValue
    val Number tmax = (OneCallAPIweatherandforecast_ForecastToday_Maxtemperature.state as Number).doubleValue
	// var double tmin = (Temp_Min.state as QuantityType<Number>).doubleValue
	// var double tmax = (Temp_Max.state as QuantityType<Number>).doubleValue
	var tDiff = tmax - tmin			//difference between max and min temperatures
	var tmean = (tmax + tmin) / 2	//mean temperature
    var doy = now().getDayOfYear()
	var lat_rad = Math.toRadians(latitude.doubleValue)
	var sd = 0.409 * Math.sin(((2 * Math.PI / 365) * doy - 1.39))	// solar declination (rad)
	var sha = Math.acos((-Math.tan((lat_rad)) * Math.tan(sd)))  //sunset hour angle
	var irl = 1 + (0.033 * Math.cos(((2 * Math.PI / 365)* doy)))   //inverse relative distance earth-sun [dimensionless]
    //the next three lines break down the incoming solar energy equation so I could read it in my text editor
	var tmp2 = sha * Math.sin(lat_rad) * Math.sin(sd)                   
	var tmp3 = Math.cos(lat_rad) * Math.cos(sd) * Math.sin(sha)  
	var Ra = (1440 / Math.PI) * solar_const * irl * (tmp2 + tmp3)  //incoming solar energy
	var hETo = 0.0023 * (tmean + 17.8) * Math.pow(tDiff.doubleValue,0.5) * 0.408 * Ra
	OSEvapotraspiration.postUpdate(hETo) //Update Item
end