Any experience with RainMachine integration?

Posted on
Sun Mar 01, 2020 5:41 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

Korey wrote:
...All I really need is the ability for Indigo to turn zones on or off and pause programs, Having the ability to know what zone is running would be a bonus!

If that is really all you need, take a look back near the start of this thread where I posted a set of scripts that do exactly what you want - minus the display of the current state of the RainMachine zones - though, I think that could be added based on timed queries.

Posted on
Sun Mar 01, 2020 9:19 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

Korey wrote:
...All I really need is the ability for Indigo to turn zones on or off and pause programs, Having the ability to know what zone is running would be a bonus!

BTW, did you know RainMachine now supports HomeKit and IFTTT? Of course, without a Reverse HomeBridge plugin, HomeKit won't help you in terms on Indigo. However, IFTTT support might get you some integration - though, since I don't use IFTTT I can't really say.

Posted on
Sun Mar 01, 2020 9:14 pm
Korey offline
User avatar
Posts: 617
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Any experience with RainMachine integration?

berkinet wrote:
Korey wrote:
...All I really need is the ability for Indigo to turn zones on or off and pause programs, Having the ability to know what zone is running would be a bonus!

If that is really all you need, take a look back near the start of this thread where I posted a set of scripts that do exactly what you want - minus the display of the current state of the RainMachine zones - though, I think that could be added based on timed queries.



I actually tried the scripts when you posted them way back, but I couldn't get them to work? are the Shell scripts or python?

Seem like shell as it gives errors if python..

I changed my IP and password and created an action group firing the script but I don't see where it does anything?

I guess I am as dumb as I look.. :D

--
Korey

Posted on
Mon Mar 02, 2020 3:41 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

Korey wrote:
...I guess I am as dumb as I look.. :D

Well, I don't have enough evidence to corroborate or deny that claim :wink:

However, perhaps a re-write of the installation instructions I provided below would help.

    To use the RainMachine script, you will need to create a plain text file named zone-on in
      /Library/Application Support/Perceptive Automation/Scripts/
    If you are running Indigo 7.4, this folder will exist, otherwise you will need to create it

    The easiest way to create the file is to use the TextEdit app. Open TextEdit and create a new file. Then from the Format menu select Make Plain Text. Now paste the script into the editor window.
    Important> Make sure the line #!/bin/ksh is the very first line in the file, with nothing above it.
    Now save the file to the location noted above (creating the Scripts directory if necessary).
    You can now quit TextEdit.

    Now, open a Terminal window (Terminal.app) and enter the following commands, one at a time: (The # and any text after that is a comment and does not need to be entered - though, it will not hurt anything if it is entered, like, if you paste the commands into the terminal window.)
    Code: Select all
    cd /Library/Application\ Support/Perceptive\ Automation/Scripts   # Change directory to the Indigo Scripts folder
    chmod 755 zone-on                                                 # make the sprinkler script executable
    ln zone-on abort-all                                              # create a link (alias) to the zone-on script for the abort-all function
    The way the script works is to use its name to determine the function to perform. zone-on and abort-all are the key functions. However, you can create links for any additional functions functions you wish. The other functions currently available are:
      zone-props
      restart
      log-days
      last-vals
      cycle-start
    The linked name must match a command name exactly.

    Now, to use this from Indigo create an Action Group and set the action to:
    Server Actions -> Script and File Actions -> Run Shell Script
    In the Configure Run Shell Script window, for Full path to file on server enter:
    Code: Select all
    /Library/Application\ Support/Perceptive\ Automation/Scripts/MyShellScripts/zone-on xx yy
    Where xx is the RainMachine zone number and yy is the run time.
    For example, to water zone 1 for 20 minutes:
    Code: Select all
    /Library/Application\ Support/Perceptive\ Automation/Scripts/zone-on 1 20
    Now name the action something like RM: Zone 1 and save it. To start watering for zone 1 now, just execute the action group.
    BTW, to make this more flexible I put the run time in a variable and then in the Run Shell Script command I referenced the variable ID.
    Code: Select all
    /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7.3/Scripts/MyShellScripts/water/zone-on xx  %%v:yyyyyyyyyy%%
    Where yyyyyyyyyy is the variable ID. This way you can change the duration by changing the variable value. You could use one variable for all zones or create a separate variable for each zone if you wanted.

    And, to stop zone 1 (or any/all zone(s) for that matter), create an action with the following Full Path Name
    Code: Select all
    /Library/Application\ Support/Perceptive\ Automation/Scripts/abort-all
    And name it something like RM: Stop All

    When you are done, you should have 1 Action Group for each zone plus 1 Action Group to Stop All

Posted on
Mon Mar 02, 2020 11:36 am
Korey offline
User avatar
Posts: 617
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Any experience with RainMachine integration?

berkinet wrote:
Korey wrote:
...I guess I am as dumb as I look.. :D

Well, I don't have enough evidence to corroborate or deny that claim :wink:

However, perhaps a re-write of the installation instructions I provided below would help.


:shock: :D :D

Thanks! I'll give it a shot when I get home!

--
Korey

Posted on
Mon Mar 02, 2020 1:10 pm
Korey offline
User avatar
Posts: 617
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Any experience with RainMachine integration?

Got it working !

Thanks for your help!

Now how do we add a Pause that will resume watering after a definable duration to that Fancy script of yours?

pause xx

:D

--
Korey

Posted on
Mon Mar 02, 2020 3:55 pm
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

Korey wrote:
...Now how do we add a Pause that will resume watering after a definable duration to that Fancy script of yours? pause xx...

This may be your lucky day. I just looked at the RainMachine API for the first time since I wrote the original script. While there is still no pause zone command, since API v4.5 there is a ppauseall command that will
    Pause all watering on device for the specified duration (in seconds). Calling this with duration set to 0 will unpause the watering.
Since you can only have one zone active at a time, that is pretty much perfect. I'll take a look at adding support tomorrow - it should be pretty easy.

Unless you'd rather specify the time in seconds, I will probably have the script accept input in minutes and then convert internally.

Posted on
Mon Mar 02, 2020 4:26 pm
Korey offline
User avatar
Posts: 617
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Any experience with RainMachine integration?

berkinet wrote:
This may be your lucky day. I just looked at the RainMachine API for the first time since I wrote the original script. While there is still no pause zone command, since API v4.5 there is a ppauseall command that will
    Pause all watering on device for the specified duration (in seconds). Calling this with duration set to 0 will unpause the watering.
Since you can only have one zone active at a time, that is pretty much perfect. I'll take a look at adding support tomorrow - it should be pretty easy.

Unless you'd rather specify the time in seconds, I will probably have the script accept input in minutes and then convert internally.



Perfect!

Minutes would be great!

--
Korey

Posted on
Tue Mar 03, 2020 2:43 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

0
I wrote:
[size=80]... I'll take a look at adding support tomorrow - it should be pretty easy. ....

STOP THE PRESSES. Yes, adding pause support was easy, I have it working. But, along the way I found a full Python3 API called RegenMaschine. This is not exactly officially supported, but it is officially recognized by RainMachine
    A community supported API is available here. Versus the official version it provides much better error handling and easier to work with.
So, I am taking a look at that to see if it is a better way to go for managing a RainMachine with scripting.

Also, while not of interest to me, someone might find this code very useful for creating a plugin. There is also an official Python API. See this page for more information.

Stay tuned.

Posted on
Tue Mar 03, 2020 4:11 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

UPDATE: I have modified the script (below) to support a pause-all command. To add this command execute the following commands from a terminal window
Code: Select all
cd /Library/Application\ Support/Perceptive\ Automation/Scripts   # Change directory to the Indigo Scripts folder
ln zone-on pause-all                                              # create a link (alias) to the zone-on script for the abort-all function
Then in an Action Group set the Run Shell Script command to
Code: Select all
/Library/Application\ Support/Perceptive\ Automation/Scripts/pause-all xx
where xx is the duration in minutes to pause. To end a pause early, set the value to 0. So, you could have 2 actions: one to pause, another to stop the pause.

Now, about the RegenMaschine API. It is probably the way to go for the future. However, since it adds no real functionality, I am not going to switch to it right now since the existing shell script does everything we can do anyway.

Here is the updated script. Make sure you change the IP Address (ADDR) and Password (PWD) at the top of the script.
Code: Select all
#!/bin/ksh

ADDR=aaa.bbb.ccc.ddd
PWD=xxxxx
#  No user changes below this line

DEBUG=false
if $DEBUG; then set -x; fi
CMD=`basename "$0"`
DUR=000

TOKEN=`curl --include \
   --insecure \
   -s \
   --request POST \
   --header "Content-Type: application/json" \
   --data-binary "{ \"pwd\": \"${PWD}\", \"remember\": 1 }" } https://${ADDR}:8080/api/4/auth/login`
TOKEN2=`echo $TOKEN|cut -d\" -f4`

case "$CMD" in
   last-vals)
      if $DEBUG; then echo received log-days; fi
      SDATE=""
      SDAYS=""
      if [[ $1 -ne "" ]]; then SDATE=/$1; fi
      if [[ $2 -ne "" ]]; then SDAYS=/$2; fi
      #curl --include \
      curl --insecure \
      https://${ADDR}:8080/api/4/watering/past${SDATE}${SDAYS}?access_token=$TOKEN2 > \
            "/Library/Application Support/Perceptive Automation/Scripts/water_data.json"
      ;;
   log-days)
      if $DEBUG; then echo received log-days; fi
      SDATE=$1  # end date YYYY-MM-DD
      SDAYS=$2  # days previous
      curl --include \
           --insecure \
      https://${ADDR}:8080/api/4/watering/log/details/${1}/${2}?access_token=$TOKEN2
      ;;
   zone-props)
      if $DEBUG; then echo received log-days; fi
      ZONE=$1
      curl --include \
           --insecure \
      https://${ADDR}:8080/api/4/zone/${ZONE}?access_token=$TOKEN2
      ;;
   abort-all)
      if $DEBUG; then echo received abort-all; fi
      curl --include \
           --insecure \
           --request POST \
          --data-binary "{ \"access_token\": ${TOKEN2} }" \
      https://${ADDR}:8080/api/4/watering/stopall?access_token=$TOKEN2
      ;;
   cycle-start)
      # $1 = cycle
      if $DEBUG; then echo received cycle-start; fi
      PRG=$1
      curl --include \
           --insecure \
           --request POST \
           --data-binary "{ \"time\": ${DUR} }" \    # This should be unecessary, but it seems to be required
           https://${ADDR}:8080/api/4/program/${PRG}/start?access_token=$TOKEN2
      echo -n "program ${PRG}:"
      ;;
   global-disable)
      if $DEBUG; then echo received global-disable; fi
      # Not yet implemented. Not sure if this is even supported in the API
      ;;
   global-enable)
      if $DEBUG; then echo received global-enable; fi
      # Not yet implemented. Not sure if this is even supported in the API
      ;;
   pause-all)
      # $1 duration
      if $DEBUG; then echo received pause-all; fi
      let DUR=$1*60
      curl --include \
           --insecure \
           --request POST \
          --data-binary "{ \"duration\": ${DUR} }" \
            https://${ADDR}:8080/api/4/watering/pauseall?access_token=$TOKEN2
      echo -n "zone ${ZN}:"
      ;;
   pct-mod)
      # $1 = global percentage
      # Not yet implemented.
      if $DEBUG; then echo received pct-mod; fi
      ;;
   status)
      if $DEBUG; then echo received queue; fi
      curl --include \
           --insecure \
           --request GET \
      https://${ADDR}:8080/api/4/watering/zone?access_token=$TOKEN2
      ;;
   restart)
      if $DEBUG; then echo received restart; fi
      curl --include \
           --insecure \
           --request POST \
           --data-binary "{ \"time\": ${DUR} }" \
      https://${ADDR}:8080/api/4/machine/reboot?access_token=$TOKEN2
      ;;
   zone-on)
      # $1 = zone, $2 = duration
      if $DEBUG; then echo received zone-on; fi
      ZN=$1
      let DUR=$2*60
      curl --include \
           --insecure \
           --request POST \
           --data-binary "{ \"time\": ${DUR} }" \
           https://${ADDR}:8080/api/4/zone/${ZN}/start?access_token=$TOKEN2
      echo -n "zone ${ZN}:"
      ;;
   *)   echo invalid operation selected: $CMD
      ;;
