Compare commits

...

3 Commits

3 changed files with 90 additions and 15 deletions

View File

@ -146,10 +146,6 @@ class TemperatureMonitor(Monitor):
def _log_temperature(self, temp):
"""Log temperature to CSV file."""
try:
# Get sensor ID
sensor_ids = self.sensor.get_sensor_ids()
sensor_id = sensor_ids[0] if sensor_ids else "unknown"
# Get timestamp
t = time.localtime()
timestamp = "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(
@ -158,8 +154,8 @@ class TemperatureMonitor(Monitor):
# Append to log file
with open(self.log_file, 'a') as f:
f.write("{},{},{},{:.2f}\n".format(
timestamp, self.label, sensor_id, temp
f.write("{},{},{:.2f}\n".format(
timestamp, self.label, temp
))
except Exception as e:
print("Error logging temperature: {}".format(e))

View File

@ -47,6 +47,7 @@ class ScheduleMonitor:
def _find_active_schedule(self):
"""Find which schedule should be active right now."""
if not self.config.get('schedule_enabled', False):
# Schedule is disabled (HOLD mode)
return None
schedules = self.config.get('schedules', [])

View File

@ -97,6 +97,29 @@ class TempWebServer:
# Load current config
config = self._load_config()
# Check if this is a "Resume Schedule" request
if params.get('resume_schedule') == 'true':
config['schedule_enabled'] = True
# Save to file
if self._save_config_to_file(config):
print("▶️ Schedule resumed")
# Reload schedule monitor
if schedule_monitor:
schedule_monitor.reload_config(config)
# Send Discord notification
try:
from scripts.discord_webhook import send_discord_message
message = "▶️ Schedule resumed - Automatic temperature control active"
send_discord_message(message)
except:
pass
return self._get_status_page(sensors, ac_monitor, heater_monitor, show_success=True)
# Otherwise, handle normal schedule update
# Update schedule enabled status
config['schedule_enabled'] = params.get('schedule_enabled') == 'on'
@ -144,7 +167,7 @@ class TempWebServer:
sys.print_exception(e)
return self._get_status_page(sensors, ac_monitor, heater_monitor, show_success=True)
def _handle_update(self, request, sensors, ac_monitor, heater_monitor, schedule_monitor):
"""Handle form submission and update settings."""
try:
@ -181,6 +204,15 @@ class TempWebServer:
config['heater_swing'] = params['heater_swing']
print("Heater swing updated to {}°F".format(params['heater_swing']))
# **NEW: Disable scheduling and enter HOLD mode**
if config.get('schedule_enabled'):
config['schedule_enabled'] = False
print("⏸️ Schedule disabled - entering HOLD mode")
# Reload schedule monitor to disable it
if schedule_monitor:
schedule_monitor.reload_config(config)
# Save settings to file
if self._save_config_to_file(config):
print("Settings persisted to disk")
@ -193,7 +225,7 @@ class TempWebServer:
heater_target_str = str(params.get('heater_target', 'N/A'))
heater_swing_str = str(params.get('heater_swing', 'N/A'))
message = "Settings Updated - AC: {}F +/- {}F | Heater: {}F +/- {}F".format(
message = "⏸️ HOLD Mode - Manual override: AC: {}F +/- {}F | Heater: {}F +/- {}F (Schedule disabled)".format(
ac_target_str, ac_swing_str, heater_target_str, heater_swing_str
)
send_discord_message(message)
@ -206,7 +238,7 @@ class TempWebServer:
sys.print_exception(e)
return self._get_status_page(sensors, ac_monitor, heater_monitor, show_success=True)
def _get_status_page(self, sensors, ac_monitor, heater_monitor, show_success=False):
"""Generate HTML status page."""
try:
@ -231,10 +263,22 @@ class TempWebServer:
# Load config
config = self._load_config()
# **NEW: Check if in HOLD mode**
is_hold_mode = not config.get('schedule_enabled', False) and len(config.get('schedules', [])) > 0
# Build schedule display
schedule_status = "ENABLED" if config.get('schedule_enabled') else "DISABLED"
schedule_color = "#2ecc71" if config.get('schedule_enabled') else "#95a5a6"
schedule_icon = "" if config.get('schedule_enabled') else "⚠️"
if is_hold_mode:
schedule_status = "HOLD MODE"
schedule_color = "#f39c12" # Orange color for hold
schedule_icon = "⏸️"
elif config.get('schedule_enabled'):
schedule_status = "ENABLED"
schedule_color = "#2ecc71"
schedule_icon = ""
else:
schedule_status = "DISABLED"
schedule_color = "#95a5a6"
schedule_icon = "⚠️"
# Build schedule cards
schedule_cards = ""
@ -276,6 +320,15 @@ class TempWebServer:
inside_temp_str = "{:.1f}".format(inside_temp) if isinstance(inside_temp, float) else str(inside_temp)
outside_temp_str = "{:.1f}".format(outside_temp) if isinstance(outside_temp, float) else str(outside_temp)
# **NEW: Add HOLD mode banner**
hold_banner = ""
if is_hold_mode:
hold_banner = """
<div style="background: linear-gradient(135deg, #f39c12, #e67e22); color: white; padding: 15px; border-radius: 10px; text-align: center; font-weight: bold; margin-bottom: 20px; box-shadow: 0 4px 8px rgba(0,0,0,0.2); animation: fadeIn 0.5s;">
HOLD MODE ACTIVE - Manual settings in use (Schedule paused)
</div>
"""
html = """
<!DOCTYPE html>
<html>
@ -483,6 +536,7 @@ class TempWebServer:
<body>
<h1>🌱 Auto Garden Dashboard</h1>
{hold_banner}
{success_message}
<div class="temp-grid">
@ -569,6 +623,7 @@ class TempWebServer:
</body>
</html>
""".format(
hold_banner=hold_banner,
success_message=success_html,
inside_temp=inside_temp_str,
outside_temp=outside_temp_str,
@ -605,8 +660,26 @@ class TempWebServer:
enabled_checked = 'checked' if config.get('schedule_enabled') else ''
form = """
<form method="POST" action="/schedule" class="controls" style="margin-top: 20px;">
# Check if in HOLD mode
is_hold_mode = not config.get('schedule_enabled', False) and len(config.get('schedules', [])) > 0
# Build header with toggle or resume button
if is_hold_mode:
# Show Resume Schedule button instead of toggle
header = """
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3 style="color: #34495e; margin: 0;"> Edit Schedules</h3>
<form method="POST" action="/schedule" style="margin: 0;">
<input type="hidden" name="resume_schedule" value="true">
<button type="submit" style="padding: 10px 20px; background: linear-gradient(135deg, #2ecc71, #27ae60); color: white; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: transform 0.2s;">
Resume Schedule
</button>
</form>
</div>
"""
else:
# Show toggle switch for enable/disable
header = """
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3 style="color: #34495e; margin: 0;"> Edit Schedules</h3>
<label class="toggle-switch">
@ -614,7 +687,12 @@ class TempWebServer:
<span class="slider"></span>
</label>
</div>
""".format(enabled_checked=enabled_checked)
""".format(enabled_checked=enabled_checked)
form = """
<form method="POST" action="/schedule" class="controls" style="margin-top: 20px;">
{header}
""".format(header=header)
for i, schedule in enumerate(schedules[:4]):
form += """