Rain gauge pulse counter

I recently installed a tipping bucked rain gauge with 0.2mm resolution (per tip) to my garden ESP32.

I’ve checked the pulse output from the gauge, very clean (no debouncing needed) with a negative going ~50ms pulse per tip.

I’ve implemented this sensor config:

  - platform: pulse_counter
    pin:
      number: GPIO21
      inverted: true
      mode:
        input: true
        pullup: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    unit_of_measurement: 'mm/h'
    device_class: precipitation_intensity
    state_class: measurement
    name: 'Rain Rate'
    icon: "mdi:speedometer"
    update_interval: 15min
    filters:
      - multiply: 0.8 # 0.2mm per pulse for 1/4 hour
    total:
      unit_of_measurement: 'mm'
      device_class: precipitation
      state_class: total
      name: 'Total Rain'
      icon: "mdi:weather-pouring"
      filters:
        - multiply: 0.2

Questions:

Have I got the rain rate filter correct?

0.2mm per tip, updated every 15 minutes (for better accuracy), gives 0.2 * 4 = 0.8 for the unit of mm/h. Correct?

Why is the total not updating?

Last night there was a short shower. it registered 0.05mm/h but no total update:

A nearby weather station (BoM) recorded 0.4mm.

The reported 0.05mm/h rain rate means there were:

0.05/0.8 = 0.0625 tips which is just wrong.

Interestingly if I multiply that by 15 it comes out damn near 1.

Does the pulse counter automatically divide the reading by my update interval and assume I want a /minute output?

That seems very counter intuitive.

Does the pulse counter report pulses per minute, same as the newer pulse meter? I thought the major difference was the new one was more accurate.

Would that make sense compared to your thinking that it reports number of pulses per interval?

I assumed this would take precedence:

Now I’m thinking that this is just how often the sensor reports to HA and it always uses a /min rate.

This would be bad. Tipping bucket rain gauge rain rate accuracy improves with sample time. 1min is awful, 10min is acceptable, but I can no longer find the paper where I read this.

I just removed all filters, rebuilt and went and squirted enough water into the gauge to tip once. Still have 6 minutes until I get a result…

Ok results are in for no filters, 15 minute interval, after applying 0.2mm of rainfall:

Total: 1mm: → I must multiply by 0.2 to get the real value. This was expected (0.2mm/tip).

Rate: 0.13 → I would have to multiply by 6.1538 to get 0.8mm/h, I have no idea where this number comes from. Has the /min rate decayed over the 15 minutes between reports?

EDIT: found the paper on accuracy by the way: https://ntrs.nasa.gov/api/citations/20070016690/downloads/20070016690.pdf conclusions are at the bottom of page 28 (pdf numbering), or page 26 (document numbering).

Next I will change the update interval to 1 minute and see what happens.

1 Like

Curiouser and curiouser.

No filters for the rate, *0.2 for the total, 1 minute interval, after applying 0.2mm of rainfall:

Total: 0 (did not update!)

Rate: 1 (decayed to 0 one minute later).

This does not help me work out where the 6.1538 for 15 minutes comes from.

And the total is back to not updating. Applying a filter to this seems to break it.

This component is busted as.

Time to try Pulse Meter instead of Pulse Counter?

I am not much help here - I use an Ecowitt weather station via 433MHz and their own gateway…

Nah the counter was the correct one. The pulse meter only counts per minute.

With the help from the knowledgeable folks over on the esphome Discord I got it sorted.

  1. If multiplying the total by 0.2 I have to set the accuracy_decimals: 1 option. The total counter has a default accuracy of 0 decimals.

  2. Calculating the rate should have been:

multiply: 12 # 5 pulses/mm in 15 minutes = *3 for mm/15min, but I want mm/h so *4 as well

Final config:

  - platform: pulse_counter
    pin:
      number: GPIO21
      # inverted: true
      mode:
        input: true
        pullup: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    unit_of_measurement: 'mm/h'
    accuracy_decimals: 4
    device_class: precipitation_intensity
    state_class: measurement
    name: 'Rain Rate'
    icon: "mdi:speedometer"
    update_interval: 15min
    filters:
      - multiply: 12 # 5pulses/mm in 15 miunutes = *3, reported as mm/h every 15 minutes = *4
    total:
      unit_of_measurement: 'mm'
      accuracy_decimals: 1
      device_class: precipitation
      state_class: total
      name: 'Total Rain'
      icon: "mdi:weather-pouring"
      filters:
        - multiply: 0.2

Finally and most importantly, note also that there is another issue. The first counter period after a restart is not guaranteed to be 15 minutes. This is what was sending my numbers all over the place. This random interval is so that all sensors don’t update at the same time.

2 Likes