I’m at a loss to explain why the statistics sensors I set up to track rainfall looking back finite periods of time from the present fail after receiving data values reliably initially. Until there was a larger number of new values it was working great. Each look back sensor was updating and then aging out the old data exactly as intended. At the point in time shown here it was behaving exactly as it was expected to be.
Then later as more rain amounts came in I could see that the rain information being sent from the ESP32 ESPHome device, just as before. But for some reason that I simply can’t figure out why, the statistics sensors stopped updating for a period of time, or would only update occasionally. The sampling_size: parameter is plenty large enough since data is received from ESPHome only once per minute. Here is a snipped for 3 of the statistics sensor code:
# Generates rain amount per last period of time - sliding window
# - sensor.rain_gauge via ESP32
- platform: statistics
name: 1h Rain Statistics
entity_id: sensor.rain_gauge
state_characteristic: total
sampling_size: 100
max_age:
hours: 1
- platform: statistics
name: 6h Rain Statistics
entity_id: sensor.rain_gauge
state_characteristic: total
sampling_size: 500
max_age:
hours: 6
- platform: statistics
name: 12h Rain Statistics
entity_id: sensor.rain_gauge
state_characteristic: total
sampling_size: 1000
max_age:
hours: 12
The rest of the entries that look farther back in time do have the sampling_size: and max_age: settings set accordingly.
It is not a matter of just some of the statistics sensors failing to see the new data, but all of them.
The ESPHome code that is supplying the data to the statistics sensor:
# GPIO contact closure - rain gauge bucket into ESP32 GPIO
- platform: pulse_counter
pin:
number: GPIO33
mode: INPUT_PULLUP
unit_of_measurement: 'inches'
name: "Rain Gauge"
filters:
# Each 0.01" (0.254mm) of rain causes one momentary contact closure
- multiply: 0.01
accuracy_decimals: 2
icon: 'mdi:weather-rainy'
id: rain_gauge
# internal: true
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
internal_filter: 13us
update_interval: 60s
The above code is outputting values every minute continuously. When it is not raining those values are 0.00000.
Here is a ESPHome log entry seen when the rain bucket had tipped once:
[14:06:21][D][pulse_counter:174]: 'Rain Gauge': Retrieved counter: 1.00 pulses/min
[14:06:21][D][sensor:094]: 'Rain Gauge': Sending state 0.01000 inches with 2 decimals of accuracy
Now what might be a factor (wondering as I’m writing this) is that the missed statistics sensor updates occurred when the above value was 0.02000 or possibly more. Anyone have specific thoughts on that? But in my manually testing values larger than 0.01000 seemed to be behaving fine.
What I can’t get my head wrapped around is how it could be working exactly as expected to, but to only fail intermittently after a relatively large number of new data samples, specifically ones with values other than 0.00. After all the 0.00 values are the vast majority over long periods of time.
Other than this issue with new data being missed after a healthy bit of new rain data, I have the rain gauge tracking and display working exactly as I intended.
Also note that I’m not interested in using Utility Meter because of the time boundaries it enforces, i.e. no way to configure it to look back some X time period from the present.
Some additional background that is mostly still current for what I’m attempting to do:
https://community.home-assistant.io/t/diy-zigbee-rain-gauge/255379/359?u=thiswaytoo