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
esphome:
  name: soilsensor
  platform: ESP8266
  board: d1_mini

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

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "password"

ota:
  password: "password"

# Deep Sleep Feature. Needs adjustments...
deep_sleep:
  run_duration: 70s
  sleep_duration: 120min
  
i2c:
  sda: D2
  scl: D1
  scan: True
  
sensor:
  platform: adc
  pin: A0
  id: moisture_sensor
  name: "Soil Moisture"
  unit_of_measurement: "%"
  update_interval: 10s
  filters:
# 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
          
display:
  - 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);
      
font:
  - 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

JAD

2 Likes

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).

Also

  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

Hi,

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.

Greetings

JAD

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.