Wi-fi Soil Moisture Sensor with ESPHome

preview_player
Показать описание
A quick and easy solution to monitoring plant soil moisture. Integrates into Home Assistant with ESPHome.

Board: Seeed Xiao ESP32-C3, I use a capacitive moisture sensor and 1200mAh battery available on Amazon.

YAML (pay attention to the greater than/less than notes below):
esphome:
name: wifi-moisture-sensor
friendly_name: WiFi Moisture Sensor
on_boot:
then:
on_shutdown:
then:

esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
encryption:
key: "your_key"

ota:
password: "your_pwd"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
power_save_mode: LIGHT
manual_ip:

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "your_fallback"
password: "fallback_pwd"

captive_portal:

sensor:
- platform: adc
pin: 3
name: "Soil Moisture"
unit_of_measurement: "%"
device_class: MOISTURE
update_interval: 2s
attenuation: 11db #required
filters:
- calibrate_linear: #set your own values here
- 1.45 -> 100.00 #replace ">" with greater than symbol (YT doesn't allow angled brackets)
- 2.821 -> 0.00
- lambda: |
if (x < 0) return 0; #replace "<" with less than symbol (YT doesn't allow angled brackets)
else if (x > 100) return 100;
else return (x);
accuracy_decimals: 0

- platform: adc
pin: 4
allow_other_uses: True
name: "Battery Life"
unit_of_measurement: "%"
device_class: BATTERY
update_interval: 2s
attenuation: 11db #required
filters:
- multiply: 2.0
- calibrate_polynomial: #set your own values here
degree: 4
datapoints:
# Map 0.0 (from sensor) to 0.0 (true value)
- 3.4 -> 0.0
- 3.6 -> 8.43
- 3.81 -> 50.06
- 3.86 -> 57.63
- 3.92 -> 72.56
- 3.96 -> 90.96
- 4.05 -> 100
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);

- platform: adc
pin: 4
allow_other_uses: True
name: "Battery Voltage"
update_interval: 2s
attenuation: 11db #required
filters:
- multiply: 2.0

- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 2s

switch:
- platform: gpio
pin: GPIO10
id: sensor_power
internal: true

deep_sleep:
run_duration: 10s
sleep_duration: '5:59:50'

=== Timestamps ===
0:00 Introduction
0:44 Commercial Products... Fail
1:10 DIY Solution
3:54 YAML Configuration Overview
7:25 Conclusion
Рекомендации по теме
Комментарии
Автор

For a future video you may want to try the Sonoff "Zigbee Smart Water Valve". It also uses ESPhome and if you use MQTT you can monitor the water usage, set it by amount of water, time and with some coding soil moisture, battery, schedule... I just installed mine on my wife's garden/rain barrel/pond pump and works great. Currently I just set it to turn on 2X a day for 30 seconds (16 ounces each run). Next is MQTT and soil moisture checking, then rain Great video you did

donaldhoudek
Автор

Thank you so much for explaining that. I had everything working except that. Great project. Looking forward to making a few.

MattOmondPrintbotOMO
Автор

Amazing work! I'm making my own and this saved me a lot of hassle

UltraEd
Автор

Thank you for sharing your project, most interesting.

MrBobWareham
Автор

Amazing video that has covered a lot of things i wanted to grasp. I am new to this so i hope i am not asking the obvious
For the voltage divider you used identical resistors which is why you used a multiplier of two in the code correct? could you have used different value resistors to get 3.3v and not used the multiplier? any benefit of one over the other and what value resistor did you use?
also the polynomial is to approximate the discharge curve of the LI battery correct?
again, great video

yromanos
Автор

I pasted your yaml code into the code for an ESP-D1 on Home Assistant and did a search and replace of the &gt and &lt markers as directed. When I run the "validate" on the code, I get the following error message:
INFO ESPHome 2024.3.1
INFO Reading configuration /config/esphome/d1-1.yaml...
ERROR Error while reading config: Invalid YAML syntax:

while scanning a simple key
in "/config/esphome/d1-1.yaml", line 61, column 9
could not find expected ':'
in "/config/esphome/d1-1.yaml", line 62, column 9


I do not see anything where I would think a ":" would be needed.

jebradleymd
Автор

