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.
Utility Meter
utility_meter:
regen_heute:
source: sensor.openweathermap_rain
name: Regen heute
cycle: daily
History Stats
- platform: statistics
name: "Regen letzte 24 Std"
entity_id: sensor.openweathermap_rain
state_characteristic: total
sampling_size: 500
max_age:
hours: 24
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.
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
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.
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
Iâm well aware of this 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.
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.
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.
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.
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.
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.