Increment Received Rainfall from Cumulative Sensor

I am receiving rain data from my weather station via rtl_433. All is going well except for the fact that the station only reports the accumulated rain since it was last powered on (491.8mm currently).

I want to create a sensor that resets to 0.0mm at midnight each day and then increments if/when my rain sensor (sensor.bresser_6in1_0_860321798_rain_total) value increases.

An example would be:

  1. sensor.bresser_6in1_0_860321798_rain_total starts at 491.8mm and sensor.rainfall_accumulated_change starts at 0mm.
  2. sensor.bresser_6in1_0_860321798_rain_total increases to 492.8mm, then sensor.rainfall_accumulated_change new value should be 1mm.
  3. sensor.bresser_6in1_0_860321798_rain_total then increases from 492.8mm to 592.8mm, therefore sensor.rainfall_accumulated_change new value should be 101mm.

I hope this makes sense.

I tried this in the template editor, including changing the state of sensor.bresser_6in1_0_860321798_rain_total from 491.8 to 492.8 beforehand:

sensor:
  - platform: template
    sensors:
      rainfall_accumulated_change:
        friendly_name: "Rainfall Accumulated Change"
        value_template: >
          {% set current_rain_total = states('sensor.bresser_6in1_0_860321798_rain_total') | float %}
          {% set last_rain_total = state_attr('sensor.rainfall_accumulated_change', 'last_rain_total') | float(default=0) %}
          {% set accumulated_change = current_rain_total - last_rain_total %}
          {{ accumulated_change }}
        attribute_templates:
          last_rain_total: "{{ states('sensor.bresser_6in1_0_860321798_rain_total') }}"

I received this output:

sensor:
  - platform: template
    sensors:
      rainfall_accumulated_change:
        friendly_name: "Rainfall Accumulated Change"
        value_template: >
          
          
          
          0.0
        attribute_templates:
          last_rain_total: "492.8"

This recognises the last rain total correctly but does not increment the value.

Feed your sensor.bresser_6in1_0_860321798_rain_total sensor to a utility meter helper with a daily cycle:

Make sure to set the periodically_resetting option to true so you don’t get erroneous results if you power cycle the rain gauge.

1 Like

Thank you, I had considered this but assumed that whilst utility Meter would start at 0 the value would jump to the total accumulated rain, e.g. 492.8, as soon as rainfall is detected.

It shouldn’t.

The helper only updates when changing from one number to another. Changing from unknown to a number (like when the helper is first created) does nothing.

And the helper only accumulates changes in value.

So…
at helper creation, unknown → 492.8 : do nothing but note the current value internally, output set to 0

0.2mm of rain occurs, 492.8 → 493.0, output set to 0.2

1 Like

That is perfect, thank you so much for helping me out.

1 Like

It won’t. I have a Utility Meter setup exactly the same way @tom_l describes, and it resets at midnight every day.

The sensor it references is always increasing. The Utility Meter will only count the change, not the baseline number.

This is what the Utility Meter data looks like in practice (and yes it’s been rainy)

In the same period, this is what the rain sensor looks like

1 Like

That’s great, thank you for the example. You certainly have had a bit of rain.

It’s typical, I may have just gotten this working and now we are going into a sunny period!