Rain Sensor with deepsleep

I have a simple rain sensor module connected to my esp32 (battery + solar powered).
If it senses raindrops the signal will go low. The ESP also has a temperature sensor connected.

I want to achieve the following process:

No Rain:

  • 4s run, 30min sleep
  • rain sensor voltage on (to detect rain)
  • temperature sensor voltage on, while running

Rain detected (output rain sensor low):

  • interrupt sleep
  • turn rain sensor voltage off (to avoid corrosion)
  • set rain sensor state to “on” for 30min (until the normal cycle activates the rain sensor again)
  • go into deep sleep for 30min

My Problem is, that when the esp should go into deep sleep it wakes up after ~1-4s and immediately goes back to sleep.

esphome:
  name: $devicename
  platform: ESP32
  board: lolin32
  on_boot:
      then:
        - output.turn_on: dht_supply
        - output.turn_on: rainsensor_supply

  on_shutdown:
      then:
        - output.turn_off: dht_supply

#WIFI
wifi:
  ssid: !secret wifiname
  password: !secret wifipw
  fast_connect: true
  manual_ip:
    static_ip: !secret node_01_ip
    gateway: !secret gatewayip
    subnet: !secret subnet
    dns1: !secret dnsip
    dns2: !secret dnsip
  power_save_mode: high
  output_power: 10

# Enable logging
logger: 
  level: ERROR

#DeepSleep
deep_sleep:
  run_duration: 4s
  sleep_duration: 30min
  id: deep_sleep_1
  wakeup_pin: 27
  wakeup_pin_mode: INVERT_WAKEUP

#MQTT
mqtt:
  broker: !secret mqttbrokerip
  username: !secret mqttuser
  password: !secret mqttpass
  topic_prefix: $devicename
  discovery: False
  discovery_retain: False
  
#3.3V Supply Switch
output:
  #DHT22
  - platform: gpio
    pin: 26
    id: dht_supply
    
  #RAINSENSOR
  - platform: gpio
    pin: 23
    id: rainsensor_supply
    
sensor:
 #DHT22
  - platform: dht
    pin: 25
    model: AM2302
    update_interval: 2s
    temperature:
      name: "${devicename}_am2302_temperature"
  
binary_sensor:
  #RAINSENSOR
  - platform: gpio
    id: regensensor
    pin: 
      number: 27
      inverted: true
      mode: INPUT_PULLUP
    name: "${devicename}_rainsensor"
    filters:
      - delayed_on: 30min
    on_release:
      then:
        - output.turn_off: rainsensor_supply
        - deep_sleep.enter: deep_sleep_1

I’ve never managed to get this to work. I have a gate on a battery powered esp and it is supposed to go to sleep if the gate is left open or closed. Works fine if the gate is closed but if it is left open it wakes repeatedly as you are seeing.

Not sure if there is an issue open for this as github is blocked from where I am at the moment.

There are some issues regarding INVERT_WAKEUP on github. Thanks for the info.

My pin is inverted:

- platform: gpio
    id: rainsensor
    pin: 
      number: 27
      inverted: true
      mode: INPUT_PULLUP

does that mean wakeup is inverted too (wakeup thinks it is high when the pin is actually low)?

#DeepSleep
deep_sleep:
  run_duration: 4s
  sleep_duration: 30min
  id: deep_sleep_1
  wakeup_pin: 27

Might work with the default wakeup mode then.

Another question:
Does the filter refer to the state before the invert command (the real state of the pin) or the inverted state?

 - platform: gpio
    id: rainsensor
    pin: 
      number: 27
      inverted: true
      mode: INPUT_PULLUP
    filters:
      - delayed_on: 30min

I’m not sure on this one. The wake up logic is hardware, but the pin inversion is software. My gut feeling is that it would still wake when the pin went high.

This one I am certain is the inverted state.

This means i`d have to wait for a fix for INVERTED_WAKEUP.
Thanks for your help, Tom.

How does this actually work? when i have a pulse_counter rain sensor with this config?

  - platform: pulse_counter
    name: ${display_name} Rain
    pin:
      number: D4
      mode: INPUT_PULLUP    
    update_interval: 2s
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 10ms
    unit_of_measurement: "mm"
    icon: "mdi:water"
    filters:
      - multiply: 0.359254458

And i just want to make sure it is going out of deep sleep when the sensor send data?
Just add this like you?

  wakeup_pin: d4
  wakeup_pin_mode: INVERT_WAKEUP
>  - platform: gpio
>     id: regensensor
>     pin: 
>       number: 27
>       inverted: true
>       mode: INPUT_PULLUP
>     name: "${devicename}_rainsensor" 

Hi,
I’m trying to build the same thing but wired instead of battery powered. Just this part is in relation to the rain sensor right? What’s the wiring look like for this? currently I’m trying to get it to work using the resistance component, so this method is new to me