Compare commits

...

3 Commits

View File

@@ -1,16 +1,20 @@
# 🌱 Auto Garden # 🌡️ Raspberry Pi Pico Thermostat
> **Forked from [Auto-Garden](https://gitea.rcs1.top/sickprodigy/Auto-Garden); [Commit c8102e62ee](https://gitea.rcs1.top/sickprodigy/Auto-Garden/commit/c8102e62ee8c3b8cf60a57654bab7703df2f27af)**
> Smart thermostat and climate control system using Raspberry Pi Pico W with web interface, scheduling, and relay control
> Automated climate control system using Raspberry Pi Pico W with web interface and scheduling
## Recent Updates ## Recent Updates
- 🆕 **Immediate schedule application:** When resuming scheduling from hold mode, the system now instantly applies the current schedule targets (no delay). - 🆕 **Immediate schedule application:** When resuming scheduling from hold mode, the thermostat instantly applies the current schedule targets (no delay).
- 🆕 **Aggressive memory management:** Garbage collection runs every 5 seconds for improved reliability. - 🆕 **Aggressive memory management:** Garbage collection runs every 5 seconds for improved reliability.
- 🆕 **Manual hold settings:** `ac_target` and `heater_target` in `config.json` now only store your last manual hold settings, not schedule targets. - 🆕 **Manual hold settings:** `ac_target` and `heater_target` in `config.json` now only store your last manual hold settings, not schedule targets.
- 🆕 **NTP sync optimization:** NTP modules are loaded only when needed, saving RAM. - 🆕 **NTP sync optimization:** NTP modules are loaded only when needed, saving RAM.
- 🆕 **Temperature validation:** Impossible sensor readings are ignored for safety. - 🆕 **Temperature validation:** Impossible sensor readings are ignored for safety.
- 🆕 **Improved config persistence:** All changes are saved and reloaded immediately. - 🆕 **Improved config persistence:** All changes are saved and reloaded immediately.
## Features ## Features
- **Core Features** - **Core Features**
@@ -24,9 +28,8 @@
- ✅ Graceful shutdown with Ctrl+C - ✅ Graceful shutdown with Ctrl+C
-**Aggressive garbage collection for stability** -**Aggressive garbage collection for stability**
- **Climate Control** - **Thermostat Control**
- ✅ Automated AC control with temperature swing logic - ✅ Automated AC and heater control with temperature swing logic
- ✅ Automated heater control with separate swing settings
- ✅ Short-cycle protection for both AC and heater - ✅ Short-cycle protection for both AC and heater
- ✅ Dual relay control via opto-coupler for 110V AC - ✅ Dual relay control via opto-coupler for 110V AC
- ✅ Mutual exclusion (AC and heater never run simultaneously) - ✅ Mutual exclusion (AC and heater never run simultaneously)
@@ -53,6 +56,7 @@
- ✅ Auto-refresh dashboard (30 seconds) - ✅ Auto-refresh dashboard (30 seconds)
-**Settings and schedule changes are reflected instantly** -**Settings and schedule changes are reflected instantly**
## Configuration Notes ## Configuration Notes
- **AC/Heater target settings:** - **AC/Heater target settings:**
@@ -61,7 +65,7 @@
- This ensures the config file always reflects the current operating temperatures, whether in hold mode or schedule mode. - This ensures the config file always reflects the current operating temperatures, whether in hold mode or schedule mode.
- **Immediate schedule application:** - **Immediate schedule application:**
- When you click "Resume Scheduling," the system applies the current schedule targets instantly, so the dashboard updates without delay. - When you click "Resume Scheduling," the thermostat applies the current schedule targets instantly, so the dashboard updates without delay.
- **Memory management:** - **Memory management:**
- Garbage collection runs every 5 seconds to prevent memory fragmentation and crashes. - Garbage collection runs every 5 seconds to prevent memory fragmentation and crashes.
@@ -69,6 +73,7 @@
- **Sensor validation:** - **Sensor validation:**
- Temperatures outside the range -50°F to 150°F are ignored to prevent false readings. - Temperatures outside the range -50°F to 150°F are ignored to prevent false readings.
## Quick Start ## Quick Start
### 1. Hardware Setup ### 1. Hardware Setup
@@ -146,56 +151,28 @@ RUN pin → Button → GND
### 4. Configuration ### 4. Configuration
**Create `secrets.py`** (copy from `secrets.example.py`): **Edit `config.json`** (created automatically on first boot, or edit manually):
```python ```json
secrets = {
'ssid': 'YOUR_WIFI_NAME',
'password': 'YOUR_WIFI_PASSWORD',
'discord_webhook_url': 'https://discord.com/api/webhooks/...',
'discord_alert_webhook_url': 'https://discord.com/api/webhooks/...',
}
```
**Sensor Configuration in `main.py`:**
```python
# Sensor configuration
SENSOR_CONFIG = {
'inside': {
'pin': 10,
'label': 'Inside',
'alert_high': 80.0,
'alert_low': 70.0
},
'outside': {
'pin': 11,
'label': 'Outside',
'alert_high': 85.0,
'alert_low': 68.0
}
}
```
**Default Climate Settings (auto-saved to config.json):**
```python
# Default config (created on first boot)
{ {
"ac_target": 77.0, # AC target temperature (°F) "ssid": "YOUR_WIFI_NAME",
"ac_swing": 1.0, # AC turns on at 78°F, off at 76°F "password": "YOUR_WIFI_PASSWORD",
"heater_target": 72.0, # Heater target temperature (°F) "discord_webhook_url": "https://discord.com/api/webhooks/...",
"heater_swing": 2.0, # Heater turns on at 70°F, off at 74°F "discord_alert_webhook_url": "https://discord.com/api/webhooks/...",
"temp_hold_duration": 3600, # Temporary hold lasts 1 hour (3600 seconds) "ac_target": 77.0,
"schedule_enabled": true, # Schedules active by default "ac_swing": 1.0,
"schedules": [ # 4 time-based schedules "heater_target": 72.0,
"heater_swing": 2.0,
"temp_hold_duration": 3600,
"schedule_enabled": true,
"schedules": [
{ {
"time": "06:00", "time": "06:00",
"name": "Morning", "name": "Morning",
"ac_target": 75.0, "ac_target": 75.0,
"heater_target": 72.0 "heater_target": 72.0
}, }
# ... 3 more schedules // ... 3 more schedules
] ]
} }
``` ```
@@ -204,12 +181,11 @@ All settings can be changed via the web interface and persist through reboots.
### 5. Upload & Run ### 5. Upload & Run
Upload all files to your Pico: **Upload all files to your Pico:**
```text ```text
/ /
├── main.py ├── main.py
├── secrets.py
├── config.json # Auto-generated on first boot ├── config.json # Auto-generated on first boot
└── scripts/ └── scripts/
├── air_conditioning.py # AC/Heater controller classes ├── air_conditioning.py # AC/Heater controller classes
@@ -223,14 +199,13 @@ Upload all files to your Pico:
The Pico will auto-start `main.py` on boot and be accessible at **<http://192.168.x.x>** The Pico will auto-start `main.py` on boot and be accessible at **<http://192.168.x.x>**
## Project Structure ## Project Structure
```text ```text
Auto-Garden/ Raspberry-Pi-Pico-Thermostat/
├── main.py # Entry point, configuration, system initialization ├── main.py # Entry point, configuration, system initialization
├── secrets.py # WiFi & Discord credentials (gitignored) ├── config.json # Persistent configuration and credentials (auto-generated)
├── secrets.example.py # Template for secrets.py
├── config.json # Persistent configuration (auto-generated)
└── scripts/ └── scripts/
├── air_conditioning.py # AC & Heater controllers with short-cycle protection ├── air_conditioning.py # AC & Heater controllers with short-cycle protection
├── discord_webhook.py # Discord notification handling ├── discord_webhook.py # Discord notification handling
@@ -241,6 +216,7 @@ Auto-Garden/
└── web_server.py # Web interface for monitoring and control └── web_server.py # Web interface for monitoring and control
``` ```
## How It Works ## How It Works
### Temperature Monitoring ### Temperature Monitoring
@@ -354,6 +330,7 @@ Access at **<http://192.168.x.x>**
- **Auto-reconnect:** Attempts every 60 seconds if disconnected - **Auto-reconnect:** Attempts every 60 seconds if disconnected
- **Static IP:** Always accessible at <http://192.168.x.x> - **Static IP:** Always accessible at <http://192.168.x.x>
## Temperature Logs ## Temperature Logs
Logs are saved to `/temp_logs.csv` on the Pico: Logs are saved to `/temp_logs.csv` on the Pico:
@@ -365,6 +342,7 @@ Logs are saved to `/temp_logs.csv` on the Pico:
Format: `timestamp,location,sensor_id,temperature_f` Format: `timestamp,location,sensor_id,temperature_f`
## Customization ## Customization
### Via Web Interface (Recommended) ### Via Web Interface (Recommended)
@@ -405,6 +383,7 @@ check_interval=10 # Temperature check frequency
report_interval=30 # Discord report frequency report_interval=30 # Discord report frequency
``` ```
## Safety Notes ## Safety Notes
⚠️ **High Voltage Warning:** ⚠️ **High Voltage Warning:**
@@ -429,6 +408,7 @@ report_interval=30 # Discord report frequency
- Hold modes reset on reboot (schedules always resume) - Hold modes reset on reboot (schedules always resume)
- Static IP ensures web interface always accessible - Static IP ensures web interface always accessible
## Troubleshooting ## Troubleshooting
**Web interface not loading:** **Web interface not loading:**
@@ -447,14 +427,14 @@ report_interval=30 # Discord report frequency
**WiFi not connecting:** **WiFi not connecting:**
- Verify SSID/password in `secrets.py` - Verify SSID/password in `config.json`
- Check 2.4GHz WiFi (Pico W doesn't support 5GHz) - Check 2.4GHz WiFi (Pico W doesn't support 5GHz)
- LED should be solid when connected - LED should be solid when connected
- Check serial console for connection status - Check serial console for connection status
**Discord messages not sending:** **Discord messages not sending:**
- Verify webhook URLs in `secrets.py` - Verify webhook URLs in `config.json`
- Test webhooks with curl/Postman first - Test webhooks with curl/Postman first
- Check Pico has internet access (ping test) - Check Pico has internet access (ping test)
- Look for error messages in serial console - Look for error messages in serial console
@@ -501,14 +481,17 @@ report_interval=30 # Discord report frequency
- Ensure config.json has write permissions - Ensure config.json has write permissions
- Try manual edit of config.json and reboot - Try manual edit of config.json and reboot
## Contributing ## Contributing
Feel free to open issues or submit pull requests for improvements! Feel free to open issues or submit pull requests for improvements!
## License ## License
MIT License - See LICENSE file for details MIT License - See LICENSE file for details
## Resources ## Resources
- [Raspberry Pi Pico W Documentation](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html) - [Raspberry Pi Pico W Documentation](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html)