Waking up from deep sleep with rain gauge

Hello guys,I’m building project of weather station solar powered with an esp32 on esphome.
But I have one issue at this time, maybe someone of you could help me, I searched a lot on google, but nothing worked…
So, I have a rain gauge sensor (https://cdn.sparkfun.com/assets/d/1/e/0/6/DS-15901-Weather_Meter.pdf) :

platform: pulse_counter
  pin:
    number: GPIO27
    inverted: True
    mode: INPUT_PULLUP
  unit_of_measurement: 'mm'
  update_interval: 2s
  name: 
  id: rain_meter

and a deep sleep component:

deep_sleep:
  id: deep_sleep_control
  sleep_duration: 120s
  run_duration:
    default: 10s

Then I want that when it’s raining, and when my rain meter measure 0,3mm (one gauge), it wake up my ESP32, for send this data to my home assistant
I tried the wakeup_pin_mode, the esp32_ext1_wakeup but nothing worked… maybe I did something wrong with mode of them…

Thanks for reading me.

you might want to look at

https://ncrmnt.org/2021/12/06/optimizing-esp8266-esphome-for-battery-power-and-making-an-ice-bath-thermometer-as-well/

It would help if you shared the yaml with wakeup_pin or similar configured - it’s a bit hard to tell were you may have gone wrong without the code.

I assume you only what to know “it’s raining”, not how much rain you are actually getting. Deep sleep sensors are not a good choice for monitoring continuous events like rainfall.

deep_sleep:
  id: deep_sleep_control
  sleep_duration: 120s
  run_duration:
    default: 10s
    gpio_wakeup_reason: 10s
  wakeup_pin: 
    number: GPIO27
    inverted: True
    mode: INPUT_PULLUP

  

 
sensor:
  - platform: pulse_counter
    pin:
      number: GPIO27
      inverted: True
      mode: INPUT_PULLUP    
    unit_of_measurement: 'mm'
    update_interval: 2s
    accuracy_decimals: 3
    name: 'station_meteo_compteur_pluviometre'
    id: rain_meter
    filters:
    - multiply:  0.01

10 seconds is a really short wakeup time - especially if using DHCP. Does your device fully come up and connect within that time?

You may want to try setting wakeup_pin_mode: to KEEP_AWAKE as well, otherwise it will go back to sleep after 10 seconds regardless.

I assume you are using deep sleep because you are running on batteries?

Hello buddy, Yes my device fully come up in 5sec, actually i’m on wifi, but after I want to made it in 4G/5G LTE.
Yep, I’m running on batterie with solar cell. I tried with KEEP_AWAKE too. and doesn’t work.
I want that when it’s raining, and my gauge mesuring his first bucket, thats wake up my esp32 to send data of this measurement to my home assistant

Ok - so what isn’t actually “working”? Is the device not waking? Or not counting? It won’t count the wake tip as part of the sensor and as defined above will only stay awake for 10 secs before shutting down again. So if you are getting light rain (less than one tip per second) then it won’t increment the sensor at all.

Yep sorry, When I said not working, is because the esp32 doesn’t waking up when the rain gauge is activated, when it measures its volume of rain to activate the pendulum

When I put off the deep sleep system, and activate the rain gauge, thats work, it measure well.

But I want the device to be in deep sleep when it’s raining hard enough to activate the pendulum, it must wake up the esp32 so that these measurements can be added to my home a

So are you sure the gauge goes low when tipping? The diagram on the data sheet implies it does, but have you tested it with a multimeter or scope?

I didnt tested it but I think it is, cause when I disable the deep sleep module, that works very well.
But I want it to work as wake up pin when its raining and my ESP32 is in deep_sleep

Ah yes - of course. Well you are using the correct pin, your yaml looks correct - so I am out of ideas. My only sensor that uses pin wakeup leaves out the inverted: true line. It works fine:

deep_sleep:
  run_duration: 60s
  sleep_duration: 6h
  wakeup_pin:
    number: GPIO04
    mode: INPUT_PULLUP
  wakeup_pin_mode: INVERT_WAKEUP
  id: deep_sleep_1

The wakeup_pin_mode: line is because it can get stuck in a closed state and so it will wake again on open.

I am also thinking to add a rain gauge in the back yard which will need to be battery powered.

In the case of a rain gauge, it is impossible to predict when the rain might start, or how heavy the rain will be - ie how long between the pulses generated as the bucket empties and the next bucket fills up.

I have been wondering if this is feasible … so thanks Daryl for confirming this works for you.

As you say, it wont count the bucket tip which does the waking up, or any before the ESP32 is fully up.
Which started me thinking that really I am after the number of tips per minute (or per hour for long-term statistics) rather that recording each individual bucket tip with millisecond timing.

I really am not into electronics, but am assuming there may be a simple electronic circuit which can count the number of pulses received, and which can be read and reset (say every minute) by the microcontroller.

I personally think that battery powered wifi sensors using deep sleep have limited use cases. They are good for event sensors (a mailbox sensor like my snippet above) or for sensors that don’t require continuous data (I have a lux sensor for outside light control that wakes every 10 minutes).

I use a lot of 433MHz sensors and my weather sensors are Ecowitt brand. The rain sensor has been running for over 2 years on a single AA battery. You do need one or more 433MHz base stations running on permanent power though.

BUT - this is just my opinion, other users may have differing experience.

Hey thanks guys for all your answers. But still not working, I tried with deleting “inverted mode : true”.
I don’t know if it’s really possible to wake up ESP32 by pulse counter…

Hello back there, keep trying to make it worth last week but still nothing…
Maybe I can’t made a wakeup by pin, when the default wake up is on too ?
Only one mode of wake up can be enabled?

update

deep_sleep:
id: deep_sleep_control
run_duration:
default: 30s
gpio_wakeup_reason: 30s
sleep_duration: 120s
wakeup_pin:
number: GPIO13
inverted: true
mode:
input: true
pullup: true

With this code, it’s waking up from deep_sleep when it’s raining, but I think that my esp is waking up to slow to add 0,3mm to my pulse_counter

I am having a go at this, and seen another thread suggesting adding “allow_other_uses: True” to both the deep-sleep and the sensor … except that when I add it to my yaml pulse_counter like

# rain gauge sends pulses as the bucket tips
  - platform: pulse_counter
    pin: 
      number: GPIO7
      mode:   INPUT_PULLUP
      allow_other_uses: true
    name: $devicename Rain Gauge
    update_interval: 2 min
    on_raw_value:
      then:
        - globals.set:
            id: is_raining
            value: 'true'

gives the validation error

INFO ESPHome 2024.12.4
INFO Reading configuration /config/esphome/greenhouse.yaml...
Failed config

sensor.pulse_counter: [source /config/esphome/greenhouse.yaml:336]
  
  Pin 7 incorrectly sets allow_other_uses: true.
  platform: pulse_counter
  pin: 
    number: 7
    mode: 
      input: True
      pullup: True
      output: False
      open_drain: False
      pulldown: False
    allow_other_uses: True
    inverted: False
    ignore_pin_validation_error: False

and removing that line compiles OK … which sounds like allow_other_uses isn’t valid for a pulse_counter, but is for other types.

FYI: “allow_other_uses” is ONLY described in the Pin Schema section of the Configuration Types documentation page, and doesn’t indicate which components it is valid for.

Why would it only apply to certain components when its just a simple configuration option that allows you to manually specify 2 uses and stops duplicate pin use warnings during compile.

Now if you would quit taking it upon yourself to decide for everyone else which parts of the config are relevant and deciding what people do or dont need to see, well that would be super helpful for the people you’re asking to help you!

Would you take your car to a mechanic and make him fix your car with one hand tied behind his back?

Of course not so, why do that to the group and only post one little part of your config? Hell, you didn’t even post the other half of the

allow_other_uses: true

Where’s the second gpio entity that’s also supposed to be using GPIO7?? He call in sick today or what? I know my GPIO7 is a lazy bumb and always calls in sick too!

Whenever you see GPIO7, you might ask him what hes sharing his pin with and if we could get some security clearances in here mucho rapido and see the config, that sure would be spectacular and mighty helpful!

I did a trial test on one of my

pulse_meter:

configs and it compiled with 0 issues or errors so, i cant imagine why your

pulse_counter:

is failing for any other reason than you didnt specificy what the second GPIO7  use is, or you made a syntax error. Couldn't tell you which one it is or how to fix it untill I get my security clearance and can cast my eyes on those state secrets!!

You are right. I didn’t specify that my objective is to use the pulse from the rain gauge on GPIO7 to also wake the ESP32 from deep_sleep … probably because that is the topic of this thread

Thinking back the 23 days to when i posted that comment, I wasn’t asking for help - just mentioning that allow_other_uses hadn’t worked for me.

I had (and still have) other aspects I am working on, and so just commented out the deep_sleep: code intending to came back to it later. FYI, the the “other half” was

deep_sleep:
  # wake up if it starts raining while asleep 
  wakeup_pin: GPIO7            # wake up if a rain gauge pulse is detected
    allow_other_uses: true
  wakeup_pin_mode: KEEP_AWAKE   # stay awake if rain is happening when otherise would sleep

Do you really want to work through my 584 lines of yaml, for a problem I am not actively looking at currently ? But when I do do the research, describe the things I have tried, provide all code and results … most often there is no reply. Such is the nature of Open Source Community - and (before you get all upset again) I understand the motivations and am okay with that.