Support for Environment Canada platforms

I’ll add my vote to setting the default update interval back to 10 min, and allowing the user to lower it as needed. While it could be cool to get the bad weather notifications within 60 sec of Env Canada posting them, is getting them within 10 mins that bad?

1 min polling by every user of this integration will definitely be visible to them as it is does not look like organic traffic. The last thing we need is for the admins on the Env Canada side to blacklist the Home Assistant user agent or worse, ask you to take down the integration.

@davidbb Sounds good, I’ve opened PRs to make the interval configurable with a default of 10 minutes.

This component is fantastic!

I’ve been working on setting up automation for warnings, advisories, watches. Curious how the ‘hidden’ attribute is toggled?

Would it be appropriate to use in an automation condition so that it only fires when there actually something to look at (ie the alert/warning/advisory is populated)?

If not, what’s the cleanest way to do this?

Current progress:

"Outside, it will be {{ states('sensor.condition') }} with a current temperature of {{ states('sensor.temperature') }} degrees. 
The forecast for today is a high of {{ states('sensor.high_temperature') }} degrees and a low of {{ states('sensor.low_temperature') }} degrees. 
{% if state_attr('sensor.warnings', 'hidden')!='true' %} There is a {{ states('sensor.warnings') }} in effect. {% endif %}

 {% if state_attr('sensor.advisories', 'hidden')!=true %} There is a {{ states(' sensor.advisories') }} in effect. {% endif %}

{% if state_attr('sensor.ended', 'hidden')!=true %} The {{ states('sensor.ended') }}  {% endif %}

I’m looking to do something similar with alerts. I’d love to have HA announce with TTS on my Sonos when an alert comes up!

Achievable with an automation.

There was a bit of this at the very end of the earlier thread:

I’ve also added the basic TTS script that I wrote to the documentation for the next release.

As of right now the hidden attribute is toggled based on whether there’s a value for the state or not. However, as of the next release it won’t be using the hidden attribute; entities can be hidden or shown using Lovelace instead (admittedly, I’m not sure how to do this myself).

On the automation side, you could try something like this:

automation:
  trigger:
    platform: state
    entity_id: sensor.warnings, sensor.watches
  action:
    service: script.turn_on
    entity_id: script.alert_tts

I seem to continually get update errors when I use this platform. However, it seems that all sensors are still updating frequently despite the errors. For example:

2019-07-30 09:34:59 ERROR (MainThread) [homeassistant.components.sensor] environment_canada: Error on device update! 
Traceback (most recent call last): 
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) 
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 57, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 
  File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -3] Try again During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen chunked=chunked) 
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 355, in _make_request conn.request(method, url, **httplib_request_kw) 
  File "/usr/local/lib/python3.7/http/client.py", line 1244, in request self._send_request(method, url, body, headers, encode_chunked) 
  File "/usr/local/lib/python3.7/http/client.py", line 1290, in _send_request self.endheaders(body, encode_chunked=encode_chunked) 
  File "/usr/local/lib/python3.7/http/client.py", line 1239, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) 
  File "/usr/local/lib/python3.7/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/local/lib/python3.7/http/client.py", line 966, in send self.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 183, in connect conn = self._new_conn() File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn self, "Failed to establish a new connection: %s" % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa1cfc0ae50>: Failed to establish a new connection: [Errno -3] Try again

During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send timeout=timeout 
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen _stacktrace=sys.exc_info()[2]) 
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='dd.weatheroffice.ec.gc.ca', port=80): Max retries exceeded with url: /citypage_weather/xml/ON/s0000326_e.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa1cfc0ae50>: Failed to establish a new connection: [Errno -3] Try again'))

