Support for Environment Canada platforms

Yes, unfortunately the changes I made in 0.115 are incompatible with the change to Python 3.8. I’ll try to work out a solution.

In the meantime, I’m using 0.114.4 of Home Assistant on Docker, with my code from 0.115 as a custom component and it’s working fine.

Regarding the the issues that folks have reported, unfortunately my ability to reproduce them is limited. There seem to be a lot of different installation environments out there, and the issues only seem to pop up in some of them. I wish I could address them all, but I’m frankly not sure how. If anyone is able to help out it would be greatly appreciated.

1 Like

Your efforts are appreciated. If I can find the time I can try to help debug the issues I was experience with the double weather platforms, but unfortunately my time is limited for this.

I’m not sure if this error is new or not, or how often it occurs, but I discovered it in the logs while trying to debug something else…

2020-11-02 21:59:28 ERROR (MainThread) [homeassistant.helpers.entity] Update for weather.richmond fails
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 309, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 164, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x7ff4cb672f70>, 'Connection to dd.weather.gc.ca timed out. (connect timeout=10)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dd.weather.gc.ca', port=443): Max retries exceeded with url: /air_quality/aqhi/pyr/forecast/realtime/xml/AQ_FCST_JBRIK_CURRENT.xml (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7ff4cb672f70>, 'Connection to dd.weather.gc.ca timed out. (connect timeout=10)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 482, in async_device_update
await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/environment_canada/weather.py", line 166, in update
self.ec_data.update()
File "/usr/local/lib/python3.8/site-packages/env_canada/ec_data.py", line 204, in res
return fun(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/ratelimit/decorators.py", line 80, in wrapper
return func(*args, **kargs)
File "/usr/local/lib/python3.8/site-packages/env_canada/ec_data.py", line 364, in update
aqhi_result = requests.get(AQHI_FORECAST_URL.format(self.aqhi_id[0],
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 504, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='dd.weather.gc.ca', port=443): Max retries exceeded with url: /air_quality/aqhi/pyr/forecast/realtime/xml/AQ_FCST_JBRIK_CURRENT.xml (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7ff4cb672f70>, 'Connection to dd.weather.gc.ca timed out. (connect timeout=10)'))

I’m running HA 0.117.2

This seems to be down with 0.118.3
Don’t see the sensor. anymore in my entities…
Is it just me or other are having same issue?
Thanks!

I’m running 0.118.3 without an issue. Could you try restarting and see if any errors are logged?

Where can I see the Log?
I restarted and still not showing up in entities.

This is what I have in my configuration.yalm

weather:
- platform: environment_canada
station: QC/s0000712

Which hasn’t been changed since it was working…

I see a bunch of entites from Environment Canada but not the weather.laval (whihc was my location). I jsut see sensors.

THanks!

Nevermind. After a second server restart it shows now…Weird.

Thanks anyway.

1 Like

Hello,

I am encountering a problem that I hope someone can help with. When I install the Environment Canada sensor platform it works perfectly. When I install the Environment Canada weather platform it too works. But, when I install both of them at the same time the sensors become unavailable.

Below is the YAML code I am using.

Thank you.

Baobab

weather:
    - platform: environment_canada

sensor:
    - platform: environment_canada

The Airing of Grievances

I’m working on a major update to the components, and would like to know if there’s anything you’d like me to include. Here’s what I’ve got on my list so far:

Done

  • Make all I/O asynchronous
  • Add tests to library
  • Use data update coordinator for sensors
  • Reduce library dependencies
  • Remove option to configure radar by station name

To Do

  • Implement config flow (configuration via UI)
    • Add config options to radar
  • Add tests for components
  • Improve error handling
  • Move AQHI to a separate component
  • Add hydrological component

A separate branch has been created for this work, so you can follow along (or contribute!) if you’re interested: https://github.com/home-assistant/core/tree/environment-canada-async-config-entries/homeassistant/components/environment_canada. You can also contribute or open issues for the library at https://github.com/michaeldavie/env_canada.

Thanks for your input and feedback.

Hello,

Thank you for your effort to make this available for HA.

Could you set up the sensor data to unknow when it’s empty string such as sensor.warnings so we can use conditional card to show it only when it’s available. currently if we set the state_not: “” (empty string) HA shows syntax error.

Could you give the sensor a parameter name, so we can setup multiple place? for example, sensor.toronro.warnings and sensor.montreal.warnings.

thank you again for your great work.

1 Like

Hello @michaeldavie,

First thank you for developing a great integration. It is my primary weather source.

Today I upgraded from Python 3.7 to 3.9 (and also the latest HA) but the environment canada integration is failing with this error:

2020-12-29 14:33:47 ERROR (MainThread) [homeassistant.components.weather] Error while setting up environment_canada platform for weather
Traceback (most recent call last):
  File "/srv/homeassistant39/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant39/lib/python3.9/site-packages/homeassistant/components/environment_canada/weather.py", line 78, in setup_platform
    ec_data = ECData(station_id=config[CONF_STATION])
  File "/srv/homeassistant39/lib/python3.9/site-packages/env_canada/ec_data.py", line 242, in __init__
    self.update()
  File "/srv/homeassistant39/lib/python3.9/site-packages/env_canada/ec_data.py", line 207, in res
    return fun(*args, **kwargs)
  File "/srv/homeassistant39/lib/python3.9/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
  File "/srv/homeassistant39/lib/python3.9/site-packages/env_canada/ec_data.py", line 343, in update
    self.aqhi_id = self.closest_aqhi(aqhi_coordinates[0], aqhi_coordinates[1])
  File "/srv/homeassistant39/lib/python3.9/site-packages/env_canada/ec_data.py", line 490, in closest_aqhi
    region_list = self.get_aqhi_regions()
  File "/srv/homeassistant39/lib/python3.9/site-packages/env_canada/ec_data.py", line 481, in get_aqhi_regions
    _children = region.getchildren()
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

I found this in the Python docs indicating that the getchildren() method was removed in Python 3.9 and I think that is the problem: https://docs.python.org/3.8/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.getchildren

Please let me know if this is something you can fix? Thanks again.

@michaeldavie I fixed the problem by changing the following line in the ec_data.py file

from: _children = region.getchildren()
to: _children = list(region)

Seems to work fine now.

Thanks, I’ve pushed a new version of the library to correct this. Would you mind modifying the manifest.json of the component to use version 0.2.5 and confirm that it works for you on 3.9?

Edit: I’ve opened a PR with this fix

Sure I have updated the manifest.json, restarted HA, and confirmed your update was installed. Seems to be working fine. I’ll let you know if I encounter any issues. Thank you for fixing this so quickly.

1 Like

Hi

Why sometime my sensor don’t update for few hour ? Exemple Last night, I don’t Receive any update for my temperature sensor for 5 hours

1 Like

image

this is the exemple in picture
my sensor update there is 3hour ago and on environment canada website, the update is make at 6 AM

(time right now : 6h48)

thx

also:

last update at 4:16:08
image

Do you have idea?

I think this might be related to rate limiting, but I’m not sure. Please try setting the scan_interval to something longer like 10 minutes and let me know if that helps. The link below has more info.

scan_interval is already set to 600 for me (10 minutes) and I still find the sensors often take many hours to update (though the weather platform updates hourly as expected)

Additionally today I found that although the weather platform shows a temperature of 0 (which sounds right today) the sensor.temperature is showing “unkown”.

I really want to use environment Canada weather information in Home Assistant. But the sensor component is basically unusable in this integration as it is frequently subject to very lengthy delays and often disagrees with the weather platform.

I’m sorry you’re having so much trouble. I’ve made a number of improvements to the component but I can’t merge them into the project until I’ve also reworked everything to support configuration via the GUI. Unfortunately, I simply don’t have the time to tackle that at the moment.

In the meantime, I suggest using the latest revision as a custom component, which is what I am doing on my own instance at home. The latest version can be found here:

Please let me know if you have any trouble.