This simple solution uses the free WUnderground API to cancel regularly scheduled irrigation (mine uses EZFlora) if either are true:
a. It's currently raining in my zip code
b. It has already rained more than 1/4 inch in my zip code today
- Register and signup for a free API key from Wunderground choosing the free 'Developer' plan: http://www.wunderground.com/weather/api/d/pricing.html
- Create a directory in the root of your hard drive:
- Code: Select all
/ruby
- Copy the ruby code below, edit the config section noted by 'CHANGE THIS', and save the file to that newly created directory like so
- Code: Select all
/ruby/weather.rb
- Add a cron entry to run that script every 5 minutes:
- Code: Select all
*/5 * * * * ruby /ruby/weather.rb
- Create the variables shown in the attached screenshot, and add the conditions shown to your irrigation schedule
I've tested it and both variables properly worked!
Note: the following can be used to add the cron entry from terminal:
- Code: Select all
env EDITOR=nano crontab -e
then just paste the line from step 4 above.
_____________________________________________
Here is the ruby code:
- Code: Select all
require 'net/http'
require 'logger'
require 'json'
########## CHANGE THESE ################
wunderground_key = 'ENTER YOUR KEY HERE'
indigo_username = 'ENTER YOUR INDIGO USERNAME HERE'
indigo_password = 'ENTER YOUR INDIGO PASSWORD HERE'
zipcode = "ENTER YOUR ZIP CODE HERE"
log_filepath = '/Users/tony/weather.log' # You'll need to change /Users/tony to whatever is the directory for your Mac user
########################################
`touch #{log_filepath}` # touch file if it doesn't exist
logger = Logger.new(log_filepath, 'monthly')
# get current conditions
conditions_url = "http://api.wunderground.com/api/#{wunderground_key}/geolookup/conditions/q/#{zipcode}.json"
url = URI.parse(conditions_url)
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
json_string = res.body
puts json_string
parsed_json = JSON.parse(json_string)
# retrieve data we want from parsed json
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
inches_of_rain_today = parsed_json['current_observation']['precip_today_in']
weather = parsed_json['current_observation']['weather'].downcase
currently_raining = 'FALSE'
if weather.include?("rain")
currently_raining = "TRUE"
end
# update indigo variables
`curl --digest -u #{indigo_username}:#{indigo_password} -X PUT -d value=#{inches_of_rain_today} http://127.0.0.1:8176/variables/inches_rained_today`
`curl --digest -u #{indigo_username}:#{indigo_password} -X PUT -d value=#{currently_raining} http://127.0.0.1:8176/variables/currently_raining`
# log data
logstring = "Current temperature in #{location} is: #{temp_f} and it has rained #{inches_of_rain_today} today\n"
print logstring
logger.info(logstring)