I’ve made some improvements to my feedparser version previously posted. This now supports “extream heat” and “thunderstorm” alerts. I’ve also reworked the summary text into something which I can layout a little better. Date time formats can be changed to your liking simply by updating the format codes.
You will also need to update the region in the regex to match your region. I strip it out because I know my region and only interested in the actual places affected.
Sensor
- platform: feedparser
name: Weather Alerts
feed_url: "https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/wm"
date_format: "%a, %b %d %I:%M %p"
Lovelace Card - needs card_mod
type: custom:stack-in-card
cards:
- type: weather-forecast
entity: weather.openweathermap
- type: conditional
conditions:
- entity: sensor.weather_alerts
state_not: '0'
card:
type: markdown
card_mod:
style:
.: |
ha-card {
--mdc-icon-size: 40px;
}
ha-markdown:
$: |
td {
vertical-align: top;
}
content: |
{% if state_attr('sensor.weather_alerts','entries') != 0 %}
{% for item in state_attr('sensor.weather_alerts','entries') %}
{% for type, icon in [('rain', 'weather-pouring'), ('thunderstorms', 'weather-lightning-rainy'),
('wind', 'weather-windy'), ('snow', 'weather-snowy-heavy'),
('lightning', 'weather-lightning'), ('ice', 'car-traction-control'),
('fog', 'weather-fog'), ('extreme heat', 'weather-sunny-alert'), ('thunderstorm', 'weather-lightning')] if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %}
{% set color = item.summary.split(' ')[0] %}
{% set summary = item.summary | regex_findall_index('(.*) affecting West Midlands: (.*) valid from (.*) to (.*)', ignorecase=True) %}
{% set time_from = as_timestamp(strptime(summary[2], "%H%M %a %d %b")) | timestamp_custom("%H:%M %d/%m") %}
{% set time_to = as_timestamp(strptime(summary[3], "%H%M %a %d %b")) | timestamp_custom("%H:%M %d/%m") %}
| | | |
| --- | --- | --- |
| <font color = {%- if 'Yellow' == color %}'gold'
{%- elif 'Amber' == color %}'darkorange'
{%- else %}'firebrick'
{%- endif %}><ha-icon icon={{ "'mdi:" + icon + "'" }}></ha-icon></font> | | **{{ summary[0] | title }}**<br />{{ time_from }} - {{ time_to }}<br />{{ summary[1] }} |
{% endfor %}
{% endfor %}
{% endif %}
Hope someone finds this useful