UK MET Office Severe Weather Warnings

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?

Yes. What goes wrong with yours?

I have changed it slightly, but shouldn’t make much difference. Here it all is anyway:

sensor: #-----------------------------------------------------------------------
- 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


template: #---------------------------------------------------------------------
- sensor:
    - name: "Weather Alerts Oxfordshire"
      state: >
        {{ state_attr('sensor.weather_alerts','entries')
          | map(attribute='summary')
          | select('search', 'Oxfordshire') 
          | list
          | count
        }}


automation: #-------------------------------------------------------------------
- alias: "Weather: Notify weather warnings"
  id: weather_notify_warnings
  trigger:
    - platform: state
      entity_id: sensor.weather_alerts_oxfordshire
  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) and item.summary | regex_findall('Oxfordshire', 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:
    - "{{ trigger.to_state.state not in ['unknown', 'unavailable','0'] }}"
    - "{{ trigger.from_state.state not in ['unknown', 'unavailable','0'] }}"
  action:
    - service: notify.notify
      data:
        title: "Met Office"
        message: "{{ message }}"
        data:
          tag: weather_alert  # will replace earlier alerts with this tag
1 Like

Ah thanks this isperfect it worked. Not sure exactly what was up with mine but I noticed your code is very clean. I’ve changed it to ‘SW’ & ‘Somerset’.

1 Like

cheers.

Here is the associated card:

    - 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) and item.summary | regex_findall('Oxfordshire', 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 }}**, {{ date_from }} |
        
        | to: | **{{ time_local_to }}**, {{ date_to }} |
            {% endfor %}
        <br>
          {% endfor %}
        {% else %} No warnings at present
        {% endif %}

I’m not getting anything when checking the met office’s rss feeds… is this correct? checking with RSS Feed Parser | TechnicalSEO.com

http://metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw

I think it should be showing this flood warning in the rss feed?

Flood Warnings are issued by Environment Agency in England (and by Natural Resources Wales in Wales and Sepa in Scotland)

The Met Office don’t issue Flood warnings so flood warnings don’t appear in its feed.

Met office do issue heavy rain warnings but there are none currently in force in the UK.

2 Likes

Thanks. Understood.

What did you guys use to ‘test’ the feed?

Here’s my implantation using custom weather card.
The weather warning card creates an empty card so I added a heading above with some other weather related data as a heading.

