View unanswered posts | View active topics It is currently Sat May 25, 2013 9:44 pm



Reply to topic  [ 29 posts ]  Go to page: 1, 2  Next
 Sprinkler/Irrigation Script 
Author Message

Joined: Jan 19, 2004
Posts: 64
Post Sprinkler/Irrigation Script
Hi,

Just got my indigo and rain8 sprinkler up and working. I created a script to make the setting of the sprinklers simpler to manage. Matt has been kind enought to add the script to

http://www.perceptiveautomation.com/indigo/scripts/Sprinkler%20Automation/Sprinkler%20Script1/download.dmg

The file is 'sprinkler schedule attachement.scpt' and the script call is

RunSprinklerSchedule(schedule_name)

This script is designed to work with Indigo and aid in setting up watering schedules. It should be placed in the Attachements folder of the Indigo User Data directory.

It assumes the exisitence of a special directory HOME:Documents:Indigo User Data:Irrigation Schedules: which must be created by the user. In this directory are placed text files which consist of lines of data each line of which has a device name and duration in minutes separated by a comma.

Example

sprinkler 1, 5
sprinkler 2, 4
sprinkler 3, 10

The script is intended to be used in conjuction with a Time/Date action that uses an embedded AppleScript Action that calls "RunSprinklerSchedule(schedule_filename)". The Time/Date action set the starting time (and day) for the schedule which is in the file schedule_name in the Irrigation Schedules directory. It then creates a set of delayed actions from the time of the trigger action turning the each device in the list on, and then off after the duration specified. It puts 5 seconds between an off event and an on event.

To debug your sprinkler schedules you can call RunSprinklerScheduleDebug(schedule_filename), which will define the schedule duration intervals in seconds, instead of minutes.

There is no error checking in the script to ensure that device names exist but the user can look at the event log to determine if there are errors.

Copyright © 2004 DSB Associates.

This code is freely distributed with no restrictions.

I've also created a Filemake pro database to make the generation of the input files easier and more visual. You can get these at

http://homepage.mac.com/dscottbuch/

in a zip file. They output files to the Irrigation Schedules directory, one for each day of the week. You need to edit the Devices value list in the _Schedules database for your list of devices.

Cheers


Sat Jan 31, 2004 6:34 pm
Profile

Joined: Jan 19, 2004
Posts: 64
Post 
I've added an additional functionality to better deal with a weeks worth of schedules

RunSprinklerScheduleSeries(series_Name)

This script is meant to be used with a series of irrigation schedule files of the form "series_name day" where series_name is the name of the series and day is the day of week, i.e., Monday, Tuesday, etc. The intent is that one Time/Date action can be set to run uniques watering combinations at the same time of day each day. For further example the files would be "Mornings Monday", "Mornings Tuesday", "Mornings Wednesday", "Mornings Thursday", "Mornings Friday", "Mornings Saturday", "Mornings Sunday". Then a single Time/Date Action with the call RunSprinklerScheduleSeries("Mornings") would activate all of these schedules, one on each day of the week.

RunSprinklerScheduleSeriesDebug(series_Name,dayofweek) is also provided which will allow the user to test each day using seconds.


The script is also available at http://homepage.mac.com/dscottbuch


Sun Feb 01, 2004 5:11 pm
Profile

Joined: Jan 19, 2004
Posts: 64
Post 
Continuing my automation of my irrigation system I've written the code below to automate turing off the sprinklers for a period of time which is input by the user.

One question I have is, is there a way to get they name of the active database from the applescript so that the script can be generalized.

Code: Select all
(*

   Routines to extract the list of TD actions and Trigger Actions from the specified database
   
   GetTDActions(dbname) returns a list of Time/Date Actions from the named database.

   GetTriggerActions(dbname) returns a list of Trigger Actions from the named database.
   
   In both cases the list is empty of no actions of the respective types are found.
   
   These Scripts require the Scripting Addition XML Tools.osax from Late Night Software and can be found at http://www.latenightsw.com/freeware/XMLTools2/index.html THIS SOFTWARE IS COPYRIGHT © 1998-2002 LATE NIGHT SOFTWARE LTD
   
   The main code uses these routines to Enable or Disable any Time/Date Action which begins with the word watering for an input period of time
   
   Copyright © 2004 DSB Associates.

   This code is freely distributed with no restrictions.



*)

