Environment Canada integration - 2021.11 onwards

Hi and thank you for your work on this great integration.
Everything is working fine beside the summary sensor have the text cut off. When the text of the summay sensors has a longer text, it’s cut off on the sensor itself as show in the development tools and reflected on the markdown card.

The cut off text is a Home Assistant limitation where state text is limited to 255 characters.

Thank you for the info

Please note that radar is currently broken due to a change to the data source made earlier today. You can track the related issues below.

This issue has been fixed in the 2023.02 release, and the radar now has 6-minute granularity.

I’ve had an ongoing issue here, almost certainly caused by the EC servers themselves, where every so often the integration would update with data that’s older than what’s already there.

For example, the previous data would have been updated as of 14:00, and then after a refresh the integration would suddenly show data as of 10:00. Very annoying.

I set up a complicated network of automations that would detect when a new observation time is older than what was there previously (i.e. previous timestamp > new timestamp) and then immediately start to refresh the data over and over until it gets a later timestamp, indicating a more correct dataset. Time should only go up, after all.

Until now I’ve kinda just dealt with the random blips in my historical data where the temperature (and everything else) would jump or plummet for a couple seconds due to bad data, but as of 10 AM yesterday this issue has suddenly become FAR worse. I’m now having my data jump back to 10 AM on February 3rd almost every single time a refresh happens, meaning that my weather fix automation needs to keep activating to fix it, and also meaning that my historical data is a complete mess of random spikes:


The “weather update delta” is simply the current time minus the value of the observation timestamp; as you can see, the spikes are showing the error increasing as EC decides to take a trip in the DeLorean back to yesterday.

image
And this is my historical data as a complete mess. Yes, I do calculate my own wind chill value from the data instead of using EC’s directly.

Is there any way to make the integration do a quick check and ensure that the data it’s receiving from EC isn’t obviously wrong? i.e., ensuring that the timestamp always increases? Not sure if it’s possible for an integration to read historical (or even current) data, but if it is possible it would be as simple as checking if the observation timestamp associated with the value received from EC is greater than or equal to the timestamp of the data that’s already received.

I’m pretty sure this is a server issue because before I used home assistant, I put together my own python script to scrape the EC RSS feed for weather data which would be outputted to an Arduino display. I had to deal with the same issue of bad data with that, which I solved by checking the new timestamp against the old one and throwing out data that didn’t make sense.

(also yes I know I could have used an actual EC library with that old python script instead of RSS, but I was dumb and I don’t use that script anymore anyway)

Just noticed over the past 2 or so days, that the integration is flipping between current weather & forecast data and past weather & forecast data - eg. It’s sunny with absolutely no clouds for the past 4 hours but the forecast flips from Sunny to Partly Cloudy. The temp and all other attributes flip back and forth as well.

This happens mostly in 5, 10 or 15 minute intervals. I’ve deleted the integration and added it back with no resolution.

WIndsor, ON weather station.

I’m on 2023.2.1 of HA.

Well, good to know I’m not alone, lol.

1 Like

I can confirm that recent EnvironCan weather warnings (notably the cold weather warning) have screwy timestamps. Today I observed one warning labeled as ‘Today 5:06 AM’ shortly followed by an identical one labeled as ‘Yesterday 5:06 AM’.

To be clear, this is EnviroCan’s screwup (their software is reporting the wrong data).

FWIW, I’ve been using EnviroCan’s data long before Home Assistant existed and I can confirm that its reported values often adhere to a specific format … but not always. I think the first example I encountered was a non-numeric humidity value. Today’s time-travelling timestamp is just another one of those anomalies.

2 Likes

Completely unrelated to the timestamp issue, I wanted to put my spin on displaying the warnings through templates:

{% if not is_state('sensor.warnings', '0') %}
{% for num in range(1,int(states('sensor.warnings'))+1) %}
  {{ state_attr('sensor.warnings',"alert_"~num) }} in effect. ({{ as_timestamp(strptime(state_attr('sensor.warnings',"alert_time_"~num), '%A %B %d, %Y at %H:%M %Z')) | timestamp_custom("%H:%M")}})
{% endfor %}
{% endif %}

This setup is unlimited in terms of the number of alerts it can display; if it’s the apocalypse and you have 25 alerts, this will display all 25.

