X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=auto%2Fburrow-auto;h=b876223dae335efe839a193bb07c71600fa0d8db;hb=refs%2Fheads%2Fmaster;hp=dbcd822e1fea00d35b25dc27c5c834c96f365064;hpb=38b7ba69dd4b5d0bc8f9c8b4468f2180e319cb51;p=home-hw.git diff --git a/auto/burrow-auto b/auto/burrow-auto index dbcd822..b876223 100755 --- a/auto/burrow-auto +++ b/auto/burrow-auto @@ -2,16 +2,35 @@ from collections import deque import getopt +import os import paho.mqtt.client as mqtt import sys import time debug_mode = False +log_name = '/run/burrow-auto' +log_file = None indent = 0 def debug(msg): if debug_mode: print(("\t" * indent) + msg, file=sys.stderr) + elif log_file is not None: + print(("\t" * indent) + msg, file=log_file) + +def debug_open(): + if not debug_mode: + global log_file + log_file = open(log_name + '.new', 'w') + +def debug_close(): + if debug_mode: + debug("=" * 80) + else: + global log_file + log_file.close() + log_file = None + os.rename(log_name + '.new', log_name) def diff(x, y): if x is None or y is None: @@ -135,7 +154,9 @@ def auto_loft_fan(): lt = st.get_sensor_avg("temp/loft") out = st.get_sensor_avg('air/outside-intake') - if lt is None or out is None: + if False and st.hour in range(21, 24) or st.hour in range(6, 10): + fs = 0 + elif lt is None or out is None: fs = 0 elif st.hysteresis('lf_out_cold', out, 5, 6) < 0: fs = 0 @@ -146,11 +167,16 @@ def auto_loft_fan(): fs = 0 elif ac_is_on() > 0: fs = 3 - elif st.hysteresis('lf_loft_hot', lt, 23, 24) > 0: + elif st.hysteresis('lf_loft_hot', lt, 25, 26) > 0: if st.hysteresis('lf_loft_hotter_than_out', lt, out - 1, out + 1) > 0: fs = 3 else: fs = 1 + else: + if st.min in range(10, 15): + fs = 2 + else: + fs = 0 st.set("loft/fan", fs) @@ -214,6 +240,11 @@ def auto_air(): debug("Air: house_warm={} house_hot={} ac_on={} outside_warmer={} mixed_warmer={}".format(house_warm, house_hot, ac_on, outside_warmer, mixed_warmer)) + if ac_on != 0: + st.set("air/ac-on", "{} {}".format(1 if ac_on > 0 else 0, int(st.now))) + else: + st.set("air/ac-on", "") + def auto_aircon(): global st @@ -279,6 +310,7 @@ checks = [ ] while True: + debug_open() st.update() debug("averages") @@ -298,5 +330,6 @@ while True: indent -= 1 else: debug("{} DISABLED".format(name)) - debug("=" * 80) + + debug_close() time.sleep(10)