Rain in the last days from a counter of a flipping bucket rain gauge

I have a flipping bucket rain gauge which works as a counter in tasmota, one flip equals 0.5mm of rain, the counter increments. I am trying to get a graph representing the amount of rain for every 1…3 hours.

I did this:

  - platform: history_stats
    name: rain_gauge_history_stat
    entity_id: sensor.rain_gauge_mm
    state: count
    duration: 3:00

where gauge_mm is:

 - platform: template
    sensors:
      rain_gauge_mm:
        friendly_name: "Rain gauge (mm)"
        value_template: "{{ states('sensor.weather_counter_c1') | float / 2 }}"
        unit_of_measurement: "mm"
        icon_template: "mdi:weather-rainy"

The history of the stats sensor is empty after few months. What is missing?

A start or end

a type, and a valid state. But the real issue is that History Stats is not the right sensor for what you are trying to do.

I did have “start” before, did not work either. So was the idea to set “end” to “now()” and duration for XX hours?
Anyway, what is the right sensor for what I am trying to do? Thanks.

You can use the Utility Meter integration for an hour-by-hour accumulation total or the Statistics integration for a rolling sum of differences.

1 Like

Shamelessly promoting my own integration which I believe is a really nice fit for your use case: MeasureIt

1 Like

If I understand your original goal correctly, you want to present rainfall information that is not bounded by midnight or similar chronological transitions.

You can maybe draw on this thread for ideas.
https://community.home-assistant.io/t/diy-zigbee-rain-gauge/255379

And this specific post in that thread for the approach that I took for total rainfall amounts looking back from the present for different finite time periods. The flaw of Utility Meter for this kind of use is that it is bound to fixed time periods that are defined by chronological time boundaries. For me it is far more valuable for things like rain to be presented with data looking back specific periods of time with no consideration of the midnight day crossings, or week end / starts etc.
https://community.home-assistant.io/t/diy-zigbee-rain-gauge/255379/359

But that approach bumped into a behavior of statistics and how it handles the recording of repeated values as discussed here - and with a workaround.
https://community.home-assistant.io/t/statistics-sensor-becomes-intermittent/591213

And here.
https://community.home-assistant.io/t/improved-handling-of-repeated-sensor-values-which-are-presently-ignored/637736

Since you are starting with sensor values that are only provided on a bucket tip, your configuration will be some different. My configuration provides a “measurement” once per minute around the clock, so it has days, or even weeks of 0.00 values.

It is not entirely clear to me if you will run into the same repeated values issue or not if you start using statistics. Just wanted to call attention to it in case that you do. It is a bit maddening at first trying to figure out why rain amounts get missed, and do so seemingly randomly.

2 Likes

I could not make it work - on the “Configure the periods to measure” screen there is “Select the periods you want to measure (when the meter will reset) and optionally provide other fields. Each period becomes a sensor.”, then “Unknown error occurred”, then “unit of measurements”. HA 2023.11.2.
So. Shame on you :smiley: What do I miss? I manually copied it into .homeassistant/custom_components, if that matters.

btw what the right state would be there? it is a counter, it is not on/off, or this is exactly the reason why history_stats is a wrong choice here?

You said it… “this is exactly the reason why history_stats is a wrong choice here”

Its function is to convert categorical data over time into numeric data.

For a count type History stats sensor: when the observed entity changes from any value that is not listed in state to any value listed in state, the count increments by 1. There’s almost no meaningful way to make it work with an observed entity value that is a continuously increasing numeric value.

Similarly, the time type will track the time the observed entity value is any value listed in state.

1 Like

Did you check at least one checkbox for the periods? If I don’t check any, I can reproduce the error. If I do, it works fine:


Unfortunately, it doesn’t rain at the moment :slight_smile:

It works today, I am confused as I have not done anything - no restart, no reload. Let’s see how it goes.

Trying this one with history-graph, looks ugly (I wanted bars like these utility meters end up in the Energy dashboard - these do not seem to be available as cards in normal dashboards):
image

statistics-graph is just Loading statistics... for the last day with no progress.

There are a few custom cards like Apexchart Card that can show historical and current values as bar charts. Here’s an example from my dashboard for my ac and heat runtime sensors:

image

1 Like

Nice card but no vertical bars. But it is inspired by GitHub - kalkih/mini-graph-card: Minimalistic graph card for Home Assistant Lovelace UI which seems to have it. Cool!