Modify ACMonitor to use 'temp_swing' instead of 'hysteresis' for temperature control logic

This commit is contained in:
Aaron 2025-11-05 13:29:34 -05:00
parent 8ec47a0f66
commit 09295d25ab

View File

@ -106,19 +106,19 @@ class TemperatureMonitor(Monitor):
class ACMonitor(Monitor): class ACMonitor(Monitor):
"""Monitor temperature and control AC automatically.""" """Monitor temperature and control AC automatically."""
def __init__(self, ac_controller, temp_sensor, target_temp=75.0, hysteresis=2.0, interval=30): def __init__(self, ac_controller, temp_sensor, target_temp=75.0, temp_swing=2.0, interval=30):
""" """
ac_controller: ACController instance ac_controller: ACController instance
temp_sensor: TemperatureSensor instance (inside temp) temp_sensor: TemperatureSensor instance (inside temp)
target_temp: Target temperature in °F target_temp: Target temperature in °F
hysteresis: Temperature swing allowed (prevents rapid cycling) temp_swing: Temperature swing allowed (prevents rapid cycling)
interval: Seconds between checks interval: Seconds between checks
""" """
super().__init__(interval) super().__init__(interval)
self.ac = ac_controller self.ac = ac_controller
self.sensor = temp_sensor self.sensor = temp_sensor
self.target_temp = target_temp self.target_temp = target_temp
self.hysteresis = hysteresis self.temp_swing = temp_swing
self.last_notified_state = None self.last_notified_state = None
def run(self): def run(self):
@ -130,25 +130,25 @@ class ACMonitor(Monitor):
# Use first sensor reading (assuming single inside sensor) # Use first sensor reading (assuming single inside sensor)
current_temp = list(temps.values())[0] current_temp = list(temps.values())[0]
# Cooling logic with hysteresis # Cooling logic with temperature swing
# Turn ON if: temp > target + hysteresis # Turn ON if: temp > target + temp_swing
# Turn OFF if: temp < target - hysteresis # Turn OFF if: temp < target - temp_swing
if current_temp > (self.target_temp + self.hysteresis): if current_temp > (self.target_temp + self.temp_swing):
# Too hot, turn AC on # Too hot, turn AC on
if self.ac.turn_on(): if self.ac.turn_on():
if not self.last_notified_state: if not self.last_notified_state:
send_discord_message(f"❄️ AC turned ON - Current: {current_temp:.1f}°F, Target: {self.target_temp:.1f}°F") send_discord_message(f"❄️ AC turned ON - Current: {current_temp:.1f}°F, Target: {self.target_temp:.1f}°F")
self.last_notified_state = True self.last_notified_state = True
elif current_temp < (self.target_temp - self.hysteresis): elif current_temp < (self.target_temp - self.temp_swing):
# Cool enough, turn AC off # Cool enough, turn AC off
if self.ac.turn_off(): if self.ac.turn_off():
if self.last_notified_state: if self.last_notified_state:
send_discord_message(f"✅ AC turned OFF - Current: {current_temp:.1f}°F, Target: {self.target_temp:.1f}°F") send_discord_message(f"✅ AC turned OFF - Current: {current_temp:.1f}°F, Target: {self.target_temp:.1f}°F")
self.last_notified_state = False self.last_notified_state = False
# Else: within hysteresis range, maintain current state # Else: within temp_swing range, maintain current state
class WiFiMonitor(Monitor): class WiFiMonitor(Monitor):
"""Monitor WiFi connection and handle reconnection.""" """Monitor WiFi connection and handle reconnection."""