+ 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
+ tii = st.get_sensor_avg('air/inside-intake')
+ tie = st.get_sensor_avg('air/inside-exhaust')
+ house_hot = st.hysteresis('ac_house_hot', tii, 23.5, 24)
+ outside_hot = st.hysteresis('ac_outside_hot', tie, 24, 25)
+ ac_on = ac_is_on()
+
+ if house_hot > 0 and outside_hot > 0:
+ want_ac = 1
+ else:
+ want_ac = -1
+
+ if not hasattr(st, 'last_ac_change'):
+ st.last_ac_change = st.now
+ need_wait = st.last_ac_change + 300 - st.now # FIXME: Increase
+
+ if need_wait > 0:
+ action = f"wait({need_wait:.0f})"
+ elif ac_on == 0:
+ action = "need-data"
+ elif ac_on != want_ac:
+ action = "change"
+ st.send('air/aircon-remote', 'p')
+ st.last_ac_change = st.now
+ else:
+ action = "none"
+
+ debug("AC: house_hot={} outside_hot={} ac_on={} want_ac={} action={}".format(house_hot, outside_hot, ac_on, want_ac, action))
+
+
+def on_connect(mq, userdata, flags, rc):
+ mq.subscribe("burrow/#")
+
+def on_message(mq, userdata, msg):
+ global st
+ # debug("Message {}: {}".format(msg.topic, msg.payload))
+ st.attrs[msg.topic] = msg.payload.decode('utf-8')