Support for Environment Canada platforms

Wow, I really wish they would consolidate this data a bit more. The components already take quite a while to load due to all the fetching and parsing required, and the fact that they use different geo-bounding for each dataset. I’ll take a look at this one and see if there’s value in pulling it in as well.

@michaeldavie They probably structured it this way because it remains static for 24 hours. Something to consider.

The structure is fine, it’s just a pain to take a user-provided lat/lon and find the right (i.e. closest) data point, and to do it separately for each feed of data that Environment Canada provides. Ideally they would provide an API to do pretty much what my env_canada library is doing—submit a lat/lon, and get back a data structure with everything they know about it. But they don’t, so I have to scrounge up all of the bits myself.

Sorry for the rant…

It’s justified. While scanning through the QC version of it I considered the challenge of matching a given location to the closest one reported within the file. Whoa! That’s a headache! Pretty far from a one-to-one mapping of weather stations to what’s available in that file.

@michaeldavie:

I saw that when I scanned the structure of the past observation data. Your rant is justified.

Let’s not forget the power of the human and let them choose the station id. In my case, the closest calculated station is actually not the one I wanted because of the micro-climate across a large water mass. It’s actually in a different province.

I had to override the logic and set the station id myself. Thanks for making that possible.

I suspect most users don’t mind being that specific and giving an id ‘a la yahoo weather’.

The same problem of geo-location existed for me in darksky. Not in another province, but…it selected sensors at a marina; again, giving me the micro-climate on the edge of a large water mass.

My suggestion, is to let Ha configurators select a station id or even a city name if they want the extra data you can provide…

Does anyone know how to add two sensors? I can only see one…

sensor:
  - platform: environment_canada
    # Lookups of dd.weather.gc.ca every 10 minutes
    scan_interval: 600
    # Chelsea
    station: "QC/s0000615"
  - platform: environment_canada
    # Lookups of dd.weather.gc.ca every 10 minutes
    scan_interval: 600
    # Ottawa
    station: "ON/s0000430"

Hmmm, that’s odd. This loads both for me:

sensor:
  - platform: environment_canada
    station: ON/s0000411
    scan_interval: 300

  - platform: environment_canada
    station: ON/s0000430
    scan_interval: 300

@michaeldavie Indeed strange…

I am not certain how the internal works but something odd is going on. I replaced my sensors for yours and now only the third sensor in the list below is working, previously only Chelsea was working.
The entries from the core.entity_registry found for: “platform”: “environment_canada”. Example for the humidity sensor I have:

            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "sensor.humidity",
                "name": null,
                "platform": "environment_canada",
                "unique_id": "Chelsea-humidity"
            },
...
            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "sensor.humidity_2",
                "name": null,
                "platform": "environment_canada",
                "unique_id": "Ottawa (Kanata - Orl\u00e9ans)-humidity"
            },
...
            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "sensor.humidity_3",
                "name": null,
                "platform": "environment_canada",
                "unique_id": "Thunder Bay-humidity"
            },

My YAML configuration is:

  - platform: environment_canada
    # Lookups of dd.weather.gc.ca every 10 minutes
    scan_interval: 600
    station: ON/s0000411
  - platform: environment_canada
    # Lookups of dd.weather.gc.ca every 10 minutes
    scan_interval: 600
    station: ON/s0000430

Hi, can I setup with my iphone location?

Unfortunately, I don’t think so. The location from the config is used up front to initialize the objects, and it doesn’t have any support for dynamic reconfiguration.

Ok thanks you

I have this issue as well.

I wanted to have both hourly and daily options on the weather.xxx and it killed off my sensors.

Are you saying that the weather component was interfering with the sensor one? I think I might know what the issue is with having two weather entities for the same location, as the entity_id would be the same. To be honest this isn’t a use case I’d considered…it might be a breaking change to fix.

probably and instance append to the id is required. The problem I have breaks sometimes the Radar and Sensors other times. I has not been consistent enough for me to report with clarity to be helpful.

DATAMART IS HAVING ISSUES AT THIS TIME:

Courriel/email: [email protected]

Téléphone/Phone: 514-421-4729

2121 Trans-Canada N. Suite 230

Dorval, Québec

CANADA H9P 1J3

====================================

Dear MSC Datamart users,

We have received several reports from users regarding access issues (timeout, slowness) to the MSC Datamart and the alternative server HPFX (*).

Our analysts are actively investigating this problem, be assured that every effort is being made to solve this issue.

We apologize for the inconvenience.

Thank you for your patience.

Kind regards,
Sandrine

1 Like

@michaeldavie:

Wondering if the code for warnings, statements, and other alerts considers the possibility of multiples of the same type.

Ie. 12/28/19 Statements for ON41
https://weather.gc.ca/warnings/report_e.html?ON41

12:37 PM EST Saturday 28 December 2019
Special weather statement in effect for:

  • Ottawa South - Richmond - Metcalfe

Ice storm possible late Sunday into Monday.

4:44 AM EST Saturday 28 December 2019
Special weather statement in effect for:

  • Ottawa North - Kanata - Orléans

Winter storm Monday.

Occasional light snow or ice pellets are expected Sunday night. However, heavier precipitation is then forecast to arrive Monday morning, then continue into Monday evening before transitioning to snow Monday night.

It does; the default behaviour is to concatenate the titles and descriptions for multiple alerts in the same category together, separated by a pipe (|) character.

However, it seems that in the case of multiple special weather statements EC treats it as a single warning for some reason. I’ll see if I can adjust the code to handle this somehow.

Same problem seems to occur when statements and warnings are mixed together…

https://weather.gc.ca/warnings/report_e.html?ON41

Warnings

3:12 PM EST Saturday 28 December 2019
Freezing rain warning in effect for:

  • Ottawa South - Richmond - Metcalfe

Ice storm possible late Sunday and continuing Monday.

Statements

3:12 PM EST Saturday 28 December 2019
Special weather statement in effect for:

  • Ottawa North - Kanata - Orléans

Winter storm Monday.

I live on a river and was wondering if it would it be possible to read a sensor for water level from environment canada?

Real-Time Hydrometric Data Graph for OUTAOUAIS (RIVIERE DES) A SAINTE-ANNE-DE-BELLEVUE (02OA013) [QC]

This one is easy since the data already comes in JSON format. I have a script that pulls it down every hour. Then I use a command_line sensor to get the value from the script. One way to do it for your station would be:

#!/usr/local/bin/bash
/usr/local/bin/curl -s "https://wateroffice.ec.gc.ca/services/real_time_graph/json/inline?station=02OA033&start_date=$(date -v -1d +%Y-%m-%d)&end_date=$(date +%Y-%m-%d)&param1=46&param2=47" > /tmp/river.json

# for water level
if [ "$1" == "level" ]
then
  echo $(cat /tmp/river.json | jq '.["46"]["provisional"][-1][1]' | grep -oE "[0-9]*\.[0-9]{1,3}")
fi
# for water flow
if [ "$1" == "flow" ]
then
  echo $(cat /tmp/river.json | jq '.["47"]["provisional"][-1][1]' | grep -oE "[0-9]*\.[0-9]{1,3}")
fi

Then add 2 sensors to your home assistant config:

 - platform: command_line
   name: River Level
   command: '/path/to/script.sh level'

 - platform: command_line
   name: River Flow
   command: '/path/to/script.sh flow'

@michaeldavie has previously incorporated a few of these side scripts into the env_canada platform, but I’m not sure if enough people need this particular type of sensor to make it worth the effort that he puts into making it general enough to cover all stations, and then maintaining it.