During handling of the above exception, another exception occurred: 
Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 261, in _async_add_entity await entity.async_device_update(warning=False) 
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 380, in async_device_update await self.hass.async_add_executor_job(self.update) 
  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/util/__init__.py", line 224, in wrapper result = method(*args, **kwargs) 
  File "/usr/src/homeassistant/homeassistant/components/environment_canada/sensor.py", line 145, in update self.ec_data.update() File "/usr/local/lib/python3.7/site-packages/env_canada/env_canada.py", line 72, in update timeout=10) 
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, **kwargs) File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, **kwargs) 
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) 
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) 
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='dd.weatheroffice.ec.gc.ca', port=80): Max retries exceeded with url: /citypage_weather/xml/ON/s0000326_e.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa1cfc0ae50>: Failed to establish a new connection: [Errno -3] Try again'))

Interesting. That’s the right address, so I’m not sure what could be causing that. I suspect that it might be something upstream, e.g. DNS or the web server itself.

Not sure how easy it is to add the yesterday’s total precipitation to the component or if anyone is interested in getting it?

I am currently using yesterday’s data from the Environment Canada website for my location. I took yesterday’s total precipitation and added it to my Homeassistant system using the scrape sensor. I am using this to determine if my garden needs watering today.

Here are the details of my config if anyone is interested:

sensor:
  - platform: scrape
    resource: https://weather.gc.ca/city/pages/nb-36_metric_e.html
    name: Environment Canada yesterday's precipitation
    select: 'section:nth-child(6) > details > div > div:nth-child(2) > dl > dd'
    value_template: '{{ ((value.split(" ")[0]) | float ) }}'
    unit_of_measurement: "mm" 
2 Likes

Great idea, I’ve added this to my library and submitted PRs to add it to the component as well.

Is there an ‘last updated’ information available at the source for the camera?

The GIF has the times on it, but they’re kinda small and in UTC. If it were an attribute you could template it onto the card or even put it on the title.

1 Like

Good idea, I’ve added this for 0.98.

Quite a few changes took affect in 0.97, hopefully for the better. I’ve tried to capture them all above at Support for Environment Canada platforms, and have updated the documentation at https://www.home-assistant.io/components/environment_canada. If you run into any trouble, please let me know.

After update to 0.97, sensor.humidex shows unknown, anytime humidex reported as none.
This was still working on v0.96 as a monitored_condition.
Has anyone have the same issue?

My humidex sensor on 0.97.1 showed values when they were present yesterday. As I noted above though, monitored_conditions was removed as a parameter in 0.97, and the sensors are no longer automatically hidden. Is that what you’re seeing?

What I meant to say was, if there is no humidex reported by Environment of Canada, the entity value shown is just “unknown”.

Yes, I think that’s how the frontend represents None from the backend. Is that a problem?

I did notice that there’s no unit anymore, since Environment Canada doesn’t provide one. I might hardcode that for the humidex and wind chill values.

I currently used Darksky but would like to switch to this component but I use Darksky’s cloud cover sensor to determine when I should open or close my blinds and I don’t see this sensor in this platform.
Is this a possibility? Also a pollen sensor for Canada would be great too.
thanks

It is not a big problem, but to me “unknown” suggest something is broken. " None", " - " or no value would be better I think.

I have updated hassio to the last release and the camera is not working. As per the log below any idea what would be the problem. tks
‘Log Details (ERROR)
Mon Aug 12 2019 12:03:04 GMT-0400 (Eastern Daylight Time)
environment_canada: Error on device update!
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 291, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 419, in async_device_update
await self.hass.async_add_executor_job(self.update)
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/util/init.py”, line 240, in wrapper
result = method(*args, **kwargs)
File “/usr/src/homeassistant/homeassistant/components/environment_canada/camera.py”, line 101, in update
self.image = self.radar_object.get_loop()
File “/usr/local/lib/python3.7/site-packages/env_canada/ec_radar.py”, line 98, in get_loop
frames = self.get_frames(count)
File “/usr/local/lib/python3.7/site-packages/env_canada/ec_radar.py”, line 81, in get_frames
frames.append(frames[count - 1])
IndexError: list index out of range’