Support for Environment Canada platforms

Yes, he’s using the condition sensor from the Environment Canada integration, which uses Environment Canada’s full set of condition values. For the weather component I map these to the subset supported by HA.

1 Like

Just to be sure I understand this correctly, a weather.some_city entity based on the Environment Canada platform can report more state values than the standard set shown in my post above?

Or are you mapping certain EC values to Home Assistant’s default set? In other words, it’s mapping EC’s water, precipitation, drizzle to Home Assistant’s rainy.

It’s the second one, the Environment Canada conditions are mapped to the Home Assistant ones; see this excerpt from weather.py:

# Icon codes from http://dd.weatheroffice.ec.gc.ca/citypage_weather/
# docs/current_conditions_icon_code_descriptions_e.csv
ICON_CONDITION_MAP = {
    ATTR_CONDITION_SUNNY: [0, 1],
    ATTR_CONDITION_CLEAR_NIGHT: [30, 31],
    ATTR_CONDITION_PARTLYCLOUDY: [2, 3, 4, 5, 22, 32, 33, 34, 35],
    ATTR_CONDITION_CLOUDY: [10],
    ATTR_CONDITION_RAINY: [6, 9, 11, 12, 28, 36],
    ATTR_CONDITION_LIGHTNING_RAINY: [19, 39, 46, 47],
    ATTR_CONDITION_POURING: [13],
    ATTR_CONDITION_SNOWY_RAINY: [7, 14, 15, 27, 37],
    ATTR_CONDITION_SNOWY: [8, 16, 17, 18, 25, 26, 38, 40],
    ATTR_CONDITION_WINDY: [43],
    ATTR_CONDITION_FOG: [20, 21, 23, 24, 44],
    ATTR_CONDITION_HAIL: [26, 27],
}

For the more specific data, there are two separate sensors, condition and icon_code:


In that case, how can the state value of weather.ec in this template ever be drizzle?

or ('drizzle' in states('weather.ec').lower())

drizzle doesn’t exist in a weather entity’s set of state values. However, I can understand how that template would work if instead of the weather entity it used the sensor entity for conditions.

What am I missing here?

You’re right, that won’t work with the weather entity. The template I suggested and posted uses the icon_code sensor.

1 Like

The additional code you added (all of the ORed statements) isn’t working the way you think. The weather.ec entity can never report state values such as drizzle, squalls, thunder, water, etc. It can only report the values shown in the posted link above. What can report those values is sensor.condition.

You can correct your template by replacing all instances of weather.ec with sensor.condition or use this streamlined version:

{{ states('sensor.icon_code') | int in [6, 9, 11, 12, 13, 19, 28, 36, 39, 46, 47] or
  states('sensor.condition').lower().split() | select('in', ['rain', 'snow', 'thunder', 'water', 'flurries', 'drizzle', 'ice', 'squalls', 'precipitation', 'lightning']) | list | count > 0 }}
1 Like

Thanks Taras!! updated my config with your version
Incidentally I noticed the sensor is now giving “unavailable” state in all EC sensors, this started yesterday and continues today; I tried restarting HA to no avail

Are others having issues as well lately? or could it be my station?
No config changes on my end and my sensor config is super simple,

  - platform: environment_canada
    station: XX/s1231234

The curious thing is that at the same time, with the same station configured, the “weather” platform works perfectly, while all sensors remain unavailable

Further to this, I removed the ‘station’ I’d from both sensor and weather configs and restarted, same results. The weather card works fine but all the sensors are ‘unavailable’. I do have lat/long configured in the system. Looks like this integration broke for some reason?
No errors are showing up in the log at all

That is definitely odd. Try removing the sensors via the UI and restarting; they should be recreated.

It’s working fine for me.

I tried removing the entities via GUI and restarting,

image

The weather card is showing OK.
Very strange.

Here’s my configuration

....
sun:

weather:
  - platform: environment_canada
