Custom Component to retrieve five days of rain history from OpenWeatherMap

This is taking the max of the calculated value or 0 as the calculated value could go below 0.

Checkout Template Designer Documentation — Jinja Documentation (3.2.x) for more information

Got it - thank you a lot!

Thank you for this integration, I have it working with my node-red flows to check the factor to decide whether to water today or not. I already had the flows configured so didn’t go with your irrigation cards, but I was wanting a smarter way to decide if to water or not by simply looking back at yesterday and if it rained enough…well… Your “factor” appears to be even more thorough however am still trying to organize my brain into its logic. I understand the levels of importance etc, however the “factor” number the results means what? You set it to measure from 10mm and subtract the various values but lost on why you then divide by 10. Is that to average? Anyway my simple mind assumes that if “factor” is greater than 0 then you haven’t had enough rain equivalent to 10mm, and if the value is less than 0 (which returns 0) then no need to water. Seems strange as I understand the point just not the value.

Thanks to anyone who has time to explain to my brain the logic its missing.

The 10mm is arbitrary, I find it easier to work in 10,100…

The factor is simply a number that will be multiply against the watering time/volume.
So 0 represents there has been enough water so don’t water
1 is it has/will not rained so water fully, also if you extend the logic to include temp and it has been very hot you can have a factor of 1.1 to water more on those hot days.
The values between 0 and 1 reduce the amount of water to top up your plants as there may of been a small shower and they need water.

If you want to simply turn on/off watering you can develop your template to return true or false and have a binary sensor. Though I have not tested this so I may need to update the component to support this as a change.

The open weather history just records and exposed data so you can get creative :slight_smile:

I hope this helps.

ok thankyou I wasn’t thinking along the lines of using it to adjust the amount of water… I hadnt clued into using the factors value more than just to water of not. Thanks for they ideas I shall get to work. And thanks again.

Hello all,

Could someone give me a little guidance as how to fix these errors in my home assistant log that are related to OpenWeatherMap HIstory?

It looks like my sensors are loading values from the integration but I am still seeing these errors in my log. Thank you all so much for your help with this!!

This error originated from a custom integration.

Logger: custom_components.openweathermaphistory.sensor
Source: helpers/update_coordinator.py:312
integration: OWM History (documentation, issues)
First occurred: June 8, 2024 at 10:00:46 PM (1 occurrences)
Last logged: June 8, 2024 at 10:00:46 PM

Unexpected error fetching openweathermaphistory data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openweathermaphistory/sensor.py", line 107, in _async_update_data
    await self._weather.async_update()
  File "/config/custom_components/openweathermaphistory/weatherhistory.py", line 301, in async_update
    historydata = await self.get_historydata(historydata)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openweathermaphistory/weatherhistory.py", line 347, in get_historydata
    hourdata = await self.gethourdata(lastdt)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openweathermaphistory/weatherhistory.py", line 407, in gethourdata
    data = self.validate_data(rest.data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openweathermaphistory/weatherhistory.py", line 88, in validate_data
    jdata = json.loads(data)
            ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
This error originated from a custom integration.

Logger: custom_components.openweathermaphistory.data
Source: custom_components/openweathermaphistory/data.py:62
integration: OWM History (documentation, issues)
First occurred: June 8, 2024 at 10:00:46 PM (1 occurrences)
Last logged: June 8, 2024 at 10:00:46 PM

TimeoutException fetching data: https://api.openweathermap.org/data/3.0/onecall/timemachine?lat=36.22772&lon=-83.31848&dt=1717898400&appid=REDACTED&units=metric failed with
day0rain: 2.03
day1rain: 0
day2rain: 0
day3rain: 0
day4rain: 0.49
attribution: Data provided by OpenWeatherMap
friendly_name: rainfactor2

Hi, this is a result of a timeout when calling the OWM api, it happens occasionally if OWM is not available or there are hiccups on your internet connection.

I thought I handled the error better that that with a more friendly message. I will revisit that in my next iteration. It is difficult to emulate all the various failures that can happen on the net, at least for me.

Cheers
Pete

@petergridge No problem. Thank you for your response and thank you for what you have built and shared with others!!

1 Like