The example is unformatted because I have this set up in a custom HTML card and I’ve removed the HTML so it’s more applicable to, say, the default Markdown card. Just change sensor.warnings to what you’ve named your sensors; it’ll work with warnings, watches, advisories, statements, and endings.

If you want to format it, just change the third line. The important part here is "alert_"~num as the second argument to state_attr, as this is what allows the template to iterate through all the warnings. The tilde (~) concatenates num to the prefix.

Wish I could give an example screenshot of how it looks, but there’s no alerts in my area rn, lol. With that said, the output should look something like:

Extreme Cold Warning in effect. (14:25)

Same type of problem here.

We had an Extreme Cold Warning all over southern Ontario up to Feb 3rd (Friday).
The warning ended, but the Environment Canada warnings sensor in Home Assistant is still flapping between 0 and 1 for the past two days, triggering the automation that I have to notify me.

The attributes for the sensor are:

{
'location': 'Kitchener-Waterloo', 
'station': "Region of Waterloo Int'l Airport", 
'alert_1': 'Extreme Cold Warning', 
'alert_time_1': 'Friday February 03, 2023 at 05:41 EST', 
'attribution': 'Data provided by Environment Canada', 
'icon': 'mdi:alert-octagon', 
'friendly_name': 'Kitchener-Waterloo Warnings'
}

It is 5th of Feb, 11:51 am as I type this.
Note that the alert_time_1 is still Feb 3rd.

I had to disable the automations.

Not sure if related but my temperature sensor has been randomly “flapping” as you say between the real temperature and -18.4 degrees for about the same amount of time, making this integration temporarily useless. already tried restarting HA and updating the core version to latest

I’m seeing it on my system too. Here’s the Github issue:

1 Like

It’s not the integration’s fault. There appears to be a problem at EnviroCan’s end. Their data feed is randomly delivering either the current day’s weather data or Friday’s data (the one with ‘Extreme Cold Warning’ for eastern Canada).

1 Like

Update: Since about 7 pm EST on Sunday, Environment Canada is no longer providing old data, but I am getting random periods where data is “unavailable”. So I guess the data feed is “improving”. Lol.

Update 2: So it’s about 2 to 3 hours of stable reporting followed by 30 to 60 minutes of unavailable.

Update 3 (7 Feb 2023): Getting anywhere from 2 to 4 hours of stable data with fewer and smaller (10 minutes) periods of unavailable.

1 Like

The fix to ignore weather data more than 2 hours old will be included in release 2023.2.3.

2 Likes

Thanks!

I guess this would work for advisories as well.

What type of card do you use to display this?

BRs

The other day I noticed an error when a forecast included a temperature of 0º; this has been patched in the 2023.3 release.

Environment Canada broke for me. It stopped working randomly and I updating Home Assistant and no change. The entities all just went to idle. Anyone else?

I’m using the HTML Jinja2 Template card on HACS:

If you’re curious, the actual code I use inside the card is as follows, including all the HTML and CSS gubbins:

type: custom:html-template-card
ignore_line_breaks: true
content: >
  <style type="text/css">
<!--snipped unrelated css-->
    h1 {
      line-height: 29px;
    }
    .warnings {
      margin-top: 0;
    }
<!--snipped unrelated css-->
  </style>

  {% if not is_state('sensor.warnings', '0') %}
  {% for num in range(1,int(states('sensor.warnings'))+1) %}
  <h1 class="warnings"> <a href="https://weather.gc.ca/warnings/report_e.html?on61" target="_blank" rel="noopener noreferrer">
    <font color=#bd1c1c>{{ state_attr('sensor.warnings',"alert_"~num) }} in effect. ({{ as_timestamp(strptime(state_attr('sensor.warnings',"alert_time_"~num), '%A %B %d, %Y at %H:%M %Z')) | timestamp_custom("%H:%M")}})</font>
  </a></h1>
  {% endfor %}
  {% endif %}
<!--snipped the rest of the HTML-->

Still can’t give you a preview of how the alerts themselves look on my dashboard cuz I don’t have any alerts at the moment, unfortunately. Also, I’m almost certain that my html code is godawful and probably breaks a bunch of rules, but hey. It works. And the final product looks pretty nice, I think:

image

Maybe I’ll post the rest of the html for my card, if people want to see that.

Fun fact: I’ve got the “observed on/retrieved at” line there specifically because of my previous interaction with the timestamp problem that’s now been patched.

Edit: I’ve actually got an advisory! This is what it looks like.

image

1 Like