Another Capacitive Soil Sensor question

Hi All. fairly new to the ESPHome world and am trying to understand how to get a capacitive soil monitor working (or just as importantly what the numbers that it outputs mean because it seems to be the reverse of what I was expecting. Eventually this will feed into Homeassistant but that is a later step in the process.

I have an espwroom-32 with one of these detectors connected. I have the following connections:

GND is connected to GND on the ESP32
VCC is connected to VN on the ESP32
AOUT is connected to D35 on the ESP32

My YAML will follow.

I am testing this but firstly leaving this on my work bench out of water and then putting it into a glass of water (water level below the white line on the sensor)

So this is my YAML - I have define the pin as GPIO35 - should it be A0 (or something like that?)

esp32:
board: esp32dev
framework:
type: arduino

time:

  • platform: homeassistant
    id: esptime

Enable logging

logger:

Enable Home Assistant API

api:

ota:

sensor:

  • platform: adc
    pin: GPIO35
    name: esp_32_01_soil_01
    update_interval: 1s
    attenuation: 11db
    id: esp_32_01_soil_01
    unit_of_measurement: “%”
    filters:

    • median:
      window_size: 7
      send_every: 4

    accuracy_decimals: 0

And these are the readings…started with dry but you can see where I dipped it in the glass of water. Should the dry ones be higher than the wet ones?

[13:04:30][D][api:102]: Accepted ::FFFF:C0A8:89
[13:04:30][D][api.connection:861]: Home Assistant 2022.7.5 (::FFFF:C0A8:89): Connected successfully
[13:04:30][D][time:042]: Synchronized time: 2022-07-31 13:04:30
[13:04:31][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.05900 % with 0 decimals of accuracy
[13:04:35][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.05900 % with 0 decimals of accuracy
[13:04:39][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.06200 % with 0 decimals of accuracy
[13:04:43][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.05900 % with 0 decimals of accuracy
[13:04:47][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.06000 % with 0 decimals of accuracy
[13:04:51][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 2.06200 % with 0 decimals of accuracy
[13:04:55][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.85200 % with 0 decimals of accuracy
[13:04:59][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.84700 % with 0 decimals of accuracy
[13:05:03][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.85000 % with 0 decimals of accuracy
[13:05:07][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.84700 % with 0 decimals of accuracy
[13:05:11][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.84700 % with 0 decimals of accuracy
[13:05:15][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.85100 % with 0 decimals of accuracy
[13:05:19][D][sensor:125]: ‘esp_32_01_soil_01’: Sending state 0.85300 % with 0 decimals of accuracy

Thanks for reading everyone.

Your readings are voltage so see how calibration is done. Lambda just makes it read from 0% to 100% not -2% or 102% you can remove this if you like (its in the calibration to make sure this reads correctly. I changed your name to show you can have it different from your id its just the name you see on HA you can change it back if you like. Also added a default icon and you can remove that or change it to whatever you like.

replace this

sensor:

    platform: adc
    pin: GPIO35
    name: esp_32_01_soil_01
    update_interval: 1s
    attenuation: 11db
    id: esp_32_01_soil_01
    unit_of_measurement: “%”
    filters:
        median:
        window_size: 7
        send_every: 4

    accuracy_decimals: 0

with this

sensor:
  - platform: adc
    pin: GPIO35
    name: "ESP32-01-Soil-01"
    id: esp_32_01_soil_01
    update_interval: 1s
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    accuracy_decimals: 0
    attenuation: 11db
    filters:
    - median:
        window_size: 7
        send_every: 4
    - calibrate_linear:
          - 0.86 -> 0.0 
          - 2.07 -> 100.0 
    - lambda: |
        if (x < 0.0) return 0.0;
        else if (x > 100.0) return (x);
        else return (x);

hope this helps you :grinning:

Thank you very much…I’m off to play :slight_smile: Sorry - experiment.

Sorry it’s been a busy day Blacky but your solution was spot on so once again many thanks.