esac

exit  0

Posted on
Tue Mar 03, 2020 7:58 am
Korey offline
User avatar
Posts: 617
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Any experience with RainMachine integration?

berkinet wrote:
UPDATE: I have modified the script (below) to support a pause-all command. To add this command execute the following commands from a terminal window
Code: Select all
cd /Library/Application\ Support/Perceptive\ Automation/Scripts   # Change directory to the Indigo Scripts folder
ln zone-on pause-all                                              # create a link (alias) to the zone-on script for the abort-all function
Then in an Action Group set the Run Shell Script command to
Code: Select all
/Library/Application\ Support/Perceptive\ Automation/Scripts/pause-all xx
where xx is the duration in minutes to pause. To end a pause early, set the value to 0. So, you could have 2 actions: one to pause, another to stop the pause.


FANTASTIC! Thank you so much!

I love this community!

:D :D

Incidentally I was playing around and came up with this last night after copying your zone on command.

Not quite right thou and I wasn't home to test it..

Code: Select all
 pauseall)
     # $1 = duration
      if $DEBUG; then echo received pauseall; fi
      let DUR=$1*60
      curl --include \
           --insecure \
           --request POST \
           --data-binary "{ \"time\": ${DUR} }" \
           https://${ADDR}:8080/api/4/watering/pauseall

