Rain Sensor tracking

Hello,

i try to track daily precipitation for our garden irrigation using OpenWeatherMap and add it up in a variety of ways.
I have tried three different ways and also three different results.
Can someone please help me with what is the most useful and accurate way?

Here are my different ways of tracking precipitation.

  1. Utility Meter

utility_meter:
  regen_heute:
    source: sensor.openweathermap_rain
    name: Regen heute
    cycle: daily

  1. History Stats

  - platform: statistics
    name: "Regen letzte 24 Std"
    entity_id: sensor.openweathermap_rain
    state_characteristic: total
    sampling_size: 500
    max_age:
      hours: 24

  1. Input Number with automation

alias: "Bewässerung: Niederschlag Heute aufzeichnen"
description: Zeichnet den Niederschlag von heute auf
trigger:
  - platform: time_pattern
    hours: /1
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.niederschlag_heute
      value: >-
        {{ states('input_number.niederschlag_heute')|float +
        states('sensor.openweathermap_rain')|float}}

The History Stats Sensor I took from the forum, no idea if this is really true.

Greetings
Moss

I am not sure how this sensor is used but it is likely not an increasing total, it is just showing the existing/total rain for that day? If it is the total then you donot need any of the above…so I am probably not correct with my assumption?
EDIT: questioning the value of my response now :roll_eyes:

I’ve never used that sensor entity from the OpenWeatherMap integration, but it happens to be a rainy day here all day and looking at what it’s reported throughout the day it looks like it’s a forecasted total rainfall for the day. If that’s the case, skip all of the total methodologies and just grab the value at say 11:55pm each night and do with it what you like.

Predicted is not the sensor I use in my opinion, there is yes the forecast and the rain sensor, I use the rain sensor. Also the documentation says otherwise…

In that case, since the sensor is actually mm/hr (not sure why the units don’t match this nor why they would use the term ‘volume’ for a distance measurement), I would probably try an integration helper. You might need to use a template sensor first to get the units corrected.

Honestly though, I wouldn’t really expect that to correlate super-accurately to the actual rainfall. Have you looked to see if there are any other weather integrations that report daily totals directly? Admittedly, I’ve never looked at any of the ‘actual’ values from a weather integration as I have my own weather station, but I would think some would.

I will also switch to my own weather station, is simply the best way to control automations for various devices with weather dependence

But still I can not understand the different results of my three variants since all the same sensor dry.

They’re completely different methodologies, so it would be expected that they’d yield different results.

To be honest, I don’t really understand the purpose of that sensor/value being reported by OWM. I’ve seen rain rates reported in in/hr (or mm/hr) for say the last minute (so you get an idea of how much it’s currently raining). But a rolling total from the last hour doesn’t seem very useful outside of (did it rain much the last hour?).

(Off topic but explanatory) It is quite common to use ‘mm’ or ‘inches’ to describe how much rain has fallen.
What you need to realise is that there is an implied ‘per square metre’ when they refer to ‘mm’ (and similar for the old imperial measurements).
Susan

1 Like

I’m well aware of this :wink: and is how I assume it is handled worldwide.

My issue/confusion was why the the units are listed as mm instead of mm/hr (since that’s what it actually is and is how rain rate is typically labelled) and why it’s explicitly defined as volume (despite using units of mm and the implied ‘per unit of area’ still not making it a volume measurement). It’s just inaccurately labelled and defined which I found odd.

The utility meter resets at midnight. The statistics sensor has a buffer if 500 measurement over a running 24 hours. The third is just something different entirely.

Thanks for the replies, but unfortunately I am still in the dark as to what is the best or “correct” way to track rain per day.
Regardless of the fact that the result can of course only be as good as the output values or accuracy of the rain sensor I use.
But even if I switch to a weather station, I will then need a meaningful way to track the rain.

Does no one here in the forum track the rain and is sure to have found a correct way?
Thank you for your time and answers, it’s just very important to me to do the whole project the right way.

Greetings
Moss