tell application "Indigo"
   display dialog "Enable or Disable watering:" buttons {"Cancel", "Enable", "Disable"} default button 2
   copy the result as list to {button_pressed}
   log button_pressed
   if button_pressed is "Disable" then
      display dialog "This will disable the watering actions for a number of days.  Please enter the number of days you would like:" default answer "1" buttons {"Cancel", "Delay"} default button 2
      copy the result as list to {delay_days, button_pressed}
      
      set duration to (delay_days as number) * 24 * 3600
      set TDActions to my GetTDActions("Buchanan Household.indiDb")
      repeat with i from 1 to (count of TDActions)
         set this_action to item i of TDActions
         if the first word of this_action is "watering" then
            disable time date action this_action for duration
         end if
      end repeat
   else
      set TDActions to my GetTDActions("Buchanan Household.indiDb")
      repeat with i from 1 to (count of TDActions)
         set this_action to item i of TDActions
         if the first word of this_action is "watering" then
            remove delayed actions for trigger this_action
            enable time date action this_action
         end if
      end repeat
   end if
end tell


on GetTDActions(dbname)
   tell application "Finder"
      set fname to ((home as string) & "Documents:Indigo User Data:" & dbname)
   end tell
   try
      set dbfile to (open for access file fname)
      set theXMLSource to (read dbfile)
      close access dbfile
   on error
      close access dbfile
      return {}
   end try
   
   set theXML to parse XML theXMLSource
   set dbcontents to the XML contents of theXML
   set ndb to count dbcontents
   set TDActions to {}
   
   try
      repeat with i from 1 to ndb
         set dbitem to item i of dbcontents
         if XML tag of dbitem is equal to "TDTriggerList" then
            set tdlist to XML contents of dbitem
            set ntd to count of tdlist
            repeat with j from 1 to ntd
               set trig to the XML contents of item j of tdlist
               repeat with k from 1 to count of trig
                  if XML tag of item k of trig is equal to "Name" then
                     set TDActions to TDActions & (the XML contents of item k of trig)
                  end if
               end repeat
            end repeat
            return TDActions
         end if
      end repeat
   on error
      log "No Time/Date Trigger Actions Found"
      return {}
   end try
   
end GetTDActions

on GetTriggerActions(dbname)
   tell application "Finder"
      set fname to (home as string) & "Documents:Indigo User Data:" & dbname
   end tell
   try
      set dbfile to (open for access file fname)
      set theXMLSource to (read dbfile)
      close access dbfile
   on error
      close access dbfile
      return {}
   end try
   set theXML to parse XML theXMLSource
   set dbcontents to the XML contents of theXML
   set ndb to count dbcontents
   set TDActions to {}
   
   try
      repeat with i from 1 to ndb
         set dbitem to item i of dbcontents
         if XML tag of dbitem is equal to "TriggerList" then
            set tdlist to XML contents of dbitem
            set ntd to count of tdlist
            repeat with j from 1 to ntd
               set trig to the XML contents of item j of tdlist
               repeat with k from 1 to count of trig
                  if XML tag of item k of trig is equal to "Name" then
                     set TDActions to TDActions & (the XML contents of item k of trig)
                  end if
               end repeat
            end repeat
            return TDActions
         end if
      end repeat
   on error
      log "No Trigger Items Found"
      return {}
   end try
   
end GetTriggerActions


Edit: Removed one incorrect line of code in the part that handles the enable function.


Last edited by dscottbuch on Wed Feb 04, 2004 12:18 pm, edited 1 time in total.



Wed Feb 04, 2004 9:24 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post 
dscottbuch wrote:One question I have is, is there a way to get they name of the active database from the applescript so that the script can be generalized.

Wow. Very cool script. That is the first script I have seen that reads the database file itself to extract information.

There isn't a way to get the active database name currently, but I'll add a property on the application that is the active database name, or the full file path to the active database file. I'll post this in the next build, probably in a few days.

Regards,
Matt


Wed Feb 04, 2004 9:49 am
Profile WWW

Joined: Jan 19, 2004
Posts: 64
Post 
support wrote:
dscottbuch wrote:One question I have is, is there a way to get they name of the active database from the applescript so that the script can be generalized.

Wow. Very cool script. That is the first script I have seen that reads the database file itself to extract information.

There isn't a way to get the active database name currently, but I'll add a property on the application that is the active database name, or the full file path to the active database file. I'll post this in the next build, probably in a few days.

Regards,
Matt


Thanks. How does one get the current build ?

Regards,
Scott


Wed Feb 04, 2004 12:19 pm
Profile

