So I wanted to create a sensor representing how much rain has been received over the last 3 days.
I have a custom integration (Australian BoM by @bremor) that provides a sensor for rain since 9AM, and this gets reset daily.
Sounds like a perfect use for ‘state_class: total_increasing’
I set up another template sensor:
- name: "Rain total"
unit_of_measurement: mm
state_class: "total_increasing"
state: "{{ states('sensor.sydney_observatory_hill_rain_since_9am') }}"
I use a separate template sensor rather than customising the original sensor since it seemed cleaner.
I then have a sensor:
- platform: statistics
name: Recent rain
entity_id: sensor.rain_total
state_characteristic: change
sampling_size: 144
precision: 1
max_age:
days: 3
What I see is that total_increasing will set the statistical history sum to the accumulating amount, but the state gets reset each day. So it appears the statistical sensor is taking the ‘state’ rather than the ‘sum’ of the sensor.rain_total sensor, and so the 3 day calculation is incorrect.
I thought that total_increasing would set the state to the accumulating value?
So now I am quiet confused about how the ‘total_increasing’ state_class is meant to be used.
Is this only for storing in the statistical database (as ‘sum’), and is never available as a ‘state’ value?
My next step is to start looking at the code, but there’s a lot to navigate through, so hence I am asking here.