ESP rain detector

Hi guys
I’m trying to create a weather station that include a rain sensor like that:

I’m using a ESP32 DevKit V4 and I tried this code:

  name: weather-station

  board: esp32dev
    type: arduino

# Enable logging

# Enable Home Assistant API

  password: ""

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Weather-Station Fallback Hotspot"
    password: "Zaamb9bZPZm2"

  - id: bus_a
    sda: GPIO21
    scl: GPIO22
    frequency: 100kHz
    scan: true
  - id: bus_b
    sda: 14
    scl: 15
    scan: true
# sensore temperatura e pressione     
  - platform: bmp085
    i2c_id: bus_a
    address: 0x77
      name: "Temperatura esterna"
      name: "Pressione atmosferica"
    update_interval: 1800s

# sensore luminosità    
  - platform: adc
    pin: GPIO32
    name: "Sensore luminosità"
    update_interval: 1800s
    unit_of_measurement: lx
    attenuation: 11db
      - lambda: |-
          return (x / 10000.0) * 2000000.0;
# sensore movimento 
#  - platform: gpio
#    pin: GPIO33
#    name: "PIR Sensor2"
#    device_class: motion     

# sensore pioggia 
  - platform: adc
    pin: GPIO34
    name: "Valore Pioggia"
    attenuation: 11db
    internal: true

    # It is important to have a low update interval so that
    # the measurement has time to be done correctly during
    # the activation of the voltage AND taking into account the median filter
    update_interval: 300s

      - multiply: 0.846153 # 3.9 (11db attenuation full-scale voltage) -> 3.3V
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
  - platform: gpio
    pin: GPIO36
    name: "sensore pioggia"
  #  device_class: moisture    

In Ha i see binary sensor state but its “inverted”. When dry it returns “wet” and when wet it returns “dry”
And I cant see the sensor “valore pioggia” in HA even if it works in ESP logs.

What I’m doing wrong?

What signal does your rain-sensor produce?

This diagram (source) indicates that rain is represented as LOW and dry as HIGH:

You can adapt your binary sensor configuration to invert the value:

  - platform: gpio
      number: GPIO36
      inverted: true
    name: "sensore pioggia"

You configured this as internal: true which keeps it on the ESP without generating a sensor in HA.

Thankyou guys !
It’s now working !

In ESPHome , I use platform adc with only DO connected to pin GPIO35


  • platform: adc
    pin: GPIO35
    name: “waterleak”
    update_interval: 2s

It works well…

1 Like

This is a brilliant thread. I have some of these rain sensors arriving today (July 18th 2022). If you live in the UK you will appreciate the irony of!

Now if only I could find a similar article in integrating the Max30102 sensor into ESPHome :slight_smile:


This is a nice solution that I would like to try.
I looked for info on the size of the resistor but couldn’t find it.
You have no idea about the value of the resistor?

Thank you. I only read the article and didn’t look at the complete yaml so I missed it.
Thanks again for the direction.

According with the picture, the resistance is 1k ohm (Brown, Black, Red), any reason why t’he code fix a resistor value of 9.868 kohm?


It’s a 10k resistor (brown, black, orange), and the “resistor value” is the real resistor value measured with a multimeter. In mine the measured value is 9.94kOhm

Thanks Nuno,

In my monitor seems red, not orange.



I’m trying to do the same with an esp32-wroom-32 like this
but I don’t understand how to wire the esp to the rain, any help will be appreciated

What is the connection type? i2c?


First post above shows how it is connected to the controller. The controller has 4 wires that go to the ESP as follows:

VCC to 3.3V on ESP
SDA to GPIO21 pin on ESP
SCL to GPIO22 pin on ESP

You need to check what voltage the sensor requires

thx I don’t have SDA and SCL I have DO and AO

I would suggest wiring it this way (and make use of the yaml snippet) so that the permanent dc voltage doesn’t degrade your raindrops module within weeks/months :point_down:

Diagram for connecting the rain detection sensor

I misread and definitely not i2c! @orange-assistant is the way to go

what is the part I marked and where do I get it?