Environment Canada integration - 2021.11 onwards

Thanks! That is cool.

1 Like

I like the look of that.

I’d like to see the rest of the HTML for the card if you don’t mind.

In the same vane (weather vane I suppose if you like :rofl: ) I came upon this templated sensor in reddit to show advisories etc

template:
   - sensor:
   - name: weatheralerts
     state: >
       {% for type in ['statements', 'advisory', 'warnings', 'watches' ] %}
       {% if states('sensor.barrie_' + type)|int > 0 %}
       {% for index in range(states('sensor.barrie_' + type)|int) %}
         {% set timestamp =  strptime(state_attr('sensor.barrie_' + type, 'alert_time_' + (index+1)|string), '%A %B %d, %Y at %H:%M %Z') %}
         ## [{{ state_attr('sensor.barrie_' + type, 'alert_' + (index+1)|string) }}](https://weather.gc.ca/warnings/report_e.html?on18)
         *Issued on {{ as_timestamp(timestamp) | 
         timestamp_custom('%A, %-d %B %Y at %-I:%M %p', true, '')  }}*.
        {% endfor %}
      {% endif %}
    {% endfor %}

The formatting isnt working for me though and I cant get it to pass muster in the check my yaml before a restart. I thought I would take another crack at setting up a tts announcement or push notification for this. Seems like a good place to start would be a sensor.

Here you go! Really didn’t want to dump a 127 line code block into a forum thread, so I just uploaded it all to github.

1 Like

Thanks for that.

Haven’t got it to work yet (I’m running the container version of HA), but will keep poking away at it.

throwing this template in the dev/template

What is the problem, doesn’t the container version work with custom cards?

Keep in mind that if any of the sensors are wrongly spelled or doesn’t exist, the card might not render at all (I tried myself and took some minutes to figure that out). I thought that errors would show up in HTML, but it would ultimately render something, however it is not always that way, if the template fails to evaluate a “if” statement for instance, the entire content of that “if” block is not rendered.

@Techdisk thanks for sharing, great work.

Hi,

Have there been any changes? Integration no longer seems to support accents in French


1 Like

FWIW, I noticed what I believe may be a related problem. I attempted to install the Environment Canada integration for a city whose name contains accented characters and the installation failed.

I chose to have the weather data displayed in English but that had no impact; the installation failed.

Tested with version 2023.3.3.

No changes of late. What station failed?

It looks like Environment Canada changed their XML encoding. PR submitted.

Have noticed an issue with humidex and wind chill data the past month or so, in that the entity continues to report data even though there should be no humidex (temp is below 20C) or wind chill (temp is above 0C). Basically, the entity appears to be ‘stuck’.

For example, right now (2023-04-13 9:34 am) the humidex entity for Windsor ON is showing 21 in HA, but the current conditions at weather.gc.ca show no humidex.

Home Assistant 2023.4.2

Seems something is off with the latest update to the integration.

All of the temperature related values are showing zero for me

Temperatures are zero for me to.

Mine are working fine except the forecast expectation for precipitation for current day. That hasn’t been working since started looking more carefully at this integration over the last week. Is that something we need to fix on HA side or Env Canada side (e.g., is it the recent XML format change @ michaeldavie mentioned)?

Noticed this in my logs today my have been there before but can’t be certain.

Logger: homeassistant.components.environment_canada
Source: components/environment_canada/__init__.py:117
Integration: Environment Canada (documentation, issues)
First occurred: 1:39:06 PM (1 occurrences)
Last logged: 1:39:06 PM

Unexpected error fetching environment_canada weather data: Weather update failed; could not parse result
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/xml/etree/ElementTree.py", line 1713, in feed
    self.parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1035, column 11

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/env_canada/ec_weather.py", line 362, in update
    weather_tree = et.fromstring(weather_xml)
  File "/usr/local/lib/python3.10/site-packages/defusedxml/common.py", line 126, in fromstring
    parser.feed(text)
  File "/usr/local/lib/python3.10/xml/etree/ElementTree.py", line 1715, in feed
    self._raiseerror(v)
  File "/usr/local/lib/python3.10/xml/etree/ElementTree.py", line 1622, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1035, column 11

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 250, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/environment_canada/__init__.py", line 117, in _async_update_data
    await self.ec_data.update()
  File "/usr/local/lib/python3.10/site-packages/env_canada/ec_weather.py", line 364, in update
    raise ECWeatherUpdateFailed("Weather update failed; could not parse result")
env_canada.ec_weather.ECWeatherUpdateFailed: Weather update failed; could not parse result

It’s hopefully fixed by this PR: Bump env_canada to v0.5.33 by michaeldavie · Pull Request #91468 · home-assistant/core · GitHub. The EC changes have certainly tested the limits of the code!

2 Likes

Thank you, I look forward to this ending up on my system.

The issue of numeric sensor values being 0 has been fixed in 2023.4.5.

3 Likes

Environment Canada out again for me today, not sure if anyone else has thus problem.

It’s working for me. Do you see anything in the log?