Is there any update on this project? How is the battery life? How accurate are your readings? I'd be very interested in a follow up

timderks
Автор

Thanks a lot for sharing your project! A quick question: the Xiao C3 is rated up until 3.6V whilst the battery is 3.7V (and I assume the voltage goes even higher, maybe lower 4.x when fully charged). Have you experienced any issues with it, should I be considered if I were to copy your setup with a 3.7V LiPo battery?

tbandras
Автор

Do you have a github page or a written guide with wiring diagrams? I'm just getting started with ESP32 using batteries. Also, did you consider fitting a solar panel to this battery to keep it topped up?

niallbt
Автор

Thanks for the tutorial! But by Pasting your code i get the following error code:

INFO ESPHome 2024.5.5
INFO Reading configuration
ERROR Error while reading config: Invalid YAML syntax:

while scanning a simple key
in "/config/esphome/boden-feuchtigkeit-1.yaml", line 16, column 1
could not find expected ':'
in "/config/esphome/boden-feuchtigkeit-1.yaml", line 17, column 1

can someone help me out? Many thanks!

tobias
Автор

Hello, I'm trying to make my yaml configuration, but I got this error: Pin 0 is used in multiple places. Could you help me? thanks in advance


Failed config

sensor.adc: [source <unicode string>:55]

Pin 0 is used in multiple places.
platform: adc
pin:
number: 0
mode:
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
ignore_strapping_warning: False
drive_strength: 20.0
name: Battery Life
unit_of_measurement: %
device_class: battery
update_interval: 2s
attenuation: 11db
filters:
- multiply: 2.0
- calibrate_polynomial:
degree: 4
datapoints:
- from: 3.4
to: 0.0
- from: 3.6
to: 8.43
- from: 3.81
to: 50.06
- from: 3.86
to: 57.63
- from: 3.92
to: 72.56
- from: 3.96
to: 90.96
- from: 4.05
to: 100.0
- lambda: !lambda |-
if (x > 0) return 0;
else if (x > 100) return 100;
else return (x);
disabled_by_default: False
force_update: False
accuracy_decimals: 2
state_class: measurement
raw: False
sensor.adc: [source <unicode string>:80]

Pin 0 is used in multiple places.
platform: adc
pin:
number: 0
mode:
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
ignore_strapping_warning: False
drive_strength: 20.0
name: Battery Voltage
update_interval: 2s
attenuation: 11db
filters:
- multiply: 2.0
disabled_by_default: False
force_update: False
unit_of_measurement: V
accuracy_decimals: 2
device_class: voltage
state_class: measurement
raw: False

Marco
Автор

I was testing a very similar setup, and found that my Xiao ESP32C3 was still drawing ~25mA in deep sleep. I wasn't able to reduce the power consumption, so with it only lasting a day or two, I ended up making it a hardwired system instead. What kind of battery life did you ultimately end up with?

codybarker
Автор

How well did the capacitive sensor hold up?

DivinaFarms_James
Автор

normal water does not conduct like mineral salts or acid or hard ground water PH
but great project.

Rene
Автор

Ok, my sensor is working, it reads 30 second and after 3h in deep sleep. But I have 2 questions.
1. It seems that the Voltage reading is not very accurate. I have calibrate the value Many times but after some reboot it reads 0.2 0.3 V more or less than the real battery value. I have used two resistor 220k in parallel.
2. How can I do to allowr home assistant to show in the dashboard the last value read when the esp32 is in deep sleep.
Thanks in advance for any help.

Marco
Автор

Thanks, this is great and exactly what I want to create. Would you be willing to share the design for the case and a link to the battery you used (for sizing)?

IF-VR
Автор

This is my very first ESP32 project and I am trying to understand how to connect a 18650 battery to the board. How did you make the connection? Are you connecting it to the 5v pin?

lflondonol
Автор

Can Share all ? the project is amazing. I've been looking for something like this for a long time and now I'm grateful to you for showing it. can you show the wiring properly? Thx

SuperMrZerox
Автор

Can you charge the battery via the Xiao or do you need to de solder and charge via a charger. Thanks/

MattOmondPrintbotOMO
Автор

Can you share the 3d printed design? I'd like to make my own :)

LorenzKort