Statistics for the rain level within the last 7 days - value not correct

Hello together,

I have created an input_value which will be daily at 23:59 be filled with the current value of the day.
My goal is to have a sensor with the sum of the last 7 days to steer my irrigation system.

My code looks like the following:

  - platform: statistics
    unique_id: niederschlag_letzte_7_tage_in_mm
    name: "Niederschlag letzte 7 Tage in mm"
    entity_id: input_number.niederschlag_gestern_in_mm
    state_characteristic: sum
      days: 7
    sampling_size: 7

Within the last week there was only one day with rain:

But the sensor shows the following:

What am I doing wrong?
I have also the feeling that after home assistant reboot the value is changing …
Thank you!

Have you looked at using a Riemann sum integral sensor Helper?

It would do well on the addition of multiple days values.

You means this?

No not until now because I want to avoid to install additional things because my opinion is that the statistics is exactly what I need.

Show how you are automating this. Share your automation config.

Very likely. You probably need a better trigger or a condition to prevent restarts altering the sum.

There is not much in it:

- id: '1676360064217'
  alias: Log - Niederschlag
  description: ''
  - platform: time
    at: '23:58:00'
  condition: []
  - service: input_number.set_value
      value: '{{ states(''input_number.niederschlag_gestern_in_mm'') }}'
      entity_id: input_number.niederschlag_vorgestern_in_mm
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: input_number.set_value
      value: '{{ states(''sensor.esszimmer_esszimmer_esszimmer_regenmesser_rain_today'')
      entity_id: input_number.niederschlag_gestern_in_mm
  mode: single

Crazy, I had now installed the update, and now the value is fine again.

Just right now had a look ro utility meter and riemann…

I see no chance to use this for a 7 day period.

I think with riemann this is just not possible and with utility meter it will be ressetted to 0 after a period of time.

It won’t reset if you don’t define a cycle.

Yes thats true, but I need for my automation always the value from the last 7 days.
Do you have a recommendation maybe?
I are not 100% precent working.

With my current I think it is the best, but afte rebooting HA I got the feeling that the valuie is added twice.
Like when it is switching again from 0/null or unavailable to the last value and this is added again and so the statistics calculates it.

I just checked again, the intitial value is - initial: null

Is there a possibility to avoid that?

No, the initial value will be unknown until it is restored.

The statistics sensor needs to be fixed to ignore unknownsome value transitions.

You can open a new issue here:

Those aren‘t sensors.
All I am using are input_numbers which I am filling each night once with the last values.
I am doing this because my sensor are sending not constant updstes and so it is hard to define a valid statistics.
With 7 values within 7 days for an input_number I thoughtbit is more robust.

What I am triing also now is to create an input_number in parallel with initial=0 to avoid the double adding.

Need some weeks to test this. Because my feeling will bw that i have now less values.

Does not matter, input_numbers are restored too.

Think I got it solved!
Via initial=0