Joined: Jan 19, 2004
Posts: 64
Post Getting the database name
Here's some quick code to get the database name.

on GetDatabaseName()
     tell application "Indigo"
          set y to name of windows
          repeat with i from 1 to (count of y)
               if item i of y is not equal to "" then
                    if the first word of item i of y is not in {"Variable", "Event"} then
                         set z to ((item i of y) as string) & ".indiDb"
                         return z
                    end if
               end if
          end repeat
     end tell
end GetDatabaseName


-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]


Thu Feb 05, 2004 4:35 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post Re: Getting the database name
I've posted a new Indigo beta which has an new application property, "database file", that should simplify this:

http://www.perceptiveautomation.com/ind ... o_beta.dmg

Regards,
Matt


Fri Feb 06, 2004 1:40 pm
Profile WWW

Joined: Jan 19, 2004
Posts: 64
Post Re: Getting the database name
support wrote:I've posted a new Indigo beta which has an new application property, "database file", that should simplify this:

http://www.perceptiveautomation.com/ind ... o_beta.dmg

Regards,
Matt


Thanks. Works great.

Here's the new script taking advantage of the change.

(*

     Routines to extract the list of TD actions and Trigger Actions from the specified database
     
     GetTDActions(dbname) returns a list of Time/Date Actions from the named database.

     GetTriggerActions(dbname) returns a list of Trigger Actions from the named database.
     
     In both cases the list is empty of no actions of the respective types are found.
     
     These Scripts require the Scripting Addition XML Tools.osax from Late Night Software and can be found at http://www.latenightsw.com/freeware/XML ... index.html THIS SOFTWARE IS COPYRIGHT © 1998-2002 LATE NIGHT SOFTWARE LTD
     
     The main code uses these routines to Enable or Disable any Time/Date Action which begins with the word watering for an input period of time
     
     Copyright © 2004 DSB Associates.

     This code is freely distributed with no restrictions.



*)


tell application "Indigo"
     set db_name to database file
     display dialog "Enable or Disable watering:" buttons {"Cancel", "Enable", "Disable"} default button 2
     copy the result as list to {button_pressed}
     log button_pressed
     if button_pressed is "Disable" then
          display dialog "This will disable the watering actions for a number of days. Please enter the number of days you would like:" default answer "1" buttons {"Cancel", "Delay"} default button 2
          copy the result as list to {delay_days, button_pressed}
          
          set duration to (delay_days as number) * 24 * 3600
          set TDActions to my GetTDActions(db_name)
          repeat with i from 1 to (count of TDActions)
               set this_action to item i of TDActions
               if the first word of this_action is "watering" then
                    disable time date action this_action for duration
               end if
          end repeat
     else
          set TDActions to my GetTDActions(db_name)
          repeat with i from 1 to (count of TDActions)
               set this_action to item i of TDActions
               if the first word of this_action is "watering" then
                    remove delayed actions for trigger this_action
                    enable time date action this_action
               end if
          end repeat
     end if
end tell


on GetTDActions(dbname)
     try
          set dbfile to (open for access file dbname)
          set theXMLSource to (read dbfile)
          close access dbfile
     on error
          close access dbfile
          return {}
     end try
     
     set theXML to parse XML theXMLSource
     set dbcontents to the XML contents of theXML
     set ndb to count dbcontents
     set TDActions to {}
     
     try
          repeat with i from 1 to ndb
               set dbitem to item i of dbcontents
               if XML tag of dbitem is equal to "TDTriggerList" then
                    set tdlist to XML contents of dbitem
                    set ntd to count of tdlist
                    repeat with j from 1 to ntd
                         set trig to the XML contents of item j of tdlist
                         repeat with k from 1 to count of trig
                              if XML tag of item k of trig is equal to "Name" then
                                   set TDActions to TDActions & (the XML contents of item k of trig)
                              end if
                         end repeat
                    end repeat
                    return TDActions
               end if
          end repeat
     on error
          log "No Time/Date Trigger Actions Found"
          return {}
     end try
     
end GetTDActions

