Hello everyone, I’m trying to get a sensor working that pulls in the UK’s Met Office local weather warning XML and parse it into a TTS friendly list that I can use in a morning report. I’m bringing in the XML ok using feedparser:
sensor:
- platform: feedparser
name: Met Office RSS West Midlands Weather Warnings
feed_url: "http://metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/wm"
date_format: "%a, %b %d %I:%M %p"
scan_interval: 1
which returns XML. For today (2 weather warnings for lightning):
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Met Office warnings for West Midlands</title>
<link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings</link>
<description>Weather warnings of severe and extreme weather from the Met Office</description>
<language>en-gb</language>
<copyright>(c) Crown copyright</copyright>
<pubDate>Wed, 03 Sep 2025 13:00:57 GMT</pubDate>
<dc:creator>[email protected]</dc:creator>
<item>
<title>Yellow warning of thunderstorm affecting West Midlands</title>
<link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2025-09-04&id=c95c6723-6233-4847-9734-cfebbc9483e8&referrer=rss</link>
<description>Yellow warning of thunderstorm affecting West Midlands: Herefordshire, Shropshire, Staffordshire, Stoke-on-Trent, Telford and Wrekin, Warwickshire, West Midlands Conurbation, Worcestershire valid from 0100 Thu 04 Sep to 1600 Thu 04 Sep</description>
<guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2025-09-04&id=c95c6723-6233-4847-9734-cfebbc9483e8&referrer=rss&region=West Midlands</guid>
<enclosure length="17217" type="image/png" url="https://data.consumer-digital.api.metoffice.gov.uk/v1/warnings/rss/image/yellow-thunderstorm.png"/>
</item>
<item>
<title>Yellow warning of thunderstorm affecting West Midlands</title>
<link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2025-09-03&id=38613662-8c3d-415b-8311-8d5133de680c&referrer=rss</link>
<description>Yellow warning of thunderstorm affecting West Midlands: Herefordshire, Shropshire, Staffordshire, Warwickshire, West Midlands Conurbation, Worcestershire valid from 1000 Wed 03 Sep to 1900 Wed 03 Sep</description>
<guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2025-09-03&id=38613662-8c3d-415b-8311-8d5133de680c&referrer=rss&region=West Midlands</guid>
<enclosure length="17217" type="image/png" url="https://data.consumer-digital.api.metoffice.gov.uk/v1/warnings/rss/image/yellow-thunderstorm.png"/>
</item>
</channel>
</rss>
I’ve created an attempted template sensor to try and parse this but I’m struggling. I need to check for both the presence of West Midlands Conurbation and Wolverhampton (as we may have local warnings that don’t affect the wider west midlands), combine multiple warnings if applicable whilst keeping the detail of the event,time/date range and severity for informational reasons. Any help or pointers would be appreciated, cheers.
template:
- sensor:
- name: Met Office Warnings TTS
state: >
{% set warnings = state_attr('sensor.met_office_rss_west_midlands_weather_warnings', 'entries') %}
{% set relevant_warnings = [] %}
{% if warnings %}
{% for warning in warnings %}
{% if 'West Midlands Conurbation' in warning.description or 'Wolverhampton' in warning.description %}
{% set warning_parts = warning.description.split('valid from ') %}
{% if warning_parts|length > 1 %}
{% set warning_text = warning_parts[0]|replace('Yellow warning of', 'Yellow')|replace('affecting West Midlands:', '') %}
{% set valid_time = warning_parts[1] %}
{% set relevant_warnings = relevant_warnings + [warning_text ~ ' valid from ' ~ valid_time] %}
{% else %}
{% set relevant_warnings = relevant_warnings + [warning.description] %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if relevant_warnings|length > 0 %}
{{ relevant_warnings|join('. Next, ') }}
{% else %}
No weather warnings in place today
{% endif %}
but that’s breaking/defaulting to no weather warnings in place for today. It would be nice if the Met Office integration offered weather warnings, but it doesn’t.