Support for Environment Canada platforms

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?

I moved from Hassbian/venv 2 months ago to Raspbian/hass.io and copied only configuration.yaml and some homekit and insteon files. It is not likely that I have some
old env_canada stuff. The EC part of my configuration.yaml is:

camera:

  • platform: environment_canada

weather:

  • platform: environment_canada

sensor:

  • platform: environment_canada
    scan_interval: 600

What can I do to help debug this?

Wes

Is it possible that you’re loading the EC integration as a custom component?

You could try adjusting the scan_interval values to see if that makes a difference.

Well this isn’t good: Environment Canada integration violates ADR-0004.

I guess some parts of the platform are using scraping, but other parts use the EC feed right?

Yes, the only part that relies on web scraping is the details of the alerts. I suppose I can strip that out, but I haven’t worked out another way to get the same data yet.

Update: I’ve stripped out the alert details for now, and I’ll try to find time to look into using Environment Canada’s other data sources instead.

https://github.com/home-assistant/home-assistant/pull/32077