Support for Environment Canada platforms

All you should need is:

sensor:
  - platform: environment_canada

Do you see any errors in the logs?

I apparently am having an issue too with this sensor platform. I have been using environment_canada for a while now without issue but today I am getting this in my logs.

2021-03-11 15:17:14 ERROR (MainThread) [homeassistant.components.weather] Error while setting up environment_canada platform for weather
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 200, in _async_setup_platform
await asyncio.shield(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 78, in setup_platform
ec_data = ECData(station_id=config[CONF_STATION])
File "/usr/local/lib/python3.8/site-packages/env_canada/ec_data.py", line 242, in __init__
self.update()
File "/usr/local/lib/python3.8/site-packages/env_canada/ec_data.py", line 207, 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 257, in update
weather_tree = et.fromstring(weather_xml)
File "/usr/local/lib/python3.8/xml/etree/ElementTree.py", line 1321, in XML
return parser.close()
File "<string>", line None
xml.etree.ElementTree.ParseError: unclosed token: line 846, column 1

Configuration is as follows…

weather:
  - platform: environment_canada
    station: "ON/s0000573"
    scan_interval: 300

This looks like a problem with the XML file that Environment Canada is publishing. I just tested this station with the env_canada Python library and it worked without issue; are you still having this issue or was it resolved?

Edit: If this error occurred on startup you may need to restart.

1 Like

Looks like a restart corrected this.
Thanks,

1 Like

I tried that several time, It look like at one time I did added all the entity but in English. Using th UI I deleted all the entity so I can added them back in French, since then I cannot add them anymore.

The log don’t show nothing about this integration

2021-03-12 16:13:57 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.environment_canada

Does that have something to do with this old issue?

i do have two weather

###### Environnement Canada

  - platform: environment_canada
    name: Peloquin
    latitude: !secret latitude_peloquin
    longitude: !secret longitude_peloquin

  - platform: environment_canada
    name: Chalet
    latitude: !secret latitude_chalet
    longitude: !secret longitude_chalet

Yep it’s exactly that… if I remove one instance of the Weather, all the sensors work properly.
Even worst, only one of the sensor instance is working.
Is there anyway to solve this problem?

For those of you using the custom component, I’ve released v0.3.2 of the env_canada library with some fixes to the radar image, including transparency, a smaller file size, and a fix for the colours shifting around between frames. To update just modify the library version in the manifest.json file and restart.

Let me know if you have any trouble.

fixed_loop

I am continually getting a warning message in my logs with the following:

WARNING (SyncWorker_16) [env_canada.ec_data] Unable to retrieve weather forecast: HTTPSConnectionPool(host='dd.weather.gc.ca', port=443): Max retries exceeded with url: /citypage_weather/xml/BC/s0000141_e.xml (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fd094b8ab80>: Failed to establish a new connection: [Errno -2] Name does not resolve'))

Using the ‘Terminal & SSH’ supervisor addon, nslookup returns the IP address 205.189.10.47 which leads to https://dd.weather.gc.ca/.

Any ideas as to why I might be seeing this?

Any update on getting the Sensors to work reliably for those of us who don’t have more than one of the platform in our configs?
The sensors continue (as they always have) to often lag several hours behind the forecast card.

@ve6rah Which version of the component are you running?

According to home assistant configuration and supervisor my installation is fully up to date. However as this component has neither an add-on or an integration that show up in the web front end, I have no idea how to check what version number.

Hello. I noticed over the last couple days my Environment Canada weather card won’t load up.

Logger: homeassistant.components.weather
Source: components/environment_canada/weather.py:164
Integration: Weather (documentation, issues)
First occurred: 3:57:32 PM (2 occurrences)
Last logged: 3:57:32 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 322, in async_add_entities await asyncio.gather(*tasks) File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 514, in _async_add_entity await entity.add_to_platform_finish() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 547, in add_to_platform_finish self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 310, in async_write_ha_state self._async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 334, in _async_write_ha_state sstate = 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 ideas?

Garry

I’m rebuilding my HA setup from the ground up and I am having problems getting the Environment Canada Radar setup.

If I specify a station with:

  - platform: environment_canada
    station: CASFT

I get the following error:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 205, in _async_setup_platform
await asyncio.shield(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/camera.py”, line 42, in setup_platform
radar_object = ECRadar(
File “/usr/local/lib/python3.8/site-packages/env_canada/ec_radar.py”, line 102, in init
coordinates = get_station_coords(station_id)
File “/usr/local/lib/python3.8/site-packages/env_canada/ec_radar.py”, line 38, in get_station_coords
return site_dict[station_id][“lat”], site_dict[station_id][“lon”]
KeyError: ‘CASFT’

It doesn’t matter what station values I enter, it’s the same error except the KeyError changes to reflect the station I enter.

If I leave out the station line I get the Radar entry but either it times out with a warning in the log, or the card doesn’t display the image. The only way I seem to be able to get the Radar image to work (when there is no warning in the log) is to edit the Dashboard and then close the Dashboard.

I am runinng Home Assistant 2021.4.6 in docker.

It looks like the radar_sites.json file in the component hasn’t been updated with that new radar station code even though the old one is now decommissioned. If you can edit the JSON you can try just updating the station code.

Otherwise opening an issue on his GitHub repo to update the radar code and the HA wiki page would be a good idea.

I’m no longer supporting the station codes (or at least not updating the list or adding new ones), since the map is now dynamically generated for any arbitrary location. If you specify a latitude and longitude you should be all set; the default is to use the HA server settings if no location is specified.

Either of these should work fine:

camera:
  - platform: environment_canada
camera:
  - platform: environment_canada
    latitude: 50
    longitude: -100

Let me know if you have any trouble.

Wanted to share how I managed my radar cards to have rain vs snow. The default of Nov - Apr is less and less relevant given the weather extremes we have.

I used a conditional card to show rain vs snow, but conditional cards need a state, which I didn’t seem to have. So i created a binary sensor in my config.yaml to determine if i could expect rain or snow.

binary_sensor:
  - platform: template
    sensors:
       freezing_point:
         friendly_name: freezing_point
         value_template: >-
           {% set F0 = states('sensor.temperature') | int %}
           {% set F1 = states('sensor.low_temperature') | int %}
           {% set FP = (F0 + F0 + F1) /3 | int %}
           {% if FP < 2 %} on
           {% else %} off
           {% endif %}

This weights the current temp a bit more than the low, since the radar only goes 3 hours in advance. I’m not sure how well it will work when we get closer to winter but we shall see.

Then i created a conditional card to use my binary sensor.

type: vertical-stack
title: EC Ottawa Weather Radar
cards:
  - type: conditional
    conditions:
      - entity: binary_sensor.freezing_point
        state: 'on'
    card:
      type: picture-entity
      entity: camera.radar_snow
  - type: conditional
    conditions:
      - entity: binary_sensor.freezing_point
        state: 'off'
    card:
      type: picture-entity
      entity: camera.radar_rain

I have been using this integration for a number of months and haven’t knowingly updated so I’m not sure if my radar reflects the new changes that have been made. I’m using this in my config:

camera:
   - platform: environment_canada
     station: XFT
     precip_type: RAIN
     name: radar-rain
   - platform: environment_canada
     station: XFT
     precip_type: SNOW
     name: radar-snow
1 Like

Would anyone mind sharing how they went about using the “custom component”? I’m a bit stumped on this one.

Is it best to just fork the repo and copy the relevant files to a custom_components folder?

Sorry if this is way off base but I’m a little shaky on the software side of things.

I found a tool to download the folder as a ZIP file. If you copy the environment_canada folder from the ZIP file into the custom_components folder, you should be all set.

GitZip: GitZip
Github Folder: home-assistant/homeassistant/components/environment_canada at env_canada_0-3-0 · michaeldavie/home-assistant · GitHub

Let me know if you have any trouble.

Awesome! Thank you! I’ll give it a shot.

Logger: homeassistant.components.weather
Source: components/environment_canada/weather.py:164
Integration: Weather (documentation, issues)
First occurred: 8:27:07 AM (2 occurrences)
Last logged: 8:27:07 AM

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

It seems like the hourly_forecasts list was either missing or empty because attempting to get its zeroth item resulted in failure. Perhaps the weather location you are using didn’t have hourly forecast data at the time it was polled.