I’m assuming the rain sensor updates every hour with the rainfall total from the previous hour. So if you want total daily rainfall from 00:00-23:59, you’d have to take sensor data reported from 01:00-00:59. But I’m going to assume you’re not that picky because that would make everything more complicated.

If you want to use the utility meter method, your will need to set delta_values: true since your source sensor is not always increasing.

utility_meter:
  regen_heute:
    source: sensor.openweathermap_rain
    name: Regen heute
    cycle: daily
    delta_values: true

For history stats, the code you had will show you a running total of the last 24 hours. So if the current time is 12:35, the sensor will report the rainfall total from 12:35 yesterday until 12:35 today. That is distinctly different from the rainfall between 00:00 today until 12:35 today. Another downfall of the statistics platform is that it uses data from the recorder database, and the recorder database doesn’t store repeated values. So if there were was total rainfall of 3mm one hour and then 3mm the next hour, that second data point doesn’t get stored (unless there are attributes in that sensor that are changing). Ignoring the repeated value flaw, the code should be:

- platform: statistics
    name: "Regen letzte 24 Std"
    entity_id: sensor.openweathermap_rain
    state_characteristic: total
    start: '{{ today_at("00:00") }}'
    duration:
      hours: 24

If you want to go the automation route, you may have issues with timing between source sensor updates and and the execution of your automation. So your total may or may not be offset by an extra hour more than you were expecting. And if the update timing of the rainfall sensor varies, you may sometimes pick up the value of the previous hour twice and miss the next hour. Alternatively you could use a state trigger instead of the time-based trigger, but then we have the same issue as the repeated values where if the rainfall is the same for two hours then there is no state change.

The only change to your code would be to add a trigger at midnight and reset the value to zero. You can use trigger_id for each trigger and a choose block to pick the correct action based on the trigger. Or just have two completely separate automations.

Wow that’s what I call clarification, thank you very much for that.

But the statistics Sensor dosn’t work

Invalid config for [sensor.statistics]: [start] is an invalid option for [sensor.statistics]. Check: sensor.statistics->start

Greetings
Moss

my fault. I got confused between the platform: statistics and platform: history_stats.

The statistics platform doesn’t accept templating on max_age, and therefore can’t be used to get a look at a window that starts at a fixed time every day. The history_stats platform does allow for this, but doesn’t have functionality to count the total over a period.

So this option is not going to work for you.

ok, I spent a little more time looking into this because I happen to be running the OpenWeatherMap integration. Turns out that the rain sensor provided by this integration should actually be units of mm/hr, and it reflects the average rain rate since the last update. And that seems to be every 10 minutes, at least in my case. I filed a bug report on this.

So you could use the reimann sum integration to calculate total rainfall:

# Example configuration.yaml entry
sensor:
  - platform: integration
    source: sensor.openweathermap_rain
    name: OpenWeatherMap Total Rain
    unique_id: openweathermap_total_rain
    round: 2
    method: left
    unit_time: h

That will give you a sensor that tracks total rain and never resets to zero. To get to a daily rain sensor that starts at 0mm at midnight every night, you can then create a utility_meter sensor:

utility_meter:
  regen_heute:
    source: sensor.openweathermap_total_rain
    name: Regen heute
    cycle: daily

An alternative would be to use a different weather integration. I’m also using a custom Weather Underground integration and it has a daily precipitation sensor already included. It also has a rain rate sensor with correct units.

1 Like

Thank you for your help and time you have invested. I ordered a weather station yesterday and look at me then times the rain values as soon as I have installed the part.
Nevertheless, as already written, it does not matter whether Openweathermap or weather station, for my automations I need the sum of the daily precipitation and there it is probably if I have understood it correctly the best solution to use utility meter.

Greetings
Moss

If your weather station reports a rain rate (e.g. mm/hr) then you’ll have to calculate an integral first before you can use the utility meter.

If your weather station reports accumulated amounts (e.g. mm) at some regular interval then you can use utility meter directly.

2 Likes

You can create a Helper to do this with the “Integration Riemann sum integral sensor”.