Support for Environment Canada platforms

That did work, but now I’m considering keeping certain things from one, and other things from the other as the closest one that shows precipitation is actually 50km away and that makes a big difference in Alberta. Like it seems like the Blatchford station doesn’t give previous day’s rainfall (even on the website) but the integration also doesn’t show other things that the website does show, like current conditions.
sensor.condition (Blatchford) = unavailable
sensor.condition_2 (YEG) = Mostly Cloudy

Any idea why this might be?

It doesn’t look like the Edmonton Blatchford station has reported a condition for the last 24 hours (it might never), but it does report quite a few quantitative measurements: https://weather.gc.ca/past_conditions/index_e.html?station=xec. Are those showing up properly?

Good news! The PR updating the radar camera component has been merged, and will hopefully be in the next release (0.111). With this update the radar imagery is now dynamically generated and can be centered on any lat/lon you like. Specifying a location by radar station ID is still supported for backwards compatibility, but the new way is so much better!

As always, let me know if you have any trouble.

1 Like

Some data does show but not for the past 24 hours but that’s ok because I want current and future conditions to come from Blatchford. sensor.condition is a current condition, not past, correct? Past data (really, it’s only rain I care about) can come from YEG since I know Blatchford doesn’t have past rain data.

sensor.condition unknown
sensor.condition_2 Mainly Sunny

Although checking again it’s showing sensor.precipitation_yesterday as 0.0 which is interesting. It seems it shows yesterday’s rain only when there was none, but “unavailable” when it does rain.

Yes, sensor.condition is the current condition.

I’ve double-checked the sensor.percipitation_yesterday with a couple locations and it seems to be working correctly. There does seem to be precipitation data available for Blatchford as well: https://climate.weather.gc.ca/climate_data/daily_data_e.html?StationID=27214. If you see a difference between the sensor and what is shown under “Yesterday’s Data” at https://weather.gc.ca/city/pages/ab-50_metric_e.html please let me know.

The new radar component has shipped with 0.111. It seems to be working, but let me know if you have any trouble.

It’s working well for me.
I only wish there would be a speed option for radar animation (it’s really fast now) and also option for dark map like before. I use dark theme and the new map really stands out.
Not show stoppers, just something to think about.

Thanks, I’ll add these to my to-do list. Unfortunately, I need to do a major rework to how the components are configured before I can change the configuration parameters, so it might take a while.

Hi. I updated to .111 and all works well. Here is a bit of feedback:

  • The re-centered radar image has a few spear shaped artifacts which point to the radar station being north of Montreal. Before the update, the radar station used was south west of Ottawa. We live in Johnstown on the St. Lawrence at the end of #416 due south of Ottawa. Since image re-centering is happening I wonder if data from two overlapping radar stations could be “anded” to get rid of artifacts (grin).

  • The image before update provided UTC time etc. The new image does not. There is no way to check if it is current.

  • I get the following log warning on restart (only). Running hassio supervised on a Pi4 and a reasonably fast cable internet connection.

Setup of camera platform environment_canada is taking over 10 seconds.

Again, thankyou for a useful integration.

Wes

Thanks for your feedback. To your points:

  • The image is now being constructed from a composite map layer provided by Environment Canada, so you are seeing data from both the Ottawa (Franktown) and Montreal (Blainville) radar stations. The artifacts you’re seeing are present in the imagery from the Montreal station (https://weather.gc.ca/radar/index_e.html?id=CASBV), so I don’t think there’s anything I can do to remove them.

  • I can look into adding an overlay with the timestamp to each frame, but…

  • Retrieving the dynamic images from the map servers (Natural Resources for the basemap and Environment Canada for the radar data) and compiling them into an animated GIF takes a while given the computations involved on both ends. I’m already requesting the images in parallel, but I’m open to suggestions on how to speed this up further.

Thanks again, and please let me know if there’s anything else you need.

I’ve got the timestamp and legend working, and I’ve slowed the frame rate to 5 FPS. Somehow I’ve also introduced some strangeness in the colours. Aside from that, what do you think?

test-loop

3 Likes

Hoping for some help with this error setting up camera, below. Started in 0.111, still there in 0.112.2. I am running HA Core in a venv on Ubuntu 20.04, python 3.8. Not sure why the ssl errors, this was working before 0.111. I have probably missed something obvious, but seems like it is getting banned due to too many failed connection tries.
Thanks

2020-07-04 06:49:13 ERROR (MainThread) [homeassistant.components.camera] Error while setting up environment_canada platform for camera
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/connection.py", line 361, in connect
    self.sock = ssl_wrap_socket(
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 377, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "/srv/homeassistant/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='maps.geogratis.gc.ca', port=443): Max retries exceeded with url: /wms/CBMT?service=wms&version=1.3.0&request=GetMap&layers=CBMT&styles=&CRS=epsg:4326&BBOX=41.040437611330624,-82.74605638056563,44.63771838866938,-77.83953161943435&width=800&height=800&format=image/png (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)')))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
    return fut.result()
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/environment_canada/camera.py", line 51, in setup_platform
    radar_object = ECRadar(
  File "/srv/homeassistant/lib/python3.8/site-packages/env_canada/ec_radar.py", line 88, in __init__
    self.base_bytes = requests.get(url).content
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='maps.geogratis.gc.ca', port=443): Max retries exceeded with url: /wms/CBMT?service=wms&version=1.3.0&request=GetMap&layers=CBMT&styles=&CRS=epsg:4326&BBOX=41.040437611330624,-82.74605638056563,44.63771838866938,-77.83953161943435&width=800&height=800&format=image/png (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)')))

Thanks, this is a problem with NRCan’s server, as they are using a very out of date version of TLS.

If you can, would you mind changing the value for basemap_url in ec_radar.py to read http:// instead of https:// to see if that solves the problem for you?

Yes, thanks, that allows it to load. Is there any way to change the component to provide the matching TLS version so it can work with HTTPS: ?, or is that problematic too.

It’s no problem, I’ve opened a PR to address this:

Thanks for your quick response and all your work on this component.

1 Like

how I can add the hour in home assistant ?

Hi @michaeldavie. I’ve been having an issue with the integration. It seems to happen when I am restarting home assistant several times over a short period, but it’s transient and difficult to pinpoint. On HA startup, the logs show the error below, and the integration does not get set up. The only way to get it to work is to restart (sometimes a couple of times or after waiting for a bit.

Logger: homeassistant.core
Source: components/environment_canada/weather.py:153 
First occurred: 8:17:37 AM (1 occurrences) 
Last logged: 8:17:37 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 292, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 451, in _async_add_entity
    entity.async_write_ha_state()
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 290, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/local/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 314, in _async_write_ha_state
    sstate = self.state
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/weather/__init__.py", line 188, in state
    return self.condition
  File "/usr/local/lib/python3.8/site-packages/homeassistant/components/environment_canada/weather.py", line 153, in condition
    if self.ec_data.conditions.get("icon_code").get("value"):
AttributeError: 'NoneType' object has no attribute 'get'

It would appear the integration is getting stuck on some icon parsing, which may explain why it isn’t always reproducible (if say, the weather changes prior to the next restart). Any ideas of what could be going on?

My setup: HA 0.112.5, python 3.8.3, and env_canada 0.0.39

As always, thanks for the excellent work on this integration. Use it daily!

Thanks for bringing this up. This error is caused by my code not handling a missing icon_code properly, which I can fix.

Update: I’ve opened a PR to address this issue:

1 Like

Sorry @olivierjag2, I don’t understand your question. However, if you’d like to use the update time of the the sensor or camera component in a sensor entity, you can use the updated attribute of these entities in a template. Check out these links: