Error setting up "Environment Canada" weather component

My environment Canada weather component hasn’t been working for the past few weeks and I’m not sure what’s causing it. I’m getting the following error:

Logger: homeassistant.components.weather
Source: components/environment_canada/weather.py:164 
Integration: Weather (documentation, issues) 
First occurred: 3:51:19 PM (2 occurrences) 
Last logged: 3:51:20 PM

Error adding entities for domain weather with platform environment_canada
Error while setting up environment_canada platform for weather
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 615, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 368, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 402, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 374, in _stringify_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/weather/__init__.py", line 206, in state
    return self.condition
  File "/usr/src/homeassistant/homeassistant/components/environment_canada/weather.py", line 164, in condition
    elif self.ec_data.hourly_forecasts[0].get("icon_code"):
IndexError: list index out of range

Any idea what might be causing this? Am I right is assuming that the “icon” code isn’t being returned correctly and is causing the error?

I’ve been having the same issue and same error log entry. My weather.richmond has gone AWOL.

weather:
  - platform: environment_canada
    station: BC/s0000141
    forecast: daily
Error adding entities for domain weather with platform environment_canada
Error while setting up environment_canada platform for weather
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 666, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 419, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 453, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 425, in _stringify_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/weather/__init__.py", line 243, in state
    return self.condition
  File "/usr/src/homeassistant/homeassistant/components/environment_canada/weather.py", line 164, in condition
    elif self.ec_data.hourly_forecasts[0].get("icon_code"):
IndexError: list index out of range

In both cases, it is attempting to get the value of icon_code for the first hour of the hourly forecast. However, it seems like the first hour’s forecast doesn’t exist because the zeroth (first) item in the list is ‘out of range’.

Whenever it happens again, check the weather entity’s hourly forecast attribute and see if it contains any data. If it doesn’t then there’s the cause of the problem.

I created an Environment Canada integration for another home automation software a decade ago. Based on what I have seen, sometimes the received data can be missing a few things (and the only way you know if that’s possible is when you encounter it) so when the code accesses the data it has to gracefully handle the possibility it doesn’t exist.

I also experienced cases where data that is normally numeric is reported as something non-numeric. All this to say that the format of EnviroCan’s data can be a source of surprises. :slightly_smiling_face:

So it sounds like this is a bug that I should submit to the tracker then?