(Oct-23-2016, 08:39 PM)sparkz_alot Wrote: when you take a line like this
temperature = int(temperature)this keeps it a numeric value, and a whole number.
LOL I'd just worked this out myself as I saw the email update come in ... NOW it's fully working as expected...
if the "humi" is between 56 and 64 it will do nothing and it should be off. If the humidity goes hits 65 or higher then it comes on and stays on until it gets to 55 or lower.
I think the real issue I had was that pesky string conversion. I'm quite new to python and doing a lot of hacking about with it to make things work. It's a learning curve.
Thanks very much folks .. I'll post the new fully updated script taking all your comments into it as well, especially about the inconsistent print statements, while they did work it as ugly to look at hah
Ok, here's the new full script and it's working as expected ...
#!/usr/bin/python # HEADER ################################################################################################### # # Author : Robert McKenzie <[email protected]> # Script Name : humidy-check.py # ################################################################################################### hithresh = 65 lothresh = 55 import time now = time.strftime("%c") import sys import Adafruit_DHT import RPi.GPIO as GPIO import subprocess sensor = Adafruit_DHT.DHT22 pin = 4 GPIO.setmode(GPIO.BCM) while 1: # This gets the temp and humidity from the sensor and sets the result to a whole number instead of 15 decimal places humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if temperature is not None: temp = '{:.0f}'.format(temperature) if humidity is not None: humi = int(humidity) if humi >= hithresh : print("Current time %s" % now ) print("Humidity is {} - too high. We can turn on the dehumidifier".format(humi)) print("Switching on the dehumidifier") subprocess.check_output("/usr/local/bin/hs100.sh 172.16.29.146 9999 on", shell=True) time.sleep(3) dehumidpwr = subprocess.check_output("/usr/local/bin/hs100.sh 172.16.29.146 9999 check", shell=True) print("Dehumidifier is - {}".format(dehumidpwr)) print("=======================================================================") elif humi <= lothresh: print("Current time %s" % now ) print("Humidity is {} - to low. We should turn off the dehumidifier".format(humi)) print("Switching off the dehumidifier") subprocess.check_output("/usr/local/bin/hs100.sh 172.16.29.146 9999 on", shell=True) time.sleep(3) dehumidpwr = subprocess.check_output("/usr/local/bin/hs100.sh 172.16.29.146 9999 check", shell=True) print("(Dehumidifier is - {}".format(dehumidpwr)) print("=======================================================================") else: print("Do nothing") print("Current time %s" % now ) print("Humidity is {}".format(humi)) print("=======================================================================") sys.exit(0)