.....
sensor:

  # uses system-level lat-long coordinates to determine the closest station
  - platform: environment_canada

  - platform: season
    type: astronomical

...

I’m using HA on docker, in RPi4.

System Health
Version 	core-2021.10.2
Installation Type 	Home Assistant Container
Development 	false
Supervisor 	false
Docker 	true
User 	root
Virtual Environment 	false
Python Version 	3.9.7

The integration is loaded, I can see that in the info panel

Are there any errors in the logs when the system is starting?

I have had this same issue since the Environment Canada integration was released in core. I’ve looked into it a few times and have never been able to figure out what was going wrong.

If I only configured the sensor platform, I got the sensors and they worked fine. If I configured just the sensors, start HA, then add the weather entities and restart everything works until the next restart. Then boom - all the sensors are gone, but the weather entities were still present and working. I’ve tried setting it up with default location, with long/lat, and station and a mix of them. Deleting it all, restarting. and reconfiguring, always with the same reproducible results.

I’ve set the following logs and saw nothing, no errors. The EC sensor platform seems like it just isn’t set up for some reason.

homeassistant.components.environment_canada: debug
homeassistant.components.sensor: debug
homeassistant.components.weather: debug

Anyway, the good news is the 2021.11 beta has resolved the issue for me. I deleted the integration the reinstalled it with the new config flow. Works a treat. The prefix on the sensors is nice.

What is the difference between the “current” weather entity and the normal forecast? I haven’t had a chance to look at it closely yet. Also, the air quality index sensor is gone after the update. Other than that working great now.

No errors at all, the addon shows as loaded, but the entities did not get re-created when I removed them from the UI, I tried multiple restarts, removing the station ID, changing/checking the lat/long coordinates in the system etc.
I ended up removing the sensor component, and extracting datapoints I wanted from the weather component attributes. I’ll try the sensor again after the new GUI-based version gets merged

An update on what is going on with the integration. I’m glad that you are trying the beta and the UI config! We’ve had to split up the work to update the integration. Much of the work will land in 2021.11. Unfortunately, most likely because of Hacktoberfest, we could not get all the changes onto the .11 release, they will likely land in .12.

AQHI is one of those changes that is coming. The other thing coming with the sensors is, and beware, these changes have not been accepted by the HA team, so they may change:

  • The alerts will be an integer count of the number active. The attributes will be the text/time of the alert.
  • There is no timestamp attribute on the sensors any longer. There is an observation timestamp sensor which will make it easier for automations to know when the sensors have a new observation point.

The two open pull requests with these changes are: Add SensorEntityClass support for Environment Canada integration by gwww · Pull Request #58615 · home-assistant/core · GitHub and Use _attr_ and add radar_type service for Environment Canada by gwww · Pull Request #58657 · home-assistant/core · GitHub. The pull request for AQHI is not created yet and is waiting for the two PRs listed here.

@jazzyisj Your question, what is the difference between current entity and normal forecast… say more, what are you referring to when you say current entity?

2 Likes

I have weather template that is very similarly named to the way the EC integration names the entities now. It came up when I did a quick filter in devtools to check out the new sensors and like I said I hadn’t had time to look closely at it. So I just did. Ignore me…lol.

BTW I was able to add a second station with no issues with the new config flow.

Looking forward to the additional changes. :slight_smile:

I do have one comment about the alert sensors. One reason I still have Dark Sky installed is the additional alert description text and alert expiry time provided for Environment Canada alerts. Any chance this data can be added as attributes to the EC integration warning sensors?

I’ll leave that to @michaeldavie. He is focusing on the base library that interacts with Environment Canada while I’ve been focusing on the HA integration piece.

I would love to have the alert descriptions too. Unfortunately, I haven’t found a way to get this information without web scraping, which HA doesn’t allow. I’ll keep looking into it though, and see if I can come up with something.

1 Like

Now that 2021.11 has been released, @gwww and I have decided to close off this topic (after almost 2.5 years!) and start up a new one to mark the major update. Please join us at the link below to continue the discussion.