Support for Environment Canada platforms

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.

THANK YOU!

I’m Very new to all this… I’m getting an error “end of the stream or a document separator is expected at line 6, column 1:
if [ “$1” == “flow” ]”

Hi,
I’ve had trouble getting this component to start since just before christmas. Error log:

Wed Jan 01 2020 23:56:08 GMT-0700 (Mountain Standard Time)
Error while setting up platform environment_canada
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/environment_canada/weather.py", line 77, in setup_platform
    ec_data = ECData(coordinates=(lat, lon))
  File "/usr/local/lib/python3.7/site-packages/env_canada/ec_data.py", line 240, in __init__
    self.update()
  File "/usr/local/lib/python3.7/site-packages/env_canada/ec_data.py", line 205, in res
    return fun(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
  File "/usr/local/lib/python3.7/site-packages/env_canada/ec_data.py", line 254, in update
    self.metadata[m] = weather_tree.find(meta['xpath']).text
AttributeError: 'NoneType' object has no attribute 'text'

Anyony have any suggestions? Install is latest HA release on docker.

In that case EC didn’t include the warning in their XML for some reason, otherwise it would have worked.

Maybe, I’ll take a look at it. Although @davidbb’s solution looks good too.

@pinballnewf: Can you tell me what station or approximate location you’re using? It looks like you might be trying to access data that’s not there anymore.

@michaeldavie Hey,
I was using auto-locate in the Calgary area. It most likely mapped to AB/s0000126 as that is the closest station to me. Forcing it to AB/s0000047 [Calgary] has fixed it, so I guess EC is no longer publishing the required data for Calgary/Olympic Park.

Thanks so much for your help and for the awesome component.
-Corey

Thanks, I’ve confirmed that this is a bug. EC doesn’t publish current conditions for Calgary/Olympic Park, only forecasts, and this is causing the metadata update to break. There are quite a few stations like this, so I should be handling it better. Thanks for letting me know!

Update: The fix for this has been merged, and it should be in either the next major or minor release.

@richard2: Looking more closely at the data, I think it would make the most sense for the hydrometric data to be its own component, with separate sensors for water level and discharge. It should be pretty straightforward to put this together based on what I have already, so I’ll take a crack at it.

3 Likes

@pinballnewf The fix for your issue was merged into 0.103.6, so please let me know if it works for you.

@richard2 I put together a PR for a new hydrometric component, you can keep an eye on it at https://github.com/home-assistant/home-assistant/pull/30426 or try it out as a custom component.

Hey @michaeldavie, I pulled 0.103.6 and can confirm the issue has been addressed! I removed the station ID, it reverted to auto-locate using Olympic Park as the data source and is working fine.

Thanks again.
-Corey

1 Like

Hi, could you kindly look at why this radar station is not loading? CASMB, Marion Bridge, NS. Other stations are loading for me. Home Assistant 0.103, HassOS 3.7

Here is my config:

weather:

  • platform: environment_canada
    station: NS/s0000670
    sensor:
  • platform: environment_canada
    station: NS/s0000670
    camera:
  • platform: environment_canada
    station: CASMB

Log:

2020-01-12 10:46:05 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform environment_canada
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File “/usr/local/lib/python3.7/asyncio/tasks.py”, line 442, in wait_for
return fut.result()
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/homeassistant/homeassistant/components/environment_canada/camera.py”, line 53, in setup_platform
station_id=config[CONF_STATION], precip_type=config.get(CONF_PRECIP_TYPE)
File “/usr/local/lib/python3.7/site-packages/env_canada/ec_radar.py”, line 43, in init
self.station_name = site_dict[self.station_code][‘name’]
KeyError: ‘CASMB’
2020-01-12 10:47:56 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8)
2020-01-12 10:48:05 ERROR (Recorder) [homeassistant.components.recorder] Error in database connectivity: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8). (retrying in 3 seconds)
2020-01-12 10:48:20 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8)
2020-01-12 10:48:20 ERROR (Recorder) [homeassistant.components.recorder] Error in database connectivity: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8). (retrying in 3 seconds)
2020-01-12 10:48:28 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8)
2020-01-12 10:48:38 ERROR (Recorder) [homeassistant.components.recorder] Error in database connectivity: (sqlite3.OperationalError) database is locked
(Background on this error at: http://sqlalche.me/e/e3q8). (retrying in 3 seconds)

Thanks for letting me know, my list is out of date. I’ll add CASMB in the next release, but in the meantime you can use XMB as they’re still supporting it.

Let me know if you have any trouble.

XMB worked no problem. Thank you for the quick reply.

Are the sensors values numeric or are they string values? I am trying to do a numeric state trigger on low_temperature?

They’re numeric. If you post what you’re having trouble with I can take a look.

BTW, the CASMB change was merged and should be in the next major release.

Here is the automation I copied from my automations.yaml I’m still new to HA. It may be working. When I change the temperature in the automation, I assume that it should trigger after each save of the automation. How else do I confirm the trigger is working? I think action is okay. The current low_temperature is -9

trigger:

  • below: ‘-5’
    entity_id: sensor.low_temperature
    platform: numeric_state
    condition: []
    action:
  • data: {}
    entity_id: switch.air_exchange_override
    service: switch.turn_on

Hi: I have been using the EC Integration for a few months with generally good results but I would like to feedback on 2 issues:

My HA install is release 105.2, using hass.io on a Pi4 running Raspbian Buster, latest updates.

First I recently installed Pi-hole and noticed a large number of DNS hits on dd.weather.gc.ca
(over 16,000 hits in 24hrs) and weather.gc.ca (over 11,000 hits). These are the top 2 on the hit parade. Github.com is next at 1600 hits. The hits do no real harm as they are served locally by the Pi-hole cache, but it seems excessive.

Second there can be many hours between successful weather updates. If I restart HA a current update usually arrives.

Here are some recent log records that I think are related:

Update of weather.brockville is taking over 10 seconds
7:56 PM main.py (WARNING)

Setup of camera platform environment_canada is taking over 10 seconds.
7:24 PM main.py (WARNING)

Unable to update from sensor: could not convert string to float: ‘unknown’
7:24 PM components/generic_thermostat/climate.py (ERROR)

I am far from a programmer but would be happy to help collect results etc.
Wes Warner

That’s odd. I run Pi-Hole as well and I don’t see anywhere near that many requests in my logs. The components are configured by default to update every 10 minutes, and in mine I have them set to 5. Is it possible that you have an older version of the env_canada library kicking around in your installation?