Support for Environment Canada platforms

Oh, it looks like there’s something wrong with cloudflare dns which I’m using… They say it’s Operational on their status page tho…

(google dns)
$ dig @8.8.8.8 meteo.gc.ca +short
205.189.10.44
205.189.10.43
(cloudfare dns)
$ dig @1.1.1.1 meteo.gc.ca +short
$

FYI they fixed the issue.

1 Like

Is there a way to use this integration to know if “Currently” it’s raining in a specific monitoring station? I’m interested in current state (or near real time), rather than forecast.

My use case: I want to create a binary sensor: “currently_raining” that (when active) I would then use in some automations as a condition, to ignore motion detection events from an outdoor camera that gives false alerts when it rains.

Another possible use case for the same sensor: if the sensor went ON during the last 12 hours, show in Lovelace that the plants do NOT require watering today.

I have an EC monitoring station nearby so I thought this integration could help. Any idea/suggestion on how to achieve this would be welcome!

This might not be the best way, sometimes I see current weather indicates “rain” and there’s no precipitation in my area despite not being that far from EC weather station. It could also rain during 4 hours leaving only 1mm or raining 30min leaving 2cm, two cases you couldn’t code exceptions for.

Best options I see are fetching precipitation data from Historical Data - Climate - Environment and Climate Change Canada using curl or simply buy or diy build a rain gauge. Another cheap but effective solution is to build an arduino moisture sensor: if ground is dry then start watering automation for X minutes.

I would suggest using a template binary sensor based on the icon code, like this (EDIT - Updated to use the template integration):

template:
  - binary_sensor:
    - name: "Currently Raining"
      state: >
        {% if states('sensor.icon_code') | int is in [6, 9, 11, 12, 13, 19, 28, 36, 39, 46, 47] %}
          {{ true }}
        {% else %}
          {{ false }}
        {% endif %}

You can choose with icon codes you’d like to include based on the following:

  • The mapping I’ve done between the icon codes and weather component states
  • The icon code descriptions

@michaudjp & @michaeldavie Thanks for the feedback on this!
I will try both ideas, first the binary sensor based on the EC weather icon and see how it goes. I mainly want to be able to detect heavy rain at night (drizzle doesn’t trip the outdoor cams motion detection)

I also just ordered a MiFlora soil moisture sensor. It’s a bluetooth low energy device that I’m planning to “bridge” to HA using an ESP32 with ESPhome, they support it. I was building one to the the same for a BLE air quality monitor and I just noticed ESPhome also supports miflora BLE bridging.

I wonder though if the MiFlora device will survive our winter here :), and also how to map the moisture reading to rain. I’m thinking I could leave the device in the pebble area in the side of the house. If the idea doesn’t pan out as a rain sensor I can still use the sensor next year to automate backyard irrigation.

1 Like

I noticed that sometimes the weather entity gets more timely than the “sensor” so I updated the template like so:

          {% if
             states('sensor.icon_code') | int is in [6, 9, 11, 12, 13, 19, 28, 36, 39, 46, 47] 
             or ('rain' in states('weather.ec').lower())
             or ('snow' in states('weather.ec').lower())
             or ('thunder' in states('weather.ec').lower())
             or ('water' in states('weather.ec').lower())
             or ('flurries' in states('weather.ec').lower())
             or ('drizzle' in states('weather.ec').lower())
             or ('ice' in states('weather.ec').lower())
             or ('squalls' in states('weather.ec').lower())
             or ('precipitation' in states('weather.ec').lower())
             or ('lightning' in states('weather.ec').lower())
          %}
            {{ true }}
          {% else %}
            {{ false }}
          {% endif %}

it seems to be working well

I’m trying to get a hydrometric sensor. Is this now a part of the Environment Canada platform?

I’ve added hydrometric data to the env_canada Python library, but I haven’t made it into a Home Assistant component. I don’t think it belongs with the weather data, so it would likely be separate. I wasn’t sure how much interest there would be, but I can add this to my list of things to do.

1 Like

According to the source-code for the weather integration (the basis for all weather platforms), the state value of a weather entity can have the following values:

Your template looks for other values, not shown in that list, such as drizzle, water, precipitation, squalls, etc. Are those additional values reported by the Environment Canada platform?

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.