Can't get readings from Capacitive Soil Moisture Sensor

I was looking around the Community forum and managed to connect my Capacitive Soil Moisture Sensor (v1.2) with a Wemos D1 Mini*, and flash it through ESP Home. I get everything but the readings… Maybe someone can help me sorting the issue?

Here is my hardware connection:

My current code:

esphome:
  name: soil-moisture-inside-garden
  platform: ESP8266
  board: AZDelivery_d1_mini_nodemcu

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Soil-Moisture-Inside-Garden"
    password: "my_pass"

captive_portal:

# Enable logging
logger:

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

ota:
  password: "my_password"

sensor:
  - platform: adc
    pin: A0
    name: soil_moisture_inside_garden
    id: moisture1
    accuracy_decimals: 4
    update_interval: 1s
    unit_of_measurement: "v"
    icon: "mdi:water-percent"
    filters:
    - median:
        window_size: 20
        send_every: 10
        send_first_at: 5
#    - calibrate_linear:
#        - 0.0175 -> 0
#      - 0.0488 -> 100

#updates above template to HA #
interval:
  - interval: 10sec
    then:
      - component.update: moisture1

I managed to get it recognized by ESP Home, as such:

But all I can get in the device Logs is this:

The error I’m getting:

Logger: frontend.js.latest.202207071
Source: components/system_log/__init__.py:190
First occurred: 15:09:59 (16 occurrences)
Last logged: 16:18:23
:0:0 ResizeObserver loop completed with undelivered notifications.

I cant get any readings from the sensor, neither any entity on ESPHome integration (only device). Tried both with 3V and 5V. I also tried with a different sensor, from the same batch.

Any ideas for what I’m doing wrong?
Thanks in advance for any help.

*I also tried with a EZDelivery ESP8266 (Wemos D1 Mini clones)

For what is that interval exactly? The sensor get’s updated every second already and then on top you run another component update every 10 seconds?

You probably just can get rid of the interval block completely.

If you leave this running for some time is everything else printed here? From time to time new lines should appear here :thinking:

@orange-assistant, thank you for your tips. I’m working with some more few tests and I think tomorrow I will have news.

I finally had the time to finish some tests, and here are some answers and updates.

Since I’m close to zero knowledge in Yaml and ESPHome, I looked in the HAcommunity forum - here - and tried to follow the steps there, including copy/pasting whatever codes I found. So, I have no idea why this other component was there. But I took out this part of the code, and took in some other bits I’ve found here.

sensor:
  - platform: adc
    pin: A0
    name: "Soil Moisture Wemos"
    id: moisture1
    accuracy_decimals: 4
    update_interval: 1s
    unit_of_measurement: "%"
    device_class: humidity
    icon: "mdi:water-percent"
    filters:
      - lambda: |-
          float moisture_dry_soil_value= 0.61328;
          float moisture_wet_soil_value =  0.25488;
          if (x >  moisture_dry_soil_value ) {
            return 0;
          } else if (x < moisture_wet_soil_value) {
            return 100;
          } else {
            return (moisture_dry_soil_value - x) / (moisture_dry_soil_value - moisture_wet_soil_value ) * 100.0;
          }

Did some more tests and I’m now getting readings, as a percentage as I wanted!

The only little thing I’m missing is that I loose a socket per minute or so. Not something too problematic…But with the genuine Wemos D1 Mini I just dont loose any socket. Perhaps something about the fact the EzDelivery D1 Mini clones are just lower quality.

Thanks for looking into this!

The thing with these cheap moisture sensors is that they are not calibrated in factory and the output differs a lot between them. For example you copied the the values 0.61328 and 0.25488 for the maximums (dry and wet) and while that is probably true for the person posted that code it is most likely not the case for your sensor.

While you get some percentages now they probably are not representing your min/max.

It’s actually quite easy to “calibrate” these sensors. The maximum (wet) is just to put the sensor in a glass of water while the minimum would be just sitting in dry air. Next problem is only that the output of this type of sensors is not linear - something that the code you have doesn’t take into account. Best would be to try to also get values in between and then maybe just use the calibrate_linear function from esphome and ditch the custom lambda filter instead.

This link might give an idea what to expect on the analog output of such sensors: Testing Capacitive soil moisture sensors

1 Like

@orange-assistant, thank you again for your help. I calibrated mine with my values already :wink: That part I got! Certainly will look into changing from lambda to linear in the near future, and will come back with the results.

1 Like