on GetTriggerActions(dbname)
     try
          set dbfile to (open for access file dbname)
          set theXMLSource to (read dbfile)
          close access dbfile
     on error
          close access dbfile
          return {}
     end try
     set theXML to parse XML theXMLSource
     set dbcontents to the XML contents of theXML
     set ndb to count dbcontents
     set TDActions to {}
     
     try
          repeat with i from 1 to ndb
               set dbitem to item i of dbcontents
               if XML tag of dbitem is equal to "TriggerList" then
                    set tdlist to XML contents of dbitem
                    set ntd to count of tdlist
                    repeat with j from 1 to ntd
                         set trig to the XML contents of item j of tdlist
                         repeat with k from 1 to count of trig
                              if XML tag of item k of trig is equal to "Name" then
                                   set TDActions to TDActions & (the XML contents of item k of trig)
                              end if
                         end repeat
                    end repeat
                    return TDActions
               end if
          end repeat
     on error
          log "No Trigger Items Found"
          return {}
     end try
     
end GetTriggerActions


-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]


Fri Feb 06, 2004 2:57 pm
Profile

Joined: Apr 30, 2005
Posts: 141
Post 
Can someone describe in a little more detail how to set this sprinkler script up?

I've got the Rain 8 attached to 6 zones. What I would like to do is have the ability to turn each zone on by itself, and then be able to run specific schedules. How would I go about doing this.

Any help is appreciated.

-Bradley


Mon May 02, 2005 6:13 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post 
Hi Bradley,

There are several different scripts available to control the Rain8. The easiest to get up and running is probably the fourth one ("Sprinkler Script4") on the Indigo Scripts page. There are a couple of examples at the top of the script that show you how to use it. Put it in your scripts/attachments/ folder first.

Once you have it installed, you can create Trigger or Time/Date Actions that do a "Execute AppleScript" action with the single line to run the sprinkler zones, as shown in the example comments at the top of the attachment script you downloaded above.

If you get stuck in the process somewhere, let me know.

Regards,
Matt


Mon May 02, 2005 7:19 pm
Profile WWW

Joined: Apr 30, 2005
Posts: 141
Post 
Matt,

That clarifies it. A few quick questions though.

1.) Do you have to have the Macintosh version of the Rain8 for these scrips to work? I've got the Rain8II serial version.

2.) In the example, you have "DoSprinkler("C1", {15, 15, 10, 20})" But from my setup, it seems that each address controls a differnt zone...M1 controls Zone 1, M2 controls Zone 2...etc... (This could be because I don't have the Mac version?)

Should my action be DoSprinkler("M1", {5})

for a 5 minute duration of zone 1?

-Bradley


Tue May 03, 2005 7:44 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post 
You do not have to have the Mac version of the Rain8. The Mac version allows you to easily set the house code used by the Rain8 without a serial connection. Once you have the house code set to what you want, both Rain8s operate identically.

The House/Device code argument to the function is used to specify what address you have already assigned to your Rain8. In your case, presuming the Rain8 is on M1-8, then you want to use "M1." If you had used M9-16, then you would have specific "M9."

Your example should turn on zone 1 for 5 minutes.

Regards,
Matt


Tue May 03, 2005 2:37 pm
Profile WWW

Joined: Apr 30, 2005
Posts: 141
Post 
I've got Indigo and my sprinkler system working great except for one thing. The system does not respond to:

CancelSprinkler("B1")

The event log shows that all zones are being turned off, however the sprinkler does not go off. If I set a particular zone up as a device, it will go on and off.

Anyone else have this problem or know how to fix it?

-Bradley


Sun May 08, 2005 2:14 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11698
Location: Texas
Post 
Hi Bradley,

Can you copy/paste the relevant lines from the Event Log that occur before/during/after the CancelSprinkler() call?

Regards,
Matt


Sun May 08, 2005 5:01 pm
Profile WWW

Joined: Apr 30, 2005
Posts: 141
Post 
Matt,

Here is the relevant info from the event log. First I turned on zone 6, then tried to turn it off with the cancel command. It looks like the command is getting sent properly, but something is wrong. Let me know.

3:05:55 PM, 5/8/05 Sent X10 B6 on
3:06:10 PM, 5/8/05 Trigger Action Cancel Sprinklers
3:06:10 PM, 5/8/05 Sent X10 "Sprinklers" off (address)
3:06:10 PM, 5/8/05 Sent X10 B2 off (address)
3:06:11 PM, 5/8/05 Sent X10 B3 off (address)
3:06:11 PM, 5/8/05 Sent X10 B4 off (address)
3:06:12 PM, 5/8/05 Sent X10 B5 off (address)
3:06:12 PM, 5/8/05 Sent X10 B6 off (address)
3:06:13 PM, 5/8/05 Sent X10 B7 off (address)
3:06:13 PM, 5/8/05 Sent X10 B8 off

Thanks again,
Bradley


Sun May 08, 2005 6:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 29 posts ]  Go to page: 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.