daily pastebin goal
56%
SHARE
TWEET

sprinkler.py

tripzero May 16th, 2015 (edited) 712 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. from Koyo import Koyo
  4. import urllib2
  5. import json
  6. import time
  7.  
  8. from et import Et
  9.  
  10. plc = Koyo('192.168.0.200')
  11.  
  12. f = urllib2.urlopen('http://api.wunderground.com/api/{apiKey}/geolookup/conditions/q/OR/Hillsboro.json')
  13. json_string = f.read()
  14. f.close()
  15. parsed_json = json.loads(json_string)
  16. location = parsed_json['location']['city']
  17. temp_f = parsed_json['current_observation']['temp_f']
  18.  
  19. precip = parsed_json['current_observation']['precip_today_metric']
  20.  
  21. lawn = Et('fogo').get()["LAWN"]
  22.  
  23. with open('/home/root/config.json') as config_file:
  24.         sprinklerSystem = json.load(config_file)
  25.  
  26. zones = sprinklerSystem['zones']
  27.  
  28. precip = float(precip)
  29.  
  30. print ("daily precipitation", precip, " forcasted et ", lawn.forcast)
  31.  
  32.  
  33. if precip < lawn.forcast:
  34.         stillNeed = lawn.forcast - precip
  35.  
  36.         for zone in zones:
  37.                 waterTime = stillNeed / zone['rate']
  38.                 print ("starting zone {0} for {1} mins".format(zone['id'], waterTime))
  39.                 plc.WriteOutput(zone['id'], True)
  40.  
  41.                 time.sleep(waterTime * 60)
  42.                 plc.WriteOutput(zone['id'], False)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top