home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.48k stars 30.69k forks source link

OpenWeatherMap sensor issue (?) #8640

Closed TheJulianJES closed 6 years ago

TheJulianJES commented 7 years ago

Home Assistant release (hass --version): 0.49.1

Python release (python3 --version): Python 3.5.2

Component/platform: Ubuntu 16.04 LTS

Description of problem: Sensors (OpenWeatherMap) only display "unknown" while the map works.

Expected: The sensors do display proper data.

Problem-relevant configuration.yaml:

sensor:
  - platform: openweathermap
    api_key: *********
    forecast: 0
    monitored_conditions:
      - weather
      - temperature
      - wind_speed
      - humidity
      - pressure
weather:
  - platform: openweathermap
    api_key: *********

Issue: http://i.imgur.com/kXxvzPJ.png Sensors (sensor.owm_...) do not work while the weather map works (weather.openweathermap).

Additional info: OneTwo other persons on Discord also have this error. The API key is the same for the sensor and the map (I tested multiple API keys). http://i.imgur.com/5ZQtAUS.png http://i.imgur.com/UkuS9n6.png So it seems that the issue is only present in the latest updates.

einschmidt commented 7 years ago

I experienced the same issue since version 0.49 After a downgrade back to 0.48.1 HA received information from openweathermap. After reverting back to 0.49.1 the same issue appeared again. Could it be related to https://github.com/home-assistant/home-assistant/pull/8276?

hartmms commented 7 years ago

I turned on "debug" level for the weather logger and got this below in the homeassistant.log. So I launched a python session/command line and manually loaded the pyowm module and was able to successfully call pyowm and query the weather. The below log would seem to indicate that openweather website is not responding to all site calls. I don't understand what in HA could be causing the pyowm module to time out with the HTTP call to openweaternmap's servers.

Traceback (most recent call last):
  File "/home/hartmms/.homeassistant/deps/pyowm/commons/weather_client.py", line 55, in _lookup_cache_or_invoke_API
    response = urlopen(API_full_url, None, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/openweathermap.py", line 128, in update
    self.owa_client.update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/util/__init__.py", line 303, in wrapper
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/openweathermap.py", line 189, in update
    obs = self.owm.weather_at_coords(self.latitude, self.longitude)
  File "/home/hartmms/.homeassistant/deps/pyowm/webapi25/owm25.py", line 257, in weather_at_coords
    'lang': self._language})
  File "/home/hartmms/.homeassistant/deps/pyowm/commons/weather_client.py", line 94, in call_API
    return self._lookup_cache_or_invoke_API(self._cache, url, timeout)
  File "/home/hartmms/.homeassistant/deps/pyowm/commons/weather_client.py", line 65, in _lookup_cache_or_invoke_API
    raise api_call_error.APICallError(str(e), e)
pyowm.exceptions.api_call_error.APICallError: Exception in calling OWM web API.
Reason: <urlopen error [Errno 110] Connection timed out>
Caused by: <urlopen error [Errno 110] Connection timed out>
hartmms commented 7 years ago

I did a diff of the components/weather/openweathermap.py with the previous 0.48.1 version that was reported to work. The only change was to upgrade from an older pyowm version (2.6.1) to the new one (2.7.1). However, my testing I mentioned above proves the new version works ok stand alone. This seems to indicate the problem lies outside the openweathermap.py code and something else inside HA.

hartmms commented 7 years ago

@TheJulianJES - it's not nessassary to configure both "weather" and "sensor" as you have it above. I only have the "sensor" part of the config in my setup and it still worked fine before.

hellad commented 7 years ago

I've also run into the problem with owm as soon as upgraded to 0.49 version.

fabaff commented 7 years ago

This configuration works on dev:

sensor:
  - platform: openweathermap
    api_key: !secret owm_api
    forecast: 1
    monitored_conditions:
      - weather
      - temperature
      - wind_speed
      - wind_bearing
weather:
  - platform: openweathermap
    api_key: !secret owm_api

But the data for the sensor are not instantly available. After 30 seconds or so the sensors are populated.

To be honest I have never tested the sensor and the weather platform together. Someday the weather platform will supersede the sensor implementation for the meteorological data.

hartmms commented 7 years ago

I can confirm with @fabaff's settings it works again. For me, I had to add the "forcast: 1" and "weather:" sections.

newmindJP commented 7 years ago

I had exactly the same issue - after setting forecast to 1 it works again - this is a nice workaround, but any idea why only the forecast of next 3h works instead of actual values?

hellad commented 7 years ago

I'd like also to confirm that with "forecast: 1" option sensor started to work again. Thank @fabaff for solution offered.

fabaff commented 7 years ago

I need to look into it more deeply. Perhaps we are hitting an issue with caching or something.

ekt- commented 7 years ago

Migrated from 0.35.3 to 0.50.2. Adding "forecast: 1" solved also for me No need for the "weather:" section

maweki commented 7 years ago

I am also affected with 0.52.2. Setting forecast: 1 works. But doesn't that mean we get some forecast and not the current condition?

balloobbot commented 6 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment :+1:

halfbaked commented 6 years ago

Adding forecast:1 fixed it for me. Maybe it should be added to the documentation.

maweki commented 6 years ago

Yeah, but was is the semantic of the change? Do we get other data then? Forecast for what?

0BuRner commented 6 years ago

Same for me, adding forecast:1 fixed it.

alko89 commented 6 years ago

Same issue here. Adding forecast: 1 fixes the issue.

maweki commented 6 years ago

Does anybody know what exactly that does, besides "fixing the issue"?

alko89 commented 6 years ago

It basicaly just sets the forecast to true. From the docs:

forecast

(string)(Optional)Enables the forecast. The default is to display the current conditions.

Default value: false
maweki commented 6 years ago

I did read the documentation and the semantics aren't super clear on that.

Yeah, but was is the semantic of the change? Do we get other data then? Forecast for what?

Is it tomorrow's forecast? How much forecast is it compared to current? Is it some 14-day-forecast? Is it a 0-day-forecast and we're just setting some flag? In my understanding a forecast is a guess about the weather for any number of possible times in the future.

alko89 commented 6 years ago

I admit, I don't know. I'm guessing its just the current forecast, since the value is just true or false. But I didn't check, since I don't need it. You should check the OWM API docs to find out.