--
Korey

Posted on
Tue Mar 03, 2020 8:54 am
jay (support) offline
Site Admin
User avatar
Posts: 16264
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Any experience with RainMachine integration?

Note that the RegenMaschine API is Python 3 (and appears to extensively use Python 3 features so a backport to Python 2 doesn't seem likely), so until Indigo moves to Python 3 (which is on the radar but isn't imminent), you would need to do some trickeration to use it in a plugin.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Mar 03, 2020 10:01 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

jay (support) wrote:
Note that the RegenMaschine API is Python 3 ...

Well, yes, that was kind of implicit in the name, Python3 API. That is also a big part of why I chose to not use it as the basis for a script at this time, since without access to the Indigo Object Model, there would be no benefit over the existing shell script.

As for a plugin. While I have no personal interest in writing a RainMachine plugin, I thought maybe the Python3 API might be useful as an architectural model, perhaps using PycURL or Requests. BTW, for anyone who is interested, RainMachine provides their own Python API implementation. It seems to be in Python2.x However, it hasn't been updated in several years, probably because they felt the Python3 API was better.

Posted on
Tue Mar 03, 2020 10:09 am
berkinet offline
User avatar
Posts: 3404
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Any experience with RainMachine integration?

Korey wrote:
...Incidentally I was playing around and came up with this last night after copying your zone on command.
... Not quite right thou and I wasn't home to test it..
Code: Select all
...
    --data-binary "{ \"time\": ${DUR} }" \
    https://${ADDR}:8080/api/4/watering/pauseall
Congratulations, you were actually very close. The main thing you were missing was the addition of the authentication token to the cURL command, and changing the time attribute to duration.
Code: Select all
    --data-binary "{ \"duration\": ${DUR} }" \
    https://${ADDR}:8080/api/4/watering/pauseall?access_token=$TOKEN2

Posted on
Tue Mar 03, 2020 12:43 pm
siclark offline
Posts: 1322
Joined: Jun 13, 2017
Location: UK

Re: Any experience with RainMachine integration?

I've looked to see if there are hookups to other HA systems, especially where we could leverage via mqtt or node-red but consensus seems to be they are happy to let it run locally and no need.

I definitely want the ability to run a zone on demand as some will be connected as required to sprinklers or hoses. However as the Pro has homekit and I can ask Siri on the Apple watch that probably covers most use cases.

Who is online

Users browsing this forum: No registered users and 0 guests

cron