matlar
September 20, 2022, 7:58am
1
Hi,
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
Matteo
1 Like
FPro
(Florian)
September 20, 2022, 8:38am
2
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.
matlar
September 20, 2022, 8:46am
3
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
Matteo
FPro
(Florian)
September 20, 2022, 8:54am
4
Ah, you’re using the official integration. It doesn’t provide the necessary data.
I use this custom component:
matlar
September 20, 2022, 10:32am
5
Thank you,
it seems interesting
But it tracks only the last 5 days Why?!
FPro
(Florian)
September 20, 2022, 1:56pm
6
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.
matlar
September 20, 2022, 1:58pm
7
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):
template:
- trigger:
- platform: time_pattern
minutes: "0" # every hour
sensor:
- name: "Rain last hour"
state: "{{ states('sensor.openweathermap_rain') }}"
unit_of_measurement: "ml"
attributes:
updated_at: "{{ now() }}"
Then I created the statistics sensors, to sum up the hour rain volumes:
sensor:
- platform: statistics
name: "Rain last day"
entity_id: sensor.rain_last_hour
state_characteristic: total
max_age:
hours: 24
sampling_size: 24
precision: 0
- platform: statistics
name: "Rain last 2 days"
entity_id: sensor.rain_last_hour
state_characteristic: total
max_age:
hours: 48
sampling_size: 48
precision: 0
Hope this can help
6 Likes
Hi, the API only exposed the last 5 days data. You can find the documentation on the openweathermap site.
cmdr
(cmdr)
September 12, 2023, 7:54pm
9
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.
matlar
September 13, 2023, 6:39am
10
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
boelle
(Bo Herrmannsen)
June 21, 2024, 8:42pm
13
so i got this to work
only to discover that openweathermap updates rain mm/h each 10 minutes
so i guess it has to update every 10 minutes and not at minute number 0
Here is how i ended up doing the same thing
in configuration.yaml
homeassistant:
packages:
sensor_rain: !include rainmeter.yaml
sensor_rain_1h: !include rainmeter_1h.yaml
sensor_rain_24h: !include rainmeter_24h.yaml
sensor_rain_30d: !include rainmeter_30d.yaml
rainmeter.yaml
template:
- trigger:
- platform: state
entity_id: sensor.openweathermap_rain
sensor:
- name: "rain last hour"
state: "{{ states('sensor.openweathermap_rain') }}"
unique_id: "rain_last_hour"
unit_of_measurement: "mm"
attributes:
updated_at: "{{ now() }}"
that only updates when there are a change and not at fixed interval, i did it this way as who knows if openweathermap changes the interval
include rainmeter_1h.yaml
sensor:
- platform: statistics
name: "Rain during the last hour"
entity_id: sensor.rain_last_hour
unique_id: "rain_last_1h"
state_characteristic: total
max_age:
hours: 1
precision: 0
rainmeter_24h.yaml
sensor:
- platform: statistics
name: "Rain during the last 24 hours"
entity_id: sensor.rain_last_hour
unique_id: "rain_last_24h"
state_characteristic: total
max_age:
hours: 24
precision: 0
rainmeter_30d.yaml
sensor:
- platform: statistics
name: "Rain during the last 30 days"
entity_id: sensor.rain_last_hour
unique_id: "rain_last_30d"
state_characteristic: total
max_age:
days: 30
precision: 0
and yeah, not the most precise way, but then as i write we have very slow rain and openweathermap says no rain
1 Like
MateHolda
(Mate Holda)
November 12, 2024, 3:44pm
14
I also receive values that are way too high, maybe 5-10 times more than forecasted.
I see that the Openweather sensor.openweathermap_rain it updates every 10 min, so for the newly created sensor “Rain last hour” I have divided it by 6.
template:
trigger:
platform: time_pattern
minutes: “0” # every hour
sensor:
name: “Rain last hour”
state: “{{ states(‘sensor.openweathermap_rain’)| float(0) / 6 }}”
unit_of_measurement: “mm”
attributes:
updated_at: “{{ now() }}”
The rain has stopped and i cannot verify, but the values are closer to reality. For example a 1mm/hr rain is a light rain (the car wiper blades can run intermittently), while a 10mm/hr (is more of a rain-storm where wiper blades might need a 3rd speed).