UK MET Office Severe Weather Warnings

Perfect, thanks so much. I’m going to look at how to pass that through to my notification.

I don’t think this is working properly with combo warnings - it seems fine when there are separate warnings for wind and rain, but Met Office can and do issue warnings for multiple elements eg wind and rain in the same warning. One such wind + rain warning has been issued today, but isn’t displaying in the card.

I am seeing multiple warnings for met office. Seems to be working for me

Hi

Great work. Ive used your code and all is coming through brilliantly for the Yorkshire and Humber and I have 2 entities but was wondering.

I know you said it was old script but I was wondering if you have had to update as I cant see a script.notify in scripts ?

I dont use the Marker Card but mainly mushroom, do you have it show on any cards on your dashboard ?

Thanks in advance

Martyn

Hello

Does this still work for anyone else? As I have weather warnings but it doesn’t show on this card anymore

    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_alertsne','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 North East England: (.*) 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 %}

Yes, it’s still working. But you need to insert code that covers the display of compound alerts like “snow, ice” and “rain, wind”. Try overwriting the {% for type, icon ... %} statement with this:

            {% for type, icon in [('rain', 'weather-pouring'), ('thunderstorms', 'weather-lightning-rainy'), ('rain, wind', 'weather-pouring'), 
                                  ('wind', 'weather-windy'), ('snow', 'weather-snowy-heavy'), ('snow, ice', '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) %}

2 Likes

I’m not sure I understand your question.

I think I previously just posted my sensor here.
I then use that sensor in notifications.

Thanks! This is the piece I was missing for compound warnings.

Im having trouble getting this work - I get:

 Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:385
First occurred: 15:37:17 (8 occurrences)
Last logged: 15:53:39

    TemplateError('IndexError: list index out of range') while processing template 'Template("{% if state_attr('sensor.met_office_rss_south_west_weather_warnings','entries') != None %} {% for item in state_attr('sensor.met_office_rss_south_west_weather_warnings','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 East 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") %} {% endfor %} {% endfor %} {% endif %}")' for attribute 'weather2' in entity 'sensor.template_sidebar'
    TemplateError('IndexError: list index out of range') while processing template 'Template("{% set entity_weather = 'sensor.met_office_rss_south_west_weather_warnings' %} {% if not is_state(entity_weather, 'unknown') %} {% for item in state_attr(entity_weather,'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 East 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") %} {% endfor %} {% endfor %} {% endif %}")' for attribute 'weather2' in entity 'sensor.template_sidebar'
    TemplateError('IndexError: list index out of range') while processing template 'Template("{% set entity_weather = 'sensor.met_office_rss_south_west_weather_warnings' %} {% if not is_state(entity_weather, 'unknown') %} {% for item in state_attr(entity_weather,'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 East 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") %} {% endfor %} {% endfor %} {% else %} Broken, very broken {% endif %}")' for attribute 'battery' in entity 'sensor.template_sidebar'
    TemplateError('UndefinedError: 'dict object' has no attribute 'description'') while processing template 'Template("{% if state_attr('sensor.met_office_rss_south_west_weather_warnings','entries') != None %} {% for item in state_attr('sensor.met_office_rss_south_west_weather_warnings','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')] if type == item.description[0].split(' ')[3]|trim(',') %} --- | | | | | --- | --- | --- | | <font color = {%- if 'Yellow' == item.description[0].split(' ')[0]|trim(',') %}'gold' {%- elif 'Amber' == item.description[0].split(' ')[0]|trim(',') %}'darkorange' {%- else %}'firebrick' {%- endif %}><ha-icon icon={{ "'mdi:" + icon + "'" }}></ha-icon></font> | | {{ item.description|trim("'[]'") }} | {% endfor %} {% endfor %} {% endif %}")' for attribute 'battery' in entity 'sensor.template_sidebar'
    TemplateError('IndexError: list index out of range') while processing template 'Template("{% if state_attr('sensor.met_office_rss_south_west_weather_warnings','entries') != 0 %} {% for item in state_attr('sensor.met_office_rss_south_west_weather_warnings','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 %}")' for attribute 'battery' in entity 'sensor.template_sidebar'

The code:

{% if state_attr('sensor.met_office_rss_south_west_weather_warnings','entries') != 0 %}
            {% for item in state_attr('sensor.met_office_rss_south_west_weather_warnings','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 %}

Note the indendetation has gone all whack since pasting it in here.

Are you using weather alerts for the south west? Then you also need to change the line that refers to the West Midlands to match your region:

{% set summary = item.summary | regex_findall_index('(.*) affecting West Midlands: (.*) valid from (.*) to (.*)', ignorecase=True) %}

Oh yes I missed that. No errors now, but nothing it being output. Very strange. I don’t know how to debug from here on.

Are there alerts active in the south west currently? If it’s a compound alert e.g ‘rain, wind’ then you’ll need to amend the code according to this post

This is a really helpful thread, thanks everyone. I’ve created a sensor and card but can’t test it because there are no weather warnings at the moment (doh!), but there is one bit which definitely isn’t work. I’m trying to add an else clause to the first if, to display a default message when there are no warnings. But I can’t make it display, for some reason. Can anyone spot what I’m doing wrong? It’s the penultimate line below.

{% if state_attr('sensor.met_office_rss_east_midlands_weather_warnings','entries') != 0 %}
  {% for item in state_attr('sensor.met_office_rss_east_midlands_weather_warnings','entries') %}
    {% for type, icon in [('rain', 'weather-pouring'), ('thunderstorms', 'weather-lightning-rainy'),
                          ('wind', 'weather-windy'), ('snow', 'weather-snowy-heavy'), 
                          ('snow, ice', '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 East 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") %}
      {% set link = item.link %}
| | | |
| --- | --- | --- |
| <font color = {%- if 'Yellow' == color %}'gold'
                {%- elif 'Amber' == color %}'darkorange'
                {%- else %}'firebrick'
                {%- endif %}><ha-icon icon={{ "'mdi:" + icon + "'" }}></ha-icon></font> | | **<a href="{{ link }}" target="_blank">{{ summary[0] | title }}</a>**<br />{{ time_from }} - {{ time_to }}<br />{{ summary[1] }} |
    {% endfor %}
  {% endfor %}
{% else %}
  No warnings at present
{% endif %}

Are you using the overall weather card and markdown card code as was posted here?

If so, the markdown card is set within a conditional card that only shows if the alert sensor is above 0. So your ‘no alert’ message would be working, but not showing because the conditional card is off.

Otherwise your code looks fine to me, so can’t see why it wouldn’t work.

Thanks - no conditional card or weather card, just a single Markdown card and the code in my post above is its entire contents. I can put more markdown after the final {% endif %] and it displays correctly. I did wonder whether it’s because the attribute has never been set (because there haven’t been any weather warnings since last night when I created the card), so I created an entity card to display the attribute and it’s currently set to -. I therefore updated the markdown card code so that the final few lines were like this:

                {%- endif %}><ha-icon icon={{ "'mdi:" + icon + "'" }}></ha-icon></font> | | **<a href="{{ link }}" target="_blank">{{ summary[0] | title }}</a>**<br />{{ time_from }} - {{ time_to }}<br />{{ summary[1] }} |
    {% endfor %}
  {% endfor %}
{% elif state_attr('sensor.met_office_rss_east_midlands_weather_warnings','entries') == '-' %}
  Yet to update
{% else %}
  No warnings at present
{% endif %}
asdfasdfasdffasfd

However, it’s still only the asdf... that’s displayed.

Did you manage to fix this? I tried doing what you did and it works for me (but I did not use the {% elif %}

            {% endfor %}
          {% endfor %}
        {% else %} No warnings at present
        {% endif %}

Today, (and maybe it’s always been this way), I’m getting the right date, but wrong day.

My sensor.weather_alerts shows this"

entries: 
- title: Yellow warning of thunderstorm affecting London & South East England
  summary: >-
    Yellow warning of thunderstorm affecting London & South East England:
    Bracknell Forest, Brighton and Hove, Buckinghamshire, East Sussex, Greater
    London, Hampshire, Isle of Wight, Kent, Medway, Milton Keynes, Oxfordshire,
    Portsmouth, Reading, Slough, Southampton, Surrey, West Berkshire, West
    Sussex, Windsor and Maidenhead, Wokingham valid from 1100 Sun 18 Jun to 2259
    Sun 18 Jun

icon: mdi:rss
friendly_name: Weather Alerts

Sun 18 Jun is correct, but my markdown (below) shows Mon (not Sun)

{% for item in state_attr('sensor.weather_alerts','entries') %}
  {% for type in [
    ('extreme heat'),('fog'),('ice'),('lightning'),('rain'),('rain, wind'),('snow'),('snow, ice'),('thunderstorm'),('thunderstorms'),('wind')]
    if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %}
    {% set summary = item.summary | regex_findall_index('(.*) of (.*) affecting .* valid from (.*) to (.*)', ignorecase=True) %}
    {% set time_from = as_timestamp(strptime(summary[2], "%H%M %a %d %b")) | timestamp_custom("%H:%M %a") %}
    {% set time_to = as_timestamp(strptime(summary[3], "%H%M %a %d %b")) | timestamp_custom("%H:%M %a") %}
    {% set message = summary[0] + ' | ' + summary[1] +'\nfrom: '+ time_from +'\nto: '+ time_to %}
    {{ message }}
  {% endfor %}
{% endfor %}

{% 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'), 
                          ('snow, ice', 'weather-snowy-heavy'),
                          ('lightning', 'weather-lightning'), ('ice', 'car-traction-control'),
                          ('fog', 'weather-fog'), ('extreme heat', 'weather-sunny-alert'), ('thunderstorms', '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 (.*) 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") %}
      {% set link = item.link %}
| | | |
| --- | --- | --- |
| <font color = {%- if 'Yellow' == color %}'gold'
                {%- elif 'Amber' == color %}'darkorange'
                {%- else %}'firebrick'
                {%- endif %}><ha-icon icon={{ "'mdi:" + icon + "'" }}></ha-icon></font> | | **<a href="{{ link }}" target="_blank">{{ summary[0] | title }}</a>**<br />{{ time_from }} - {{ time_to }}<br />{{ summary[1] }} |
    {% endfor %}
  {% endfor %}
{% else %}
  No warnings at present
{% endif %}

Edit:
It appears that strptime(summary[3], "%H%M %a %d %b") results in a date in 1900 (1900-06-18 22:59:00). I assume this is because there is no year in the original date (it only had 1100 Sun 18).


Edit:
OK, here’s my fix using slicing - hope it helps people:

{% set time_from = summary[2][0:2] +':'+ summary[2][2:5] +'on '+ summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %}
{% set time_to = summary[3][0:2] +':'+ summary[3][2:5] +'on '+ summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %}

which gives the correct (as of today - Sun -18-Jun) dates of::

from: 11:00 on Sun-18-Jun
to: 22:59 on Sun-18-Jun

Don’t forget the time is displayed as GMT, so here’s a version with the ‘z’ for Zulu (as I know I’m going to forget this!).

{% set time_from = summary[2][0:2] +':'+ summary[2][2:4] +'z on '+ summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %}
{% set time_to = summary[3][0:2] +':'+ summary[3][2:4] +'z on '+ summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %}

Probably fixed long ago, but the region is South West England even though the code is sw.

If in doubt, you can check the name of the area by looking through the attributes of sensor.weather_alerts

OK, here’s a better version for anyone that is interested.

It assumes the data is GMT/UTC and converts to local time.

Note

  • I added a link to take you to the relevant Met Office Weather Alert page
  • I added a line break between each alert.
  • I am using content: > (not | ) and this is why there are line spaces between the printed rows (I find it easier to read this way).
  • I also rearranged the {% for type, icon in…, again, for easy reading
- type: markdown
  content: >
    {% if state_attr('sensor.weather_alerts','entries') != 0 %}
      {% for item in state_attr('sensor.weather_alerts','entries') %}
        {% for type, icon in
          [
            ('extreme heat', 'weather-sunny-alert'),
            ('fog', 'weather-fog'),
            ('ice', 'car-traction-control'),
            ('lightning', 'weather-lightning'),
            ('rain', 'weather-pouring'),
            ('rain, wind', 'weather-pouring'),
            ('snow', 'weather-snowy-heavy'),
            ('snow, ice', 'weather-snowy-heavy'),
            ('thunderstorm', 'weather-lightning'),
            ('thunderstorms', 'weather-lightning-rainy'),
            ('wind', 'weather-windy')
          ]
          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 London & South East England: (.*) valid from (.*) to (.*)', ignorecase=True) %}
          {% set link = item.link %}
          {% set time_utc_from = summary[2][0:2] ~':'~ summary[2][2:4] %}
          {% set time_utc_to = summary[3][0:2] ~':'~ summary[3][2:4] %}
          {% set date_from = summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %}
          {% set date_to = summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %}
          {% set time_local_from = ((now().date() ~ ' ' ~ time_utc_from ~ "+00:00") | as_datetime | as_local).strftime('%H:%M') %}  
          {% set time_local_to = ((now().date() ~ ' ' ~ time_utc_to ~ "+00:00") | as_datetime | as_local).strftime('%H:%M') %}
    |  |  |

    | -: | -- |

    | <font color = {%- if 'Yellow' == color %}'gold' {%- elif 'Amber' == color %}'darkorange' {%- else %}'firebrick' {%- endif %}>
    <ha-icon icon={{ "'mdi:" + icon + "'" }}>
    </ha-icon></font>
    | <a href='{{ link }}'>**{{ summary[0] }}** </a>
    |

    || from **{{ time_local_from }}** to **{{ time_local_to }}** on **{{ date_from }}** |
        {% endfor %}
    <br>
      {% endfor %}
    {% else %} No warnings at present
    {% endif %}

If you want, you can reduce the amount of info that the sensor reads (only need summary and link)

- platform: feedparser
  name: Weather Alerts
  feed_url: 'http://metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/se'
  date_format: '%a, %b %d %I:%M %p'
  inclusions:
    - summary
    - link

And here’s my associated notification (using the HA app) which leans heavily on the one shared by @klogg :+1:

automation:
- alias: Notify Weather Warnings
  id: weather_notify_warnings
  trigger:
    - platform: state
      entity_id: sensor.weather_alerts
    - platform: homeassistant
      event: start
  variables:
    message: |
      {% for item in state_attr('sensor.weather_alerts','entries') %}
        {% for type in [
          ('extreme heat'),('fog'),('ice'),('lightning'),('rain'),('rain, wind'),('snow'),('snow, ice'),('thunderstorm'),('thunderstorms'),('wind')]
          if type == item.summary | regex_findall_index('.*warning of (.*) affecting.*', ignorecase=True) %}
          {% set summary = item.summary | regex_findall_index('(.*) of (.*) affecting .* valid from (.*) to (.*)', ignorecase=True) %}
          {% set time_utc_from = summary[2][0:2] ~':'~ summary[2][2:4] %}
          {% set time_utc_to = summary[3][0:2] ~':'~ summary[3][2:4] %}
          {% set date_from = summary[2][5:8] +'-'+ summary[2][9:11] +'-'+ summary[2][12:] %}
          {% set date_to = summary[3][5:8] +'-'+ summary[3][9:11] +'-'+ summary[3][12:] %}
          {% set time_local_from = ((now().date() ~ ' ' ~ time_utc_from ~ "+00:00") | as_datetime | as_local).strftime('%H:%M') %}  
          {% set time_local_to = ((now().date() ~ ' ' ~ time_utc_to ~ "+00:00") | as_datetime | as_local).strftime('%H:%M') %}
      {{ summary[0] }}
      {{ summary[1] }}
      {{ time_local_from }}➜{{ time_local_to }}
      {{ date_from }}
        {% endfor %}
      {% endfor %}
  condition:
  action:
    - choose:
        - conditions:
            - condition: numeric_state
              entity_id: sensor.weather_alerts
              above: 0    
          sequence:
            - service: notify.notify
              data:
                title: "Met Office"
                message: "{{ message }}"
                data:
                  tag: weather_alert  # will replace earlier alerts with this tag
                  group: weather      # will be grouped with others in this group.
        - conditions:
            - condition: state
              entity_id: sensor.weather_alerts
              state: '0'   
          sequence:
            - service: notify.notify
              data:
                message: clear_notification
                data:
                  tag: weather_alert

Thanks to everyone in this thread for the inspiration! :slight_smile:

2 Likes

Is this automation working for you still?