-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canadian Weather availability #40
Comments
I'll try to get it added when I get the config flow coded into weatheralerts to allow for easier UI integration configuration. The Canadian weather alert feed is in XML format and contains much less information than the US NWS weather alert feed. I don't think there will be too much difficulty integrating it if I can simplify the current YAML packages, otherwise the Canadian alerts may need their own YAML package to handle notification automations. If you don't want to wait, I'll post some YAML and Lovelace code to allow you to display weather alerts using the Feedparser integration (installable via HACS). And then, with some extra template sensors set up in YAML, reliable automations could be used to also trigger notifications. I'll get some YAML and Lovelace code tested and posted this week. [post edited] Initial testing of Feedparser with scan_interval set in YAML platform config seems to be working to override the hardcoded interval. I'll keep testing to be sure. |
Here is what I came up with to be able to display Canadian weather alerts in the UI. First you'll need to install the Feedparser integration (installable via HACS). Then you will need to get your alert RSS feed URL for your location. Go to https://weather.gc.ca/canada_e.html and click your province or territory link. On your province or territory page, scroll down and you will find a list of cities. Choose your city, or the nearest city to you. Once on the city weather page, scroll down past the Current Conditions, Forecast, Averages and extremes, and Yesterday's Data, and you will see a Follow box. Click the RSS icon (first icon). A popup box will give you Weather and Alerts buttons. Click the Alerts button and it will open the alerts RSS feed for your selected city. The URL for that alerts RSS feed is what you will enter into the Feedparser platform configuration posted below. If using YAML packages, create a new YAML package file and add this code (change the sensor:
- platform: feedparser
name: Canada Weather Alerts
feed_url: 'https://weather.gc.ca/rss/warning/mb-39_e.xml'
date_format: '%Y-%m-%dT%H:%M:%SZ'
scan_interval: 60
- platform: template
sensors:
#sensor that only counts active alerts
canada_weatheralerts_active_alerts:
friendly_name: Weather Alerts
entity_id:
- sensor.canada_weather_alerts
- sensor.time_hour
unit_of_measurement: Alerts
icon_template: mdi:alert-rhombus
value_template: >-
{% set alerts_active = namespace(count=0) %}
{% if (state_attr('sensor.canada_weather_alerts', 'entries')) %}
{% for entry in state_attr('sensor.canada_weather_alerts', 'entries') %}
{% if ' ended' not in entry['summary'].lower() and 'no watches or warnings in effect' not in entry['summary'].lower() %}
{% set alerts_total.count = alerts_total.count + 1 %}
{% endif %}
{% endfor %}
{% endif %}
{{ alerts_active.count }}
#sensor that counts all active and ended/expired alerts
canada_weatheralerts_total_alerts:
friendly_name: Weather Alerts
entity_id:
- sensor.canada_weather_alerts
- sensor.time_hour
unit_of_measurement: Alerts
icon_template: mdi:alert-rhombus
value_template: >-
{% set alerts_total = namespace(count=0) %}
{% if (state_attr('sensor.canada_weather_alerts', 'entries')) %}
{% for entry in state_attr('sensor.canada_weather_alerts', 'entries') %}
{% if 'no watches or warnings in effect' not in entry['summary'].lower() %}
{% set alerts_total.count = alerts_total.count + 1 %}
{% endif %}
{% endfor %}
{% endif %}
{{ alerts_total.count }} If you don't use YAML packages, you will have to place the And then to display the active alerts in a Lovelace Markdown card, you could use something like this:
Automations to control notifications would require some additional work. Notifications could be set up with what is here, but they probably will not be very reliable if based only on alert counts. Additional sensor(s) would be needed to track the alert IDs that caused triggering so older alerts don't retrigger notifications when another alert has ended. |
thanks for the workaround. would love to see an actual integration someday! |
Would it be possible to add a Canadian weather alert option?
thanks,
Chris
The text was updated successfully, but these errors were encountered: