MrBartusek / MeteoalarmCard

Meteoalarm, Météo-France and DWD severe weather warnings card for Home Assistant Lovelace UI ⛈️
MIT License
135 stars 48 forks source link

request: (UK) Met office filtered by area #272

Closed RedNo7 closed 1 week ago

RedNo7 commented 1 week ago

Describe the solution you'd like The UK's Met office issues alerts by region and so it would be great to be able to get alerts for your own region.

https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2024-11-19&id=6d1eb807-c2a7-42e4-b58f-bb2035594523

There are 4 alerts for today: Additional context Screenshot 2024-11-19 at 13 42 52

The Welsh (bottom left alert) gives this pop-up: Screenshot 2024-11-19 at 13 43 14

If one scroll's down the pop-up, you can find the regions affected by this particular alert: Screenshot 2024-11-19 at 13 43 25

I can scrape this now (so I already have it in HA, but it'd be great to use your fantastic card). Here is the scrape info I use in case it helps:

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

template: #---------------------------------------------------------------------
  - sensor:
      - name: "Weather Alerts Oxfordshire" # for conditional card & markdown card as weather_alerts can be !=0 but have no Oxfordshire content
        state: >
          {{ state_attr('sensor.weather_alerts','entries')
            | map(attribute='summary')
            | select('search', 'Oxfordshire')
            | list
            | count
          }}

and this is the card I use to display it:

    - type: markdown
      content: >
        {% if states('sensor.weather_alerts_oxfordshire') != '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 %}

Thanks for your consideration.

MrBartusek commented 1 week ago

We only support core and custom warning integrations. We won't support feedparser based warnings.