Measuring rain

I am making a DIY rain meter using a tipping bucket sensor. The sensor is connected to an ESP8266, and Home Assistant will get the results through MQTT. I could think of two options for the MQTT input:

  1. Within the ESP, I collect the amount rain measured, then periodically publish the result and reset the counter. The problem with this approach is that Home Assistant registers the state in the history only when it changes. So it works for displaying the amount of rain in some period, but I cannot ask questions, such as “how many rain fell yesterday”, because if the amount of rain is the same in two consecutive time periods, then the second one is not registered.

  2. When the circuit closes, I publish the amount of rain one impulse represents, then publish a 0 when the circuit opens again. This is useful for example when I publish the data to InfluxDB, so I can make aggregate queries. However, in Home Assistant, I will always get 0 as the result, and I cannot have any current aggregate results.

My question is if there is some way to aggregate data in Home Assistant? For example, one that adds all the samples for a sensor in a certain time period? I found that in the latest version, there is a new sensor called filter. This sounds promising, except that it does not support summing. Is there any other way to achive this? What are the usual practices in Home Assistant for such measurements?

I use the following sensor to track how many hours my gas boiler has been on today. I have never checked, but I guess looking at the reading at midnight each day would give me the ability to graph a daily trend.

- platform: history_stats
  name: Boiler ON today
  entity_id: sensor.call_to_heat
  state: "True"
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

So maybe check out history stats?

It could work with the 2nd approach. I could publish on/off state through MQTT, then use count to count the number of times it happened. However, I need to multiply the result with a number to get the correct reading.

Google is your friend! :slight_smile:

I think what you need is the statistics sensor.