waterlife

git clone https://git.tarina.org/waterlife
Log | Files | Refs

commit 6309e4109cea5d0c9c2c5f82f627b9238d6a36ae
parent 75689f7a6eab517b1c1586dae4c81c8049bf3247
Author: rob <rob@tarina.org>
Date:   Mon, 31 Jul 2023 17:55:11 +0300

one tie

Diffstat:
Mwaterlife.py | 55+++++++++++++++++++++++++++++++++++--------------------
1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/waterlife.py b/waterlife.py @@ -33,6 +33,8 @@ GPIO.output(27,GPIO.HIGH) GPIO.output(17,GPIO.HIGH) GPIO.output(26,GPIO.HIGH) +oldcode = '' + def save_passcodes(passcodes): global folder with open('water.json', 'w') as out_file: @@ -83,15 +85,16 @@ def getcodes(): return data def keylogger(code): - global apikey - print('logging key ' + str(code)) - url = 'https://water.tarina.org/waterapi?apikey='+apikey+'&logger=' + str(code) - try: - resp = requests.get(url=url) - print(resp) - except: - print('cant access water tarina') - return + global apikey, oldcode + if oldcode != code: + oldcode = code + print('logging key ' + str(code)) + url = 'https://water.tarina.org/waterapi?apikey='+apikey+'&logger=' + str(code) + try: + resp = requests.get(url=url) + print(resp) + except: + print('cant access water tarina') def doordebug(): global apikey, open_door, keypass @@ -156,6 +159,8 @@ start_time = time.time() get_code_time = time.time() waterschedule = load_passcodes() watering=False +status='system running' +oldstatus='' if is_webz_on(): keylogger('system up running') else: @@ -165,23 +170,25 @@ while 1: run_time = time.time() - start_time update = time.time() - get_code_time time.sleep(0.1) - if update > 60: + if update > 10: get_code_time = time.time() if is_webz_on(): waterschedule = getcodes() - keylogger('system running') + if status != oldstatus: + keylogger(status) + oldstatus = status else: waterschedule = load_passcodes() - if watering==False: - if datetime.datetime.now().hour==waterschedule['bevattning1']: + if watering==False and waterschedule['system']=='on': + if datetime.datetime.now().hour==waterschedule['bevattning1'] and datetime.datetime.now().minute==55: watering=True wateringstart=time.time() keylogger('watering started') - elif datetime.datetime.now().hour==waterschedule['bevattning2']: + elif datetime.datetime.now().hour==waterschedule['bevattning2'] and datetime.datetime.now().minute==55: watering=True wateringstart=time.time() keylogger('watering started') - if watering == True: + if watering == True and waterschedule['system']=='on': try: hose1=int(waterschedule['hose1']*60) except: @@ -199,31 +206,30 @@ while 1: except: hose4=0 wateringtime = time.time()-wateringstart - print('pump on') GPIO.output(15,GPIO.LOW) if wateringtime < hose1: - print('watering with hose1 ' + str(wateringtime)) + status='watering with hose1 '+str(int(hose1-wateringtime))+' seconds left' GPIO.output(15,GPIO.LOW) GPIO.output(22,GPIO.LOW) GPIO.output(27,GPIO.HIGH) GPIO.output(17,GPIO.HIGH) GPIO.output(26,GPIO.HIGH) elif wateringtime > hose1 and wateringtime < hose1+hose2: - print('watering with hose2 ' + str(wateringtime)) + status='watering with hose2 '+str(int((hose1+hose2)-wateringtime))+' seconds left' GPIO.output(15,GPIO.LOW) GPIO.output(22,GPIO.HIGH) GPIO.output(27,GPIO.LOW) GPIO.output(17,GPIO.HIGH) GPIO.output(26,GPIO.HIGH) elif wateringtime > hose1+hose2 and wateringtime < hose1+hose2+hose3: - print('watering with hose3 ' + str(wateringtime)) + status='watering with hose3 '+str(int((hose1+hose2+hose3)-wateringtime))+' seconds left' GPIO.output(15,GPIO.LOW) GPIO.output(22,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) GPIO.output(17,GPIO.LOW) GPIO.output(26,GPIO.HIGH) elif wateringtime > hose1+hose2+hose3 and wateringtime < hose1+hose2+hose3+hose4: - print('watering with hose4 ' + str(wateringtime)) + status='watering with hose3 '+str(int((hose1+hose2+hose3+hose4)-wateringtime))+' seconds left' GPIO.output(15,GPIO.LOW) GPIO.output(22,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) @@ -237,3 +243,12 @@ while 1: GPIO.output(26,GPIO.HIGH) watering=False keylogger('watering done') + else: + keylogger('system off') + GPIO.output(15,GPIO.HIGH) + GPIO.output(22,GPIO.HIGH) + GPIO.output(27,GPIO.HIGH) + GPIO.output(17,GPIO.HIGH) + GPIO.output(26,GPIO.HIGH) + watering=False +