This repository contains the ESPHome configuration for the THC-S RS485 soil sensor, a low-cost Time Domain Reflectometry (TDR) sensor for comprehensive soil monitoring.
Time Domain Reflectometry (TDR) is a sophisticated measurement technique that works similar to radar. Here's how it works:
- The sensor sends an electromagnetic pulse along a probe inserted in the soil
- When this pulse hits changes in the soil (like water content), part of it reflects back
- By measuring these reflections, the sensor can determine soil properties
The THC-S RS485 is a Chinese-manufactured low-cost alternative to expensive TDR sensors:
- Professional TDR sensors like Teros-12 can cost $200-500
- The THC-S typically costs $30-50
- Uses RS485 protocol for communication, which is industrial standard and noise-resistant
The sensor provides comprehensive soil data:
- Measures volumetric water content
- Uses dielectric permittivity of soil
- More accurate than capacitive sensors
- Built-in temperature sensor
- Used for compensating other readings
- Important for plant health monitoring
- Measures soil's ability to conduct electricity
- Indicates nutrient availability
- Temperature compensated for accuracy
- Measures soil acidity/alkalinity
- Important for nutrient availability
- Nitrogen (N): Essential for leaf growth
- Phosphorus (P): Important for root development
- Potassium (K): Key for overall plant health
- More accurate than capacitive sensors
- Less affected by soil salinity
- Provides multiple measurements in one device
- More durable due to better build quality
- RS485 allows longer cable runs (up to 1000m)
- Requires more complex setup than simple sensors
- Needs calibration for best accuracy
- More expensive than basic moisture sensors
- Requires RS485 to TTL converter for microcontroller use
- ESP32-C3 board (or similar ESP32 board)
- THC-S RS485 soil sensor
- TTL to RS485 converter
- Power supply for the sensor (12V recommended)
- Jumper wires or proper cabling for permanent installation
| ESP32-C3 | TTL-RS485 Converter |
|---|---|
| GPIO5 | TX |
| GPIO6 | RX |
| GPIO4 | DE/RE |
| 3.3V | VCC |
| GND | GND |
| TTL-RS485 Converter | THC-S Sensor |
|---|---|
| A+ | A+ |
| B- | B- |
| GND | GND |
| -- | 12V |
- Direct integration with Home Assistant via ESPHome
- Temperature readings in both Celsius and Fahrenheit
- Temperature-compensated EC readings
- Calibrated soil moisture readings using dielectric constant calculations
- Offset-corrected NPK readings
- Multiple WiFi network support with fallback AP
- Over-the-air updates
- Install ESPHome if you haven't already:
pip install esphome-
Copy
soil-sensor.yamlto your ESPHome directory -
Create and update the
secrets.yaml:
wifi_ssid: "Your_SSID"
wifi_password: "Your_Password"
wifi_ssid_2: "Your_Backup_SSID"
wifi_password_2: "Your_Backup_Password"- Flash your ESP32:
esphome run soil-sensor.yamlThe configuration includes several important calibrations derived from testing and documentation:
Uses a quadratic approximation for the apparent dielectric constant:
soil_apparent_dieletric_constant = 1.3088 + (0.1439 * raw_value) + (0.0076 * raw_value * raw_value)
Includes temperature compensation:
soil_ec = 1.93 * raw_ec - 270.8
soil_ec = soil_ec / (1.0 + 0.019 * (temp - 25.0))
Based on testing with known solutions:
- Nitrogen: -27 offset
- Phosphorus: -109 offset
- Potassium: -102 offset
Common issues and solutions:
-
No readings from sensor:
- Check wiring, especially A+ and B- connections
- Verify 12V power supply
- Confirm RS485 converter is working (LED indicators)
-
Erratic readings:
- Check cable length and quality
- Verify power supply stability
- Ensure proper grounding
-
Connection issues:
- Verify WiFi credentials
- Check ESP32 antenna orientation
- Consider signal strength and distance to router
Feel free to submit issues and pull requests if you have improvements or fixes to suggest. Please include:
- Clear description of changes
- Test results if applicable
- Any relevant documentation updates
This configuration is based on research and documentation from:
- Original Arduino code by Kromadg
- ESPHome community contributions
- Personal testing and calibration
MIT License - feel free to use and modify as needed. See LICENSE for more details.