Author Topic: Adventures in irrigation  (Read 4726 times)

iostream212

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
Adventures in irrigation
« on: July 10, 2012, 07:30:30 am »
My irrigation control has been very basic.  Started with my Rain Bird controller.  Then I automated my zones by using a CAT5 run from the irrigation controller to my ELK relay board.

Controller side:



ELK relay board side:



So this setup has been in place for several years, but nothing fancy. I use Elve to toggle zones every now and then.  Then the day came where I started a zone and left it running overnight.  One soggy lawn and $400 water bill later I decided it was time to further automate irrigation.

1.) First thing I did was add a safety check to prevent the zone from running past a certain time regardless of how the zone was started.  This was done by adding an 'Output state change' rule for each of the zones in my system.
This rule is fired whenever the sprinkler zone is turned on:

Code: [Select]
System.Sleep((Number(vars.GetVariableValue(@"intSprinklerAutoStop"))) * 1000);
if ( ELKM1.OutputStates[10] == true )
{
ELKM1.TurnOffOutput(10);
}

Notice I set a global variable for the runtime. That way if I ever need to change it I just change one variable instead of every rule for every zone.  Simply this rule sleeps for the total maximum defined runtime, then checks if the zone is still on past that runtime. If it is then it is turned off.

2.) Now that the safety system is in place I moved on to touchscreen creation. This is modified from the sample iPhone interface. The zone sliders are just boolean controls tied to ELK outputs.  The manual cycle button is where the new work on this screen set begins.



I wanted the button to have feedback of whether a irrigation cycle was running or not.  My irrigation cycle is run from my ISY and their irrigation module.  My irrigation cycle program in ISY is:

Code: [Select]
If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        Set Elk Output '1-FRONT LEFT' On
        Wait  5 minutes
        Set Elk Output '1-FRONT LEFT' Off
        Wait  1 second
        Set Elk Output '2-FRONT RIGHT' On
        Wait  5 minutes
        Set Elk Output '2-FRONT RIGHT' Off
        Wait  1 second
        Set Elk Output '3-BACK YARD' On
        Wait  5 minutes
        Set Elk Output '3-BACK YARD' Off
        Wait  1 second
        Set Elk Output '4-FRONT DRIP' On
        Wait  10 minutes
        Set Elk Output '4-FRONT DRIP' Off
        Wait  1 second
        Set Elk Output '5-BACK DRIP' On
        Wait  10 minutes
        Set Elk Output '5-BACK DRIP' Off
        Wait  1 second
        Set Elk Output '6-TREE DRIP' On
        Wait  10 minutes
        Set Elk Output '6-TREE DRIP' Off
 
Else
   - No Actions - (To add one, press 'Action')

There is other code in ISY to only run the irrigation cycle based on EVTO and to send notifications upon running, but that is not the focus of this post. So now the focus becomes to have this button activate my ISY irrigation program and get feedback from the ISY if the cycle is running.  Here is the resulting code for the activate button:

Code: [Select]
if (this.Text == "Activate")
{
http.RetrieveWebPage(@"http://isy:85/rest/programs/003C/runThen", @"User", @"Password");
this.Text="Running";
this.ForeColor = "#DC3C3C";
strResult = "running=\"then\"";
while (strResult.contains("running=\"then\""))
{
system.sleep(60000);
strResult = http.RetrieveWebPage(@"http://isy:85/rest/programs/003C", @"User", @"Password");
}
this.Text = "Activate";
this.ForeColor = "#6F789B";
end;
}
else
{
this.Text="Stopping...";
for(i=10;i<16;i++)
{
ELKM1.TurnOffOutput(i);
system.sleep(1000);
}
http.RetrieveWebPage(@"http://isy:85/rest/programs/003C/stop", @"User", @"Password");
this.Text = "Activate";
this.ForeColor = "#6F789B";
end;
}

This code starts the cycle when pressed, then changes the button text to running. Then the program polls the ISY every minute until the cycle is finished. Once finished the button is reset.  If the button is pressed while running it cancels the cycle.  The program is stopped in ISY, all irrigation zones are cycled through and turned off, then the button is reset.

Here is the result when starting the cycle:



Here is the result when stopping the cycle:



This takes care of everything I set out to do with the exception of "What if I start the viewer when the irrigation cycle is already running?"  To fix that I added a control loaded event to the button that checks if the cycle is running and sets the button as appropriate.

Code: [Select]
strResult =  http.RetrieveWebPage(@"http://isy:85/rest/programs/003C", @"User", @"Password");
if (strResult.contains("running=\"then\""))
{
this.Text="Running";
this.ForeColor = "#DC3C3C";
}
I always wanted to be somebody. In retrospect, I think I should have been more specific.