Rain in the last days

I use the OpenWeatherMap integration with hourly mode.

The integration exposes a rain sensor that, according to the documentation, it shows the “Rain volume for the last hour, mm.”

In a script I need a variable that represents the rain volume of the last X days, but I can’t figure out how to create it.

The bast would be to have the number of days as a parameter, but if it is not possible, a fixed value would be ok.

Can anybody help me?
Thank you

You can use variables in scripts that can be passed to the script when you call it:

You can use a loop to make a sum of all hourly values for the given days. The naming of the attributes in the OWM sensor should make this quite easy.

Hi Florian,
thank you for your reply.

I can’t find out how to get the “hourly values for the given days”.
The sensor.openweathermap_rain sensor just has the following attributes:

state_class: measurement
unit_of_measurement: mm
attribution: Data provided by OpenWeatherMap
friendly_name: OpenWeatherMap Rain


Ah, you’re using the official integration. It doesn’t provide the necessary data.
I use this custom component:

Thank you,
it seems interesting :slight_smile:

But it tracks only the last 5 days :frowning: Why?!

Well, for irrigation purposes it doesn’t really matter how much it rained a whole week ago. Could also be that it’s an API limitation. @petergridge can surely answer that.

If you need more, you will have to do deal with that yourself. Maybe use the old values from the recorder in a statistic sensor. Or write the values periodically into variables or text inputs.

I found a solution using the Statistics integration.

First of all I created a template sensor, just to be sure to have the entity updated once a hour even if the value do not change (the update is due to the attribute):

  - trigger:
      - platform: time_pattern
        minutes: "0" # every hour
      - name: "Rain last hour"
        state: "{{ states('sensor.openweathermap_rain') }}"
        unit_of_measurement: "ml"
          updated_at: "{{ now() }}"

Then I created the statistics sensors, to sum up the hour rain volumes:

  - platform: statistics
    name: "Rain last day"
    entity_id: sensor.rain_last_hour
    state_characteristic: total
      hours: 24
    sampling_size: 24
    precision: 0
  - platform: statistics
    name: "Rain last 2 days"
    entity_id: sensor.rain_last_hour
    state_characteristic: total
      hours: 48
    sampling_size: 48
    precision: 0

Hope this can help :slight_smile:


Hi, the API only exposed the last 5 days data. You can find the documentation on the openweathermap site.

Are you still using this? I tried setting it up with the regular openweathermap integration in hourly mode, however i am getting values that are way too high.

Yes, still using it, even if the data is not too accurate. Probably, the only way to have accurate data is to have a weather station