Rainsensor and esp32

Hello everyone,
I have this rain sensor

And want to connect this to an esp32, so this

I have been searching on the internet but I can’t find this combination.

Can someone tell me how to connect this correctly and what code I need.

I am completely new to esp home, so I don’t understand much of the numbers on the esp32 and what they are for.

Thanks for all the info!

These have 2 outputs - a digital output (D0) that goes high when water is detected and an analog output (A0) that varies with the amount of moisture.

You can use both at the same time.

Set up a GPIO binary sensor for the D0 pin:

and an ADC sensor for the A0 pin:

Thank you very much for your reply. but my esp32 is not the same as used in the explanation. I am really new to esp so I dont really understand where to connect the wiring to my esp!

It’s technically same, you can follow the tutorial.
GND to GND
VCC to D19
DO to D21
AO to VP (D36)

Thank you very much for your reply.

I think it worked,

but I don’t see the rain sensor in HA.
What am I doing wrong again?

You need to setup Esphome and when done use one of those sensor components (or both) linked above.

Thanks for your reply.

If I understand correctly I need to install Esp32 in ESPHome first, then follow this tutorial?

Exactly.

That tutorial was just for wiring and testing. You don’t run arduino code on esphome. When you have the base configuration on esphome done, you add the sensor component(s) from above.

Thanks for your response.

I now have the following setup


and the following configuration.

esphome:
  name: terras-regensensor
  friendly_name: Terras Regensensor

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

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

ota:
  - platform: esphome
    password: "xxxxxxxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Terras-Regensensor"
    password: "xxxxxxxx"

captive_portal:

web_server:
  port: 80





# Example configuration entry
sensor:

  - platform: adc
    pin: GPIO36
    name: “Waterleak”
    update_interval: 2s

and this is the result

But I really can’t get any further. What am I missing here?
Thanks for your response

Nice!
Add this to your ADC sensor

attenuation: 12dB
samples: 10

Then make a switch to power your sensor:

switch:
  - platform: gpio
    id: power
    name: "Sensor Power"
    pin: GPIO19

Later you can automate the powering and sensor reading.

Thanks for thinking along.

But could you explain to me what we have actually done (as I said I am very new to ESPHome) and how can I now measure rain and the amount of rain?

I will, when you confirm that the sensor works when powered with the switch component and you post what values you receive.

?

yes the sensor turns on and off when I press the button! :sweat_smile:

But could you explain to me what we have actually done (as I said I am very new to ESPHome) and how can I now measure rain and the amount of rain?

And now it looks like this.

Turn power on and play with water…

when I put water on the sensor the second led turns on

Amount of rain no-how with that sensor.

That’s the digital output threshold.
But what readings you get on your esphome sensor?

Would you be so kind to explain this a little bit so I can understand it a little better.

Analog output voltage changes according to the presence of water on the sensor. Might be close to zero when dry and few volts when fully wet.
At best you can use that to detect when it starts raining and maybe for frost detection. But it can’t measure rain quantity.
Here in this case we power the sensor from Esp GPIO pin, something that usually has to be avoided with most sensors. Reason for this is that the sensor electrodes oxidize very quickly if powered continuously. So if you want to continue with that setup, you need to automate the sensor readings and power on cycles.

So if I understand correctly I now need to create an automation that turns on the sensor switch every so often and then compares the “waterleak” value with the value when the switch is off?