The these is mushroom shadow.

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-chips-card
        chips:
          - type: menu
          - type: entity
            entity: sensor.7_barn_temperature
            icon: fas:house-chimney
            content_info: state
            icon_color: teal
          - type: entity
            entity: sensor.1_garden_temperature
            icon: mdi:flower
            icon_color: accent
          - type: entity
            entity: sensor.speedtest_download
            icon_color: pink
          - type: entity
            entity: person.home_assistant
            icon: ''
  - type: custom:clock-weather-card
    entity: weather.tomorrow_io_home_daily
    temperature_sensor: sensor.1_garden_temperature
    date_pattern: ccc - d - LLL - yyyy
  - type: custom:mushroom-chips-card
    chips:
      - type: entity
        entity: person.home_assistant
        content_info: name
        name: Weather Warnings
        icon: mdi:alert
        icon_color: red
      - type: entity
        entity: sensor.home_wind_speed
        icon_color: lime
      - type: entity
        entity: sensor.openweathermap_forecast_precipitation_probability
        icon: mdi:weather-pouring
        icon_color: primary
      - type: entity
        entity: sensor.openweathermap_feels_like_temperature
        icon: mdi:run-fast
        icon_color: accent
  - type: custom:stack-in-card
    cards:
      - 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')
                  ('flood', 'flooding')
                ]
                if type == item.summary | regex_findall_index('.*warning of (.*) affecting Somerset.*', ignorecase=True) %}
                {% set color = item.summary.split(' ')[0] %}
                {% set summary = item.summary | regex_findall_index('(.*) affecting South West 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 %}
  - type: custom:home-feed-card
    card_id: main_feed
    show_empty: false
    state_color: true
    entities:
      - entity: sensor.next_recycling_collection
        more_info_on_tap: true
        icon: mdi:recycle
  - type: custom:mushroom-chips-card
    chips:
      - type: entity
        entity: sensor.1_garden_temperature
        tap_action:
          action: more-info
        name: '1'
        icon_color: primary
        icon: mdi:flower
      - type: entity
        entity: sensor.2_phonebox_temperature
        tap_action:
          action: more-info
        name: '2'
        icon_color: accent
        icon: fas:square-phone
      - type: entity
        entity: sensor.3_greenhouse_temperature
        tap_action:
          action: more-info
        name: '3'
        icon_color: red
        icon: mdi:greenhouse
      - type: entity
        entity: sensor.4_shed_temperature
        icon_color: pink
        icon: mdi:garage-variant
      - type: entity
        entity: sensor.5_kitchen_temperature
        icon: mdi:pot-steam
        icon_color: purple
      - type: entity
        entity: sensor.7_barn_temperature
        tap_action:
          action: more-info
        name: '7'
        icon_color: indigo
        icon: hue:room-bathroom
      - type: entity
        entity: sensor.9_ble_temp_temperature
        icon: mdi:fridge
        icon_color: light-blue
      - type: entity
        entity: sensor.10_ble_temp_temperature
        icon: fas:house-chimney
        icon_color: cyan
  - type: vertical-stack
    cards:
      - type: custom:mushroom-chips-card
        chips:
          - type: entity
            entity: sensor.hp_deskjet_3630_series
            content_info: name
            icon: ''
            name: HP Deskjet 3630
            use_entity_picture: false
            icon_color: pink
          - type: entity
            entity: sensor.hp_deskjet_3630_series_tri_color_ink
            icon_color: accent
            icon: ''
          - type: entity
            entity: sensor.hp_deskjet_3630_series_black_ink
            tap_action:
              action: more-info
            name: '1'
            icon_color: black
            icon: ''
          - type: entity
            entity: sensor.hp_deskjet_3630_series
            icon_color: green

You can’t really. You need to wait for an actual warning.

Please note I have discovered an error in the first line of the card that prevents the "no warnings at present) from showing.
The line was:

{% if state_attr('sensor.weather_alerts','entries') != 0 %}

I think this always triggers (hence the {% else %} never triggers. I think it should either be:

{% if state_attr('sensor.weather_alerts','entries') != [] %}

or:

{% if states('sensor.weather_alerts','entries') != 0 %}

as the attribute is an array and the state is a number. I cannot check this until the next genuine warning so will post back when that happens.

There are probably others now, but today there is a warning for the southwest, which is what I use, so for testing, you could use this url:

https://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/sw

I’ve been waiting for a warning to crop up so I can do a bit of fine tuning on my card, so that’s todays job now!

Right, so I modified my package to using SW, Cornwall and affecting South West England: and it works just fine!

So, in summary, this is known to work (still) for SE / Oxon for those that want to copy/paste:

Package:

sensor: #-----------------------------------------------------------------------
- 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

template: #---------------------------------------------------------------------
- sensor:
    - name: "Weather Alerts Oxfordshire" # used for conditional card and automation as sensor.weather_alerts also shows non-Oxfordshire alerts
      state: >
        {{ state_attr('sensor.weather_alerts','entries')
          | map(attribute='summary')
          | select('search', 'Oxfordshire') 
          | list
          | count
        }}

automation: #-------------------------------------------------------------------
- alias: "Weather: Notify weather warnings"
  id: weather_notify_warnings
  trigger:
    - platform: state
      entity_id: sensor.weather_alerts_oxfordshire
  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) and item.summary | regex_findall('Oxfordshire', 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:
    - "{{ trigger.to_state.state not in ['unknown', 'unavailable','0'] }}"
    - "{{ trigger.from_state.state not in ['unknown', 'unavailable','0'] }}"
  action:
    - service: notify.notify
      data:
        title: "Met Office"
        message: "{{ message }}"
        data:
          tag: weather_alert  # will replace earlier alerts with this tag

Markdown card:

- type: markdown
  content: >
    {% if state_attr('sensor.weather_alerts','entries') != [] %}
      {% 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) and item.summary | regex_findall('Oxfordshire', 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 }}**, {{ date_from }} |

    | to: | **{{ time_local_to }}**, {{ date_to }} |
        {% endfor %}
    <br>
      {% endfor %}
    {% else %} No warnings at present
    {% endif %}

If anyone needs help converting it to their location, please ask! :slight_smile:

1 Like

Having a problem with the card.

Are you putting this into a custom card or a markdown card?

type: markdown
content: >-
  {% if state_attr('sensor.weather_alerts','entries') != [] %}
    {% 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.somerset', ignorecase=True) and item.summary | regex_findall('Somerset', ignorecase=True) %}
        {% set color = item.summary.split(' ')[0] %}
        {% set summary = item.summary | regex_findall_index('(.*) affecting South West 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 }}**, {{ date_from }} |

  | to: | **{{ time_local_to }}**, {{ date_to }} |
      {% endfor %}
  <br>
    {% endfor %}
  {% else %} No warnings at present {% endif %}

It’s a markdown card.

Your code is missing the leading dash - is that the problem?

- type: markdown

Does anyone have any examples of how they are displaying the alert information on their dashboard? I’m using browser mod to generate a popup when I click on my conditional custom button card which tells me there are alerts. It’s very minimal, and I would like to improve the styling, but CSS isn’t my strong point, and trying to change the icon size and reposition it centrally is proving difficult, as the element seems buried very deep. This is all that shows currently in my popup:

image

Looking for some ideas based on how others are displaying these alerts if anyone can help?

I have a whole bunch of mushroom-chip-cards as a horizontal bar at the top of my dashboard that only show if that alarm is ‘sounding’.

I the example below, the cloud one tells me there is a weather alert (you can also see I have a low battery):
Screenshot 2023-11-30 at 11.23.45

Clicking on that gives me this:
Screenshot 2023-11-30 at 11.30.12

It will show as many alerts as there are in a vertical list.

1 Like