|
| 1 | +# Temperature and Humidity Sensor Example |
| 2 | + |
| 3 | +Real-time reporting of soil moisture data to Home Assistant. Supports real soil moisture sensors (such as Seeed Studio soil sensors) and simulated data. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Soil Moisture Sensor** (displayed in %) |
| 8 | +- **Configurable Update Interval** (adjust data reporting frequency as needed) |
| 9 | +- **Optional Real Soil Moisture Sensor Support** (Capacitive/Resistive) |
| 10 | +- **Simulated Data Mode** (for hardware-free testing scenarios) |
| 11 | +- **WiFi Provisioning**: Web-based WiFi configuration (no hard-coded credentials required) |
| 12 | + |
| 13 | +## Hardware Requirements |
| 14 | + |
| 15 | +- XIAO ESP32-C3/C5/C6/S3 or other ESP32 development boards |
| 16 | +- Soil Moisture Sensor (optional - simulated data can be used, Seeed Studio soil sensor recommended) |
| 17 | + |
| 18 | +> **Note**: XIAO ESP32-C5 supports dual-band WiFi (2.4GHz and 5GHz) |
| 19 | + |
| 20 | +### Sensor Pin Connections |
| 21 | + |
| 22 | +| Function | Pin | Description | |
| 23 | +| :--- | :--- | :--- | |
| 24 | +| Excitation Signal (EX) | **D3** | Sends excitation square wave signal | |
| 25 | +| Analog Signal (SIG) | **D1** | Reads soil capacitance response voltage | |
| 26 | +| VCC | 3.3V | Power supply (Do not connect to 5V) | |
| 27 | +| GND | GND | Ground | |
| 28 | + |
| 29 | +### LED Indicator Connections (Common Cathode Connection) |
| 30 | + |
| 31 | +| LED Color | Pin | Status Definition | |
| 32 | +| :--- | :--- | :--- | |
| 33 | +| Green | **D8** | Moisture > 60% (Wet) | |
| 34 | +| Yellow | **D10** | Moisture 30%-60% (Moderate) | |
| 35 | +| Red | **D9** | Moisture < 30% (Dry) | |
| 36 | + |
| 37 | +## Software Dependencies |
| 38 | + |
| 39 | +### Required Libraries |
| 40 | + |
| 41 | +Install via Arduino Library Manager: |
| 42 | + |
| 43 | +| Library Name | Author | Description | |
| 44 | +| :--- | :--- | :--- | |
| 45 | +| **ArduinoJson** | Benoit Blanchon | JSON parsing | |
| 46 | +| **WebSockets** | Markus Sattler | WebSocket communication | |
| 47 | + |
| 48 | +### SeeedHADiscovery Library |
| 49 | + |
| 50 | +Manually install from [GitHub](https://github.com/limengdu/SeeedHADiscovery). |
| 51 | + |
| 52 | +## Quick Start |
| 53 | + |
| 54 | +### 1. WiFi Configuration |
| 55 | + |
| 56 | +**Method A: WiFi Provisioning (Recommended)** |
| 57 | + |
| 58 | +WiFi provisioning is enabled by default. Upon first startup: |
| 59 | + |
| 60 | +1. Device creates AP hotspot: `Seeed_TempHum_AP` |
| 61 | +2. Connect your phone/computer to this AP |
| 62 | +3. Browser opens automatically, or manually visit `http://192.168.4.1` |
| 63 | +4. Select your WiFi network and enter password |
| 64 | +5. Device restarts and connects to your WiFi |
| 65 | + |
| 66 | +**Method B: Hard-coded Credentials** |
| 67 | + |
| 68 | +To use hard-coded credentials: |
| 69 | + |
| 70 | +```cpp |
| 71 | +#define USE_WIFI_PROVISIONING false |
| 72 | +const char* WIFI_SSID = "YourWiFiName"; |
| 73 | +const char* WIFI_PASSWORD = "YourWiFiPassword"; |
| 74 | +``` |
| 75 | +
|
| 76 | +### 2. Configure Update Interval |
| 77 | +
|
| 78 | +```cpp |
| 79 | +const unsigned long UPDATE_INTERVAL = 5000; // 5 seconds |
| 80 | +``` |
| 81 | + |
| 82 | +### 3. ESP32-C5 5GHz WiFi(Optional) |
| 83 | + |
| 84 | +Force specific WiFi band on ESP32-C5: |
| 85 | +```cpp |
| 86 | +#define WIFI_BAND_MODE WIFI_BAND_MODE_5G_ONLY // 或 WIFI_BAND_MODE_2G_ONLY |
| 87 | +``` |
| 88 | +
|
| 89 | +### 4. Upload and Connect |
| 90 | +
|
| 91 | +1. Select board: XIAO ESP32C6 (or your board) |
| 92 | +2. Upload program |
| 93 | +3. Open serial monitor (115200 baud) |
| 94 | +4. Add device in Home Assistant |
| 95 | +
|
| 96 | +## Home Assistant Setup |
| 97 | +
|
| 98 | +1. Go to Settings → Devices & Services → Add Integration |
| 99 | +2. Search for Seeed HA Discovery |
| 100 | +3. Enter device IP address |
| 101 | +4. one sensor will appear: |
| 102 | + - Humidity |
| 103 | +
|
| 104 | +## Created Entities |
| 105 | +
|
| 106 | +| Entity | Type | Unit | Precision | |
| 107 | +| :------------ | :----- | :--- | :-------- | |
| 108 | +| Soil Moisture | Sensor | % | Integer | |
| 109 | +
|
| 110 | +## Simulated Data Mode |
| 111 | +
|
| 112 | +When USE_SOIL_SENSOR is not defined, the device will automatically enable simulated data mode: |
| 113 | +Soil Moisture: Fluctuates between 0-100% (simulating the full range from dry to over-wet) |
| 114 | +This mode is suitable for scenarios without real sensors, facilitating code testing and Home Assistant integration debugging. |
| 115 | +
|
| 116 | +## Device Status Page |
| 117 | +
|
| 118 | +Access device status: http://<DeviceIP>/ |
| 119 | +
|
| 120 | +## Troubleshooting |
| 121 | +
|
| 122 | +### Values Not Updating in HA |
| 123 | +- Check WiFi connection |
| 124 | +- Verify device is connected to HA |
| 125 | +- Check error messages in serial monitor |
| 126 | +
|
| 127 | +### Cannot Access Provisioning Page |
| 128 | +- Ensure you are connected to the device's AP |
| 129 | +- Try manually visiting http://192.168.4.1 |
| 130 | +
|
| 131 | +## License |
| 132 | +
|
| 133 | +Part of the SeeedHADiscovery library. |
0 commit comments