56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
|
import os
|
||
|
import logging
|
||
|
logging.basicConfig(
|
||
|
format='[%(asctime)s] %(levelname)s %(module)s/%(funcName)s - %(message)s',
|
||
|
level=logging.DEBUG if os.environ.get('DEBUG') else logging.INFO)
|
||
|
#logging.getLogger('aiohttp').setLevel(logging.DEBUG if os.environ.get('DEBUG') else logging.WARNING)
|
||
|
|
||
|
import asyncio
|
||
|
from statistics import mean
|
||
|
|
||
|
import w1therm
|
||
|
import relays
|
||
|
import data
|
||
|
|
||
|
HI_SETPOINT = 40.0
|
||
|
LO_SETPOINT = 30.0
|
||
|
|
||
|
FAN_RELAY = relays.RELAY3
|
||
|
|
||
|
async def main():
|
||
|
relays.init_relays()
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
temps = await w1therm.get_temperatures()
|
||
|
if len(temps) != len(data.PROBES):
|
||
|
raise
|
||
|
except:
|
||
|
logging.error('Problem reading temperature probes! Setting fan on and sleeping.')
|
||
|
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
||
|
await asyncio.sleep(60)
|
||
|
continue
|
||
|
|
||
|
temperature_log = []
|
||
|
for id_, temp in temps.items():
|
||
|
temperature_log.append('{}: {} C'.format(data.PROBES[id_], temp))
|
||
|
logging.info('Temperature probe ' + ', '.join(temperature_log))
|
||
|
|
||
|
temperature_list = list(temps.values())
|
||
|
temperature_mean = mean(temperature_list)
|
||
|
|
||
|
if temperature_mean > HI_SETPOINT:
|
||
|
logging.info('Turning fan on')
|
||
|
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
||
|
elif temperature_mean < LO_SETPOINT:
|
||
|
logging.info('Turning fan off')
|
||
|
relays.set_relay(FAN_RELAY, relays.RELAY_OFF)
|
||
|
|
||
|
await asyncio.sleep(10)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
loop = asyncio.get_event_loop()
|
||
|
loop.run_until_complete(main())
|
||
|
loop.close()
|
||
|
|