Skip to content

Instantly share code, notes, and snippets.

@mcprat
Last active February 6, 2025 23:49
Show Gist options
  • Save mcprat/226aa2a75676f398db5c4fc327c874ab to your computer and use it in GitHub Desktop.
Save mcprat/226aa2a75676f398db5c4fc327c874ab to your computer and use it in GitHub Desktop.
AquaCal TropiCal Heater Heat Pump Pimoroni Automation Hat main program (5V thermistor voltage divider, 85F water temp, 40F defrost)
#!/usr/bin/env python3
import time
import statistics
import automationhat
time.sleep(300)
def comp_on():
automationhat.relay.one.on()
def comp_is_on():
return automationhat.relay.one.is_on()
def comp_off():
automationhat.relay.one.off()
def comp_is_off():
return automationhat.relay.one.is_off()
def fan_on():
automationhat.relay.two.on()
def fan_is_on():
return automationhat.relay.two.is_on()
def fan_off():
automationhat.relay.two.off()
def fan_is_off():
return automationhat.relay.two.is_off()
def checkwatertemp():
time.sleep(1)
automationhat.output.one.on()
time.sleep(1)
wtemp1 = automationhat.analog[0].read()
time.sleep(1)
wtemp2 = automationhat.analog[0].read()
time.sleep(1)
wtemp3 = automationhat.analog[0].read()
time.sleep(1)
wtemp4 = automationhat.analog[0].read()
time.sleep(1)
wtemp5 = automationhat.analog[0].read()
time.sleep(1)
wtemp6 = automationhat.analog[0].read()
time.sleep(1)
wtemp7 = automationhat.analog[0].read()
time.sleep(1)
automationhat.output.one.off()
return statistics.median([wtemp1, wtemp2, wtemp3, wtemp4, wtemp5, wtemp6, wtemp7])
def checkdeftemp():
time.sleep(1)
automationhat.output.two.on()
time.sleep(1)
dtemp1 = automationhat.analog[1].read()
time.sleep(1)
dtemp2 = automationhat.analog[1].read()
time.sleep(1)
dtemp3 = automationhat.analog[1].read()
time.sleep(1)
dtemp4 = automationhat.analog[1].read()
time.sleep(1)
dtemp5 = automationhat.analog[1].read()
time.sleep(1)
dtemp6 = automationhat.analog[1].read()
time.sleep(1)
dtemp7 = automationhat.analog[1].read()
time.sleep(1)
automationhat.output.two.off()
return statistics.median([dtemp1, dtemp2, dtemp3, dtemp4, dtemp5, dtemp6, dtemp7])
def stop():
comp_off()
time.sleep(60)
if comp_is_off():
fan_off()
time.sleep(1200)
def defrost():
comp_off()
time.sleep(60)
if comp_is_off():
fan_on()
time.sleep(1200)
def run():
fan_on()
time.sleep(5)
if checkdeftemp() < 3.9 and fan_is_on():
comp_on()
else:
defrost()
time.sleep(600)
while True:
if checkwatertemp() > 3.2:
run()
else:
stop()
time.sleep(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment