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:

esphome:
  name: weather-station

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: ""

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

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



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

# sensore luminosità    
  - platform: adc
    pin: GPIO32
    name: "Sensore luminosità"
    update_interval: 1800s
    unit_of_measurement: lx
    attenuation: 11db
    filters:
      - lambda: |-
          return (x / 10000.0) * 2000000.0;
 
  
 
# sensore movimento 
#binary_sensor:
#  - 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

    filters:
      - multiply: 0.846153 # 3.9 (11db attenuation full-scale voltage) -> 3.3V
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
  
 
 
binary_sensor:
  - 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:

binary_sensor:
  - platform: gpio
    pin:
      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

sensor:

  • 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:

2 Likes

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?

Thanks

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.

Thanks,

Jose

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?

this:
image

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
GND to GND 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?