My first ESPhome project. Soil moisture sensor,

Hello everyone,
I would like to introduce my latest project to you. Nothing earth-shattering, but for me the first project I realized with ESPhome.

It is a ground humidity sensor based on a Wemos D1 mini, a small OLED display with SSD1306 chip and of course a capacitive sensor.

The sensor is working so far and could be used in this way, but I noticed a few small things which I would like to discuss with you.

Here is the YAML code:

# ESPhome Soil Moisture Sensor v 0.1
  name: soilsensor
  platform: ESP8266
  board: d1_mini

# WIFI Credentials
  ssid: "MY WIFI"
  password: "password"

# Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Soilsensor Fallback Hotspot"
    password: "password"


# Enable logging

# Enable Home Assistant API
  password: "password"

  password: "password"

# Deep Sleep Feature. Needs adjustments...
  run_duration: 70s
  sleep_duration: 120min
  sda: D2
  scl: D1
  scan: True
  platform: adc
  pin: A0
  id: moisture_sensor
  name: "Soil Moisture"
  unit_of_measurement: "%"
  update_interval: 10s
# Sensor dry around 0.825 Volt, sensor wet around 0.425 Volt. Volts are were flickering
      - calibrate_linear:
          - 0.825 -> 0.0
          - 0.425 -> 100.0
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
# Display output needs adjustments
    lambda: |-
      it.printf(0, 10, id(my_font), "Feuchtigkeit");
      it.printf(0, 32, id(my_font), "liegt bei:");
      it.printf(0, 54, id(my_font), "%.1f %%", id(moisture_sensor).state);
  - file: "arial.ttf"
    id: my_font
    size: 20

I noticed the following:

  1. the values of the sensor are not very stable and fluctuate a bit. Not too bad, but it will get better. Since I want to do the whole thing battery powered anyway and therefore have to use Deep Sleep, I thought of the following. After waking up, the values are determined several times within one minute and then simply calculate an average value for this measurement.
  2. i had already written it, battery operation and deep sleep should also be included. I played a bit with the possibilities and the sensor goes to sleep after 70 seconds, but it doesn’t wake up properly. After the Deep Sleep phase I can see what’s happening by the power consumption. However, the power consumption is always about half as much as before the first deep sleep phase. Wifi can not be connected either.
  3. is there a possibility to display the battery status of the sensor? I would like to realize this with a battery shield for the Wemos D1 mini. The A0 pin of the Wemos is already occupied by the humidity sensor…
  4. in general I would like to interrupt the deep sleep somehow. That would make maintenance a bit easier.
  5. I’m also not quite satisfied with the output on the display. There is certainly room for improvement.

So far my thoughts first. What are your thoughts about this project? What would you change in the code and why?

Maybe you have some ideas how to realize my wishes?

I am happy about your suggestions and comments.

Thanks a lot



I would move to an esp32 as it has

  1. more adc pins
  2. Better deep sleep options (eg the ability to wake up when a gpio is activated by a pushbutton).


  1. There are a number of filters built into esphome, you can filter the variable input.
  2. The dispay stuff is very subjective. You’ll have to play around with fonts etc.
1 Like


thanks for your comment.

To the hardware choice: I chose the Wemos D1 mini (ESP8266) because I still had a few of them here and they were sufficient for what I had in mind.

Regarding your comments on the software:
I already tried a little bit with the filters but I didn’t get any result that would have fit. Hence my question in the forum if anyone had a tip.

Concerning the display I have to agree with you - it’s all quite subjective. But there must be a way to make a line break more elegant, right?

As I said, would be very grateful for helpful suggestions.



Perhaps take a pic and we can see what you mean.

Well you didn’t say that, so you should perhaps tell us what you tried.

If you want two analogue inputs, it is insufficient :slight_smile:

Very basic question: is it possible to connect more than one of those soil moisture sensors to one esp32?

Very basic answer: yes.

1 Like

Thank you very much for sharing your project here!
It was working on my system 1:1. Great job!

Did you in the mean time find a way to fix the deep sleep problem?

Answer to your second point: i had the same issue. i solved it by bridging RST and D0 like on this page.

now the restore from deepsleep is succesfull.