-
Notifications
You must be signed in to change notification settings - Fork 2
/
water.py
42 lines (37 loc) · 942 Bytes
/
water.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import RPi.GPIO as GPIO
from time import sleep
from weather import weather
from ifttt import notify
relay1 = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay1, GPIO.OUT)
# Define Colors for console output
class colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Function to Reset GPIOs
def resetGPIO(relay):
GPIO.output(relay1,GPIO.LOW)
# Function to start relay and give water
def water():
resetGPIO(relay1)
print(colors.BLUE + "Watering Plants...")
GPIO.output(relay1,GPIO.HIGH)
sleep(30)
# Disable Relay
resetGPIO(relay1)
print (colors.GREEN + "Done Watering Plants")
#Get Weather information
weather() # get weather information
notify() # send telegram notification via IFTTT
# clean up GPIO
GPIO.cleanup()
# Exit script
exit()
water()