Hello,
I’m trying to use OpenWeatherMap as data source to compute the rain fall over the last 24hrs. The final application would be to skip the irrigation run for the day if the rain fall over the last 24hrs is more than a certain value.
I thought this was going to be a simple thing, but I’m getting quite confused on how to achieve this.
As per the official documentation:
rain
is Rain volume for the last hour, mm.
However, looking at the data from the OpenWeatherMap rain
sensor this does not seem to be the case. Below is today’s data. The sensor updates every ~10min, it started raining at 11:20, and by 12:20 the sensor was reading nearly 0 again. If this sensor was indeed the rain volume over the last 1 hr the value should not decrease in the first hour from when it starts raining.
I suspect this is more a precipitation rate, where for example 10mm indicates that if this rain intensity continues for 1hr there will be 10mm/h of rain.
So I was thinking I could use a Riemann sum integral sensor to compute the cumulative rain:
And then to compute the rain over the last 24hrs I would need to compute the max over the last 24hrs minus the minimum over the last 24hrs of cumulative_rain
. This would mean creating a total of 4 computed sensor for this: the integral, the max over the last 24hrs of the integral, the min over the last 24hrs of the integral and their difference.
sensor:
- platform: integration
name: cumulative_rain
source: sensor.openweathermap_rain
unit_time: h
round: 1
- platform: statistics
unique_id: rain_max_24h
entity_id: sensor.cumulative_rain
state_characteristic: value_max
max_age:
hours: 24
- platform: statistics
unique_id: rain_min_24h
entity_id: sensor.cumulative_rain
state_characteristic: value_min
max_age:
hours: 24
template:
- sensor:
- name: "Rain Last 24hrs"
unique_id: rain_last_24hrs
state: '{{ sensor.rain_max_24h - sensor.rain_min_24h }}'
unit_of_measurement: "mm"
Is there a simpler way to achieve this? Am I over complicating this?