ESPHome external component for the Chirp/Catnip I2C capacitive soil moisture sensor.
Based on the sensor available at: https://github.com/Miceuz/i2c-moisture-sensor
This component provides the following sensor readings:
- Capacitance - Raw capacitance value from the sensor
- Temperature - Soil temperature in Celsius
- Light - Ambient light level (higher values = darker)
Note: This component exports raw sensor values. To calculate moisture percentage, use Home Assistant template sensors with your own calibration values.
- I2C Address: 0x20 (default, configurable)
- Supply Voltage: 3.3V - 5V
- Interface: I2C
- Measurements: Capacitance, Temperature, Light
Connect the sensor to your ESP device:
| Sensor Pin | ESP Pin |
|---|---|
| VCC | 3.3V or 5V |
| GND | GND |
| SDA | SDA (GPIO21 on ESP32) |
| SCL | SCL (GPIO22 on ESP32) |
Clone this repository or copy the components/catnip_soil_sensor directory to your ESPHome configuration directory.
your-esphome-config/
├── components/
│ └── catnip_soil_sensor/
│ ├── __init__.py
│ ├── sensor.py
│ ├── catnip_soil_sensor.h
│ └── catnip_soil_sensor.cpp
└── your-device.yaml
Add the external component and sensor configuration to your ESPHome YAML file:
# Enable I2C
i2c:
sda: GPIO21
scl: GPIO22
scan: true
# Load external component
external_components:
- source:
type: local
path: components
# Configure sensor
sensor:
- platform: catnip_soil_sensor
address: 0x20
update_interval: 60s
capacitance:
name: "Soil Capacitance"
temperature:
name: "Soil Temperature"
light:
name: "Soil Light Level"- address (Optional, int): I2C address of the sensor. Defaults to
0x20. - update_interval (Optional, Time): Update interval for sensor readings. Defaults to
60s.
All sensor outputs are optional. Configure only the sensors you need.
-
capacitance (Optional): Raw capacitance value from the sensor.
- All options from Sensor
-
temperature (Optional): Soil temperature in Celsius.
- All options from Sensor
-
light (Optional): Ambient light level (higher values indicate darker conditions).
- All options from Sensor
This component exports raw capacitance values. To calculate moisture percentage, you can use Home Assistant template sensors with your own calibration values.
-
Measure Dry Value:
- Leave the sensor in open air
- Read the
capacitancesensor value - Note this as your dry value (typically around 290)
-
Measure Wet Value:
- Submerge the sensor in water (only the sensing area, not electronics!)
- Read the
capacitancesensor value - Note this as your wet value (typically around 600-650)
-
Create Template Sensor in Home Assistant:
template: - sensor: - name: "Soil Moisture Percentage" unit_of_measurement: "%" state: > {% set dry_value = 290 %} {% set wet_value = 650 %} {% set raw = states('sensor.soil_capacitance') | float %} {% set moisture = ((raw - dry_value) / (wet_value - dry_value) * 100) | round(1) %} {{ [0, [moisture, 100] | min] | max }}
See example.yaml for a complete configuration example.
The component communicates with the following sensor registers:
| Register | Function | Data Type |
|---|---|---|
| 0x00 | Get Capacitance | 16-bit (MSB first) |
| 0x05 | Get Temperature | 16-bit (tenths of °C) |
| 0x03 | Trigger Light Measurement | Write only |
| 0x04 | Get Light Value | 16-bit (MSB first) |
| 0x07 | Get Firmware Version | 8-bit |
The component performs measurements in the following order:
- Read capacitance value
- Read temperature
- Trigger light measurement
- Wait ~1.5 seconds
- Read light value (on next update cycle)
If you see "Communication with Catnip Soil Sensor failed!" in the logs:
- Check wiring connections
- Verify I2C pins are correct for your ESP board
- Run I2C scan to detect devices: set
scan: truein i2c configuration - Check if sensor is powered (3.3V or 5V)
- Temperature seems wrong: Sensor reports in tenths of Celsius (252 = 25.2°C)
- Light values noisy: This is expected; the light sensor is less precise than other readings
- Capacitance readings seem off: Use the calibration method above to determine your sensor's specific dry/wet values
This component is provided as-is for use with ESPHome.
- Sensor hardware: Miceuz/i2c-moisture-sensor
- ESPHome: esphome.io