petergridge / openweathermaphistory

A home assistant sensor that uses the OpenWeatherMap API to get forecast, current obs and history data
54 stars 5 forks source link

Manual Reload of Integration required #42

Open kellerassel007 opened 1 month ago

kellerassel007 commented 1 month ago

Last night I noticed an outage of the sensor data. It required a reload of the sensor settings and then it worked again instantly. The days before it worked without any outage, any clues?

Debug log:
2024-07-25 11:12:55.393 ERROR (MainThread) [custom_components.openweathermaphistory.sensor] 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 308, in async_update earliestdata = min(data) ^^^^^^^^^ TypeError: 'NoneType' object is not iterable

2024-07-25 11:22:55.392 ERROR (MainThread) [custom_components.openweathermaphistory.sensor] 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 308, in async_update earliestdata = min(data) ^^^^^^^^^ TypeError: 'NoneType' object is not iterable

2024-07-25 11:32:55.392 ERROR (MainThread) [custom_components.openweathermaphistory.sensor] 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 308, in async_update earliestdata = min(data) ^^^^^^^^^ TypeError: 'NoneType' object is not iterable

2024-07-25 11:41:42.077 DEBUG (MainThread) [custom_components.openweathermaphistory.data] Updating from https://api.openweathermap.org/data/3.0/onecall/timemachine? [...]

worked from here again after reload of sensor settings

kellerassel007 commented 1 month ago

My workaround is to build an automation that monitors my sensor and trigger reload in case the sensor is unavailable for at least 1 hour:

trigger:
  - platform: state
    entity_id:
      - sensor.<YOUR_SENSOR_ENTITY_ID>
    to: unavailable
    for:
      hours: 1
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - sensor.<YOUR_SENSOR_ENTITY_ID>
    to: unknown
    for:
      hours: 1
      minutes: 0
      seconds: 0
condition: []
action:
  - service: homeassistant.reload_config_entry
    data:
      entry_id: "{{ config_entry_id('sensor.<YOUR_SENSOR_ENTITY_ID>') }}"
oldgitdaddy commented 3 weeks ago

Same error here. Can someone please look into this?

petergridge commented 2 weeks ago

Hi can you let me know the following:

I can't replicate the problem on my systems:

I am using the latest BETA 2.0.14 of OWM

kellerassel007 commented 2 weeks ago

Hi can you let me know the following:

* HomeAssistant version

* OpenWeatherMapHistory Version

* What operating system and hardware you are using

I can't replicate the problem on my systems:

* RapberryPI4 and HA OS 13.0 and 2024.8 Home assistant

* Dev environment Docker/Windows

I am using the latest BETA 2.0.14 of OWM

Thanks for your support! This is a rare error, which only happened once for me in the last 2 months since I use this integration.

HomeAssistant HA OS (running virtualized on Proxmox host): Core 2024.7.0 Supervisor 2024.08.0 Operating System 12.4 Frontend 20240703.0

OpenWeatherMapHistory: 2.0.12

petergridge commented 2 weeks ago

I think I have found the issue here, the refresh rate has been published with my testing frequency. I will release a version with the normal 30 minute refresh (OWM only updated once an hour).

The only time I had a similar issue is when I exceed the allocated calls. Hopefully this change resolves the immediate issue. I also need to update the code to handle the situation more cleanly, maybe add a status value that can be displayed as a sensor.

I will publish the new version in the next day or so.

kellerassel007 commented 2 weeks ago

Thank you and keep up the great work!

petergridge commented 2 weeks ago

V2.0.15 release, only change is the refresh rate