Created
July 16, 2019 05:09
-
-
Save aeshirey/53eb3b7f03062291771bade25dd543bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# maximum allowable delta (°F) before we start the fans | |
TEMP_DELTA = 5.0 | |
def check_temp(): | |
global VENTILATION_STATE | |
c = db.cursor() | |
# get the last ten minutes of data only | |
c.execute("SELECT temp, room FROM temps WHERE (julianday('now') - julianday(timestamp))*86400 < 600 ORDER BY timestamp") | |
inside_temps, outside = [], 0.0 | |
for temp, room in c.fetchall(): | |
if room == 'outside': | |
outside = temp | |
elif room == 'inside': | |
inside_temps.append(temp) | |
# average all inside temps seen | |
inside = sum(inside_temps)/len(inside_temps) | |
if inside - TEMP_DELTA > outside: | |
# it's hot inside. let's cool it off | |
if VENTILATION_STATE != 'on': | |
print("Cooler outside (%f) than inside (%f). Turning on ventilation" % (outside, inside)) | |
VENTILATION_STATE == 'on' | |
mqtt_client.publish('ventilate', payload='on') | |
elif inside <= outside: | |
# we're already cooler than outside | |
if VENTILATION_STATE == 'on': | |
# turn off ventilation | |
print("Hotter outside (%f) than inside (%f). Turning off ventilation" % (outside, inside)) | |
VENTILATION_STATE == 'off' | |
mqtt_client.publish('ventilate', payload='off') | |
else: | |
print("warmer outside, but not terrible") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment