Help with rainfall calculations

Hi,

I’m after help with rainfall calculations, I cant seem to get this right. I’m trying to calculate the rainfall

  • per hour
  • per minute
  • per day
  • per 24 hours

Heres what I have, and i’m pretty sure its wrong.

Any ideas?

Thanks

####Rainfall Start####
  - platform: pulse_counter
    pin:
      # Don't forget to add a pulling resistor, see README
      number: GPIO32
      mode: INPUT
    unit_of_measurement: 'mm'
    name: "${friendly_name} rain gauge"
    icon: 'mdi:weather-rainy'
    id: rain_gauge
    internal: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 13us
    update_interval: 10s
    filters:
      # Each 0.011" (0.2794mm) of rain causes one momentary contact closure
      - multiply: 0.2
    accuracy_decimals: 4

  - platform: integration
    name: "${friendly_name} rainfall per min"
    id: rain_per_min
    time_unit: min
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    sensor: rain_gauge

  - platform: integration
    name: "${friendly_name} rainfall per hour"
    id: rain_per_hour
    time_unit: h
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    sensor: rain_gauge

  - platform: integration
    name: "${friendly_name} rainfall per day"
    id: rain_per_daily
    time_unit: d
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    sensor: rain_gauge

  - platform: total_daily_energy
    name: "${friendly_name} 24 Hour Rain"
    power_id: rain_gauge
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    filters:
      - multiply: 60
      # x60 To convert to aggregated rain amount

Not sure if this will help or not but a lot of rainfall calculations like that have been done here and may give you a lead or 2.

1 Like

Also doesn’t an integration sensor require a source sensor that is unit per time interval?

Your input sensor is a total…

You’re wanting all these rainfall sensors to be on the esp board? Do you not plan to send them to HA?

when using the integration component you need to reset it yourself otherwise it continus counting forever (or until a restart if you don’t restore values). :stopwatch:

The sensor.integration.reset action is what you need - probably together with a script so you can time your hourly / daily / etc. resets :bulb:

Thanks, these examples are great.

I’m having some issues integrating this code with my current pulse_counter sensor.

template:
  - sensor:
      - name: Rainfall today
        unit_of_measurement: mm
        state_class: total_increasing
        unique_id: rainfall_today
        state: >-
          {% set count = states('sensor.rainsensor_flips') | int(0) %}
          {% set mm = count * 0.30303 %}
          {% if count >= 0 %}
            {{ mm|round(1, 'floor') }}
          {% endif %}
        # If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
        availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

How can I adapt this to be compatible with my Pulse Counter?

Also, I dont want to do any calculations in this template sensor, as the calculations are all done on the pulse_counter.

I’ve not really used template sensors before.

Thanks