1. senex
  2. pysprinklers

Commits

senex  committed c210754

Skip threshold was expanded from just a 24 hour view to a 24 hour and 48 hour view. This allows for skipping a session if it rained heavily 2 days prior.

Code for detecting chance of rain was fixed, lookups should work now (typo).

Added watering duration adjustment to reduce water when it rains even if our threshold isn't met. Reduciton is proportional to the amount of rain received compaired to the 24 hour threshold. Example: if the threshold is .08 inches and it rains .04 inches in the last 24 hours, it will activate the sprinklers for 1/2 the time.

  • Participants
  • Parent commits 67ae255
  • Branches default

Comments (0)

Files changed (4)

File data/config.py

View file
 #inches of rain for the last 24 hours will be comparied agains this number
 SKIP_THRESHOLD_INCHES=0.08
 
+# Same as SKIP_THRESHOLD_INCHES but for a 48 hour time period
+SKIP_THRESHOLD_INCHES_48=SKIP_THRESHOLD_INCHES * 2
+
 #If its time to water the lawn but there is a good chance it will rain then
 #wait this long to try again
 FORCAST_TRIGGERED_DELAY= 3 * 60 * 60
 FORECAST_THRESHOLD_TRIGGER=30
 
 #How long the water is to be left on for each zone
-WATERING_TIME_PER_ZONE_SECONDS= 12 * 60
+WATERING_TIME_PER_ZONE_SECONDS= 9 * 60
 
 #Numbe of inches a click/impulse is equal to on your tipping bucket rain guage
 INCHES_PER_IMPULSE=0.0204

File scripts/libpysprinklers.py

View file
 def get_chance_of_rain():
     """Get the percentage chance of rain"""
     try:
-        xml_str = urllib2.urlopen(weather_gov_url).read()
+        xml_str = urllib2.urlopen(WEATHER_GOV_URL).read()
 
         stuff = ET.fromstring(xml_str)
         v = stuff.findall("data/parameters/probability-of-precipitation/value")

File scripts/rain_tweeter.py

View file
             "The rain stopped, hope the grass got enough",
             "Rain is over",
             "As far as I can tell, it's no longer raining",
-            "Rain has stoped",
+            "Rain has stopped",
         ]
         tweet_text = random.choice(rain_stop_tweet)
         tweet_text += ".  Last 24 hours was %s inches"%ps.get_inches_for_last_hours(24)

File scripts/sprinkler_manager.py

View file
 if "--debug" in sys.argv:
     ps.WATERING_TIME_PER_ZONE_SECONDS= 20 
     ps.SKIP_THRESHOLD_INCHES=119.10
+    ps.SKIP_THRESHOLD_INCHES_48=119.10
 
 if "--rs-check" in sys.argv:
     secs = ps.get_sprinklers_on_duration()
     ps.set_sprinkler_state("off")
     quit()
 
+# Inches of rain for the last 24 hours
 inches = ps.get_inches_for_last_hours(24)
 
 if inches >= ps.SKIP_THRESHOLD_INCHES:
         inches, tweet_data)
     quit()
 
+# Inches of rain for the last 48 hours
+inches_48 = ps.get_inches_for_last_hours(48)
+
+if inches_48 >= ps.SKIP_THRESHOLD_INCHES_48:
+    ps.ts_print("It rained %s inches in the last 48 hours... skipping sprinklers today"%
+        inches_48, tweet_data)
+    quit()
+
+# Chance of rain
 chance_of_rain = ps.get_chance_of_rain()
+ps.ts_print("Chance of rain is %d%%"%chance_of_rain)
 if chance_of_rain >= ps.FORECAST_THRESHOLD_TRIGGER:
     ps.ts_print("There is a %d%% chance that it will rain, gonna hold off "\
         "watering the lawn a bit"%chance_of_rain)
             "Good thing I waited a bit"%inches, tweet_data)
         quit()
 
+# Can we reduce duration if it rained some?
+watering_time_per_zone = ps.WATERING_TIME_PER_ZONE_SECONDS
+if inches != 0:
+    #Reduce watering based on how much it has rained toward the goal
+    watering_time_per_zone = (ps.WATERING_TIME_PER_ZONE_SECONDS -
+       (ps.WATERING_TIME_PER_ZONE_SECONDS * inches/ps.SKIP_THRESHOLD_INCHES))
+    if watering_time_per_zone < 5 or watering_time_per_zone >  ps.WATERING_TIME_PER_ZONE_SECONDS:
+        #Something went wrong in the calculation, revert
+        watering_time_per_zone = ps.WATERING_TIME_PER_ZONE_SECONDS
+    else:
+        ps.ts_print("Reducing watering time from %d to %d seconds"%(
+            ps.WATERING_TIME_PER_ZONE_SECONDS, watering_time_per_zone))
+
 if inches == 0:
     ps.ts_print("No rain in the last 24 hours... Watering lawn", tweet_data)
 else:
+    bonus_text=""
+    if watering_time_per_zone != ps.WATERING_TIME_PER_ZONE_SECONDS:
+        bonus_text=" for only %d min/zone since we got a little rain"%\
+            (watering_time_per_zone/60)
     ps.ts_print("It rained about %s inches in the last 24 hours... "\
-        "Watering lawn"%inches, tweet_data)
+        "Watering lawn%s"%(inches,bonus_text), tweet_data)
 
 for zone in range(1, ps.NUM_SPRINKLER_ZONES + 1):
     ps.ts_print("Watering zone %d for %d seconds (%d minutes)"%(zone,
-        ps.WATERING_TIME_PER_ZONE_SECONDS,
-        ps.WATERING_TIME_PER_ZONE_SECONDS/60))
+        watering_time_per_zone,
+        watering_time_per_zone/60))
     ps.set_sprinkler_state("on", simulate_opt)
-    time.sleep(ps.WATERING_TIME_PER_ZONE_SECONDS)
+    time.sleep(watering_time_per_zone)
     ps.set_sprinkler_state("off", simulate_opt)
     #Give time for zone switching
     time.sleep(10)