Hourly Weather Alert Notifier

Weather Forecast Alert Helper

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Blueprint Yaml
blueprint:
  name: Weather Forecast Alert Helper
  description: |
    # Weather Forecast Alert Helper

    ## Description
    This blueprint creates a weather forecast alert automation that sends a notification when the hourly weather forecast meets the specified conditions.

    Do you want to be notified when the temperature drops below a certain threshold, when it's going to rain, or when it's going to snow? This blueprint allows you to set up mobile app notifications for these conditions.

    ## How it works
    This blueprint operates using the following logic, handled internally by Jinja templates:

    1. Fetch the hourly weather forecast for the next 24 hours using the `weather.get_forecasts` action (with `{"data": {"type": "hourly"}}`).
    2. Filter the result into multiple lists of hourly weather conditions which meet the specified conditions (one list for each condition).
    3. If any of the lists have a length greater than the specified threshold (i.e. the condition was met for the required number of hours), send a notification with the details of the alert(s).
       - The notification will include an alert for any list having a length greater than the threshold.

    ## Set-up
    1. Create a [weather entity](https://www.home-assistant.io/integrations/weather/) in Home Assistant.
    2. Create a [notification service integration](https://www.home-assistant.io/integrations/notify/) in Home Assistant (recommended using [Notify Groups](https://www.home-assistant.io/integrations/group/#notify-groups)).
    3. (Optional) Create a [schedule or time helper entity](https://www.home-assistant.io/integrations/input_datetime/) in Home Assistant to trigger the automation
       - Alternatively, you can use a time-based trigger in the automation editor.
    4. Enable the desired alert conditions (cold, rain, snow) and set the desired thresholds to be used for each condition.

    ## Recommended Use Cases
    - If you live in a snowy climate, notify of upcoming overnight snowfall in order to plan for snow removal.
    - If you have a garden, notify of upcoming rain, or risk of frost/freezing temperatures.
  domain: automation
  author: travipross
  input:
    alert_triggers:
      name: Alert Trigger(s)
      description: The trigger(s) to use for the alert. Recommended to use a schedule or time helper entity.
      selector:
        trigger:
    weather_entity:
      name: Weather Entity
      description: The weather entity from which to retrieve [hourly forecast](https://www.home-assistant.io/integrations/weather/#action-weatherget_forecasts).
      selector:
        entity:
          domain: weather
    notify_service:
      name: Notify Service
      description: The service to use for notifications (e.g., notify.<my_notify_service>). **Do not include the `notify.` domain.**
      selector:
        text:
    enable_snow_alert:
      name: Enable Snow Alerts
      description: Enable snow alert.
      default: true
      selector:
        boolean: {}
    enable_rain_alert:
      name: Enable Rain Alerts
      description: Enable rain alert.
      default: true
      selector:
        boolean: {}
    enable_cold_alert:
      name: Enable Cold Alerts
      description: Enable cold alert.
      default: true
      selector:
        boolean: {}
    enable_hot_alert:
      name: Enable Heat Alerts
      description: Enable heat alert.
      default: false
      selector:
        boolean: {}
    num_hours_threshold:
      name: Hours Threshold
      description: The number of hours the provided condition(s) must be met in order to warrant an alert.
      default: 2
      selector:
        number:
          min: 1
          max: 24
          mode: slider
          step: 1
    num_hours_to_check:
      name: Hours to Check
      description: The number of hours to check in the forecast. **Note:** The maximum number of hours that can be checked is 24, as that is what would typically be returned by the call to fetch the hourly forecast.
      default: 12
      selector:
        number:
          min: 1
          max: 24
          mode: slider
          step: 1
    min_temp_threshold:
      name: Minimum Temperature Threshold
      description: The minimum temperature threshold for cold alerts (in the unit used by your selected weather entity).
      default: 0
      selector:
        number:
          min: -50
          max: 50
          mode: slider
          step: 1
    max_temp_threshold:
      name: Maximum Temperature Threshold
      description: The maximum temperature threshold for heat alerts (in the unit used by your selected weather entity).
      default: 100
      selector:
        number:
          min: -50
          max: 100
          mode: slider
          step: 1
triggers: !input alert_triggers
conditions: []
actions:
  - variables:
      weather_entity: !input weather_entity
      temp_unit: "{{ state_attr(weather_entity, 'temperature_unit') }}"
      notify_group: !input notify_service
      enable_snow: !input enable_snow_alert
      enable_rain: !input enable_rain_alert
      enable_cold: !input enable_cold_alert
      enable_hot: !input enable_hot_alert
      low_temp_threshold: !input min_temp_threshold
      high_temp_threshold: !input max_temp_threshold
      num_hours_threshold: !input num_hours_threshold
      num_hours_lookahead: !input num_hours_to_check
    alias: Define variables from input params
  - action: weather.get_forecasts
    metadata: {}
    data:
      type: hourly
    target:
      entity_id: "{{ weather_entity }}"
    response_variable: action_response
    alias: Get hourly weather for given entity
  - variables:
      forecast: >-
        {{
        action_response[weather_entity]['forecast'][:num_hours_lookahead]
        }}
      datetimes: >-
        {{ forecast | map(attribute='datetime') | map('as_datetime') |
        map('as_local') | list }}
      temps: "{{ forecast | map(attribute='temperature') | list }}"
      min_temp: "{{ temps | min }}"
      max_temp: "{{ temps | max }}"
      min_temp_idx: "{{ temps.index(min_temp) }}"
      max_temp_idx: "{{ temps.index(max_temp) }}"
      min_temp_hour: "{{ forecast[min_temp_idx]['datetime'] | as_datetime | as_local }}"
      max_temp_hour: "{{ forecast[max_temp_idx]['datetime'] | as_datetime | as_local }}"
      avg_temp: "{{ temps | average | round(1) }}"
      cold_hours: >-
        {{ forecast | selectattr('temperature', 'le', low_temp_threshold) | list
        }}
      hot_hours: >-
        {{ forecast | selectattr('temperature', 'ge', high_temp_threshold) | list
        }}
      snowy_hours: >-
        {{ forecast | selectattr('condition', 'search', '(?i)snow|flurr(y|ies)')
        | list }}
      rainy_hours: "{{ forecast | selectattr('condition', 'search', '(?i)rain') | list }}"
      precip_prob_snowy_hours: "{{ snowy_hours | map(attribute='precipitation_probability') | list }}"
      precip_prob_rainy_hours: "{{ rainy_hours | map(attribute='precipitation_probability') | list }}"
      cold_alert: "{{ enable_cold and cold_hours | count > num_hours_threshold }}"
      hot_alert: "{{ enable_hot and hot_hours | count > num_hours_threshold }}"
      rain_alert: "{{ enable_rain and rainy_hours | count > num_hours_threshold }}"
      snow_alert: "{{ enable_snow and snowy_hours | count > num_hours_threshold }}"
    alias: Parse response and define new variables
  - alias: If any weather conditions warrant notification
    condition: template
    value_template: "{{ cold_alert or rain_alert or snow_alert or hot_alert}}"
  - variables:
      notification_message: >
        {% macro format_datetime(d) %}{{ d | as_timestamp |
        timestamp_custom("%I:%M %p") }}{% endmacro %} Over the next {{
        num_hours_lookahead }} hours:


        {% if cold_alert %} Temperature: Temps will dip below {{
        low_temp_threshold }}{{ temp_unit }} for {{ cold_hours | count }} hours,
        initially reaching a minimum of {{ min_temp }}{{ temp_unit }} at
        {{format_datetime(min_temp_hour)}} (avg={{ avg_temp }}{{ temp_unit }}).
        {%endif %}


        {% if hot_alert %} Temperature: Temps will rise_above {{
        high_temp_threshold }}{{ temp_unit }} for {{ hot_hours | count }} hours,
        initially reaching a maximum of {{ max_temp }}{{ temp_unit }} at
        {{format_datetime(max_temp_hour)}} (avg={{ avg_temp }}{{ temp_unit }}).
        {%endif %}


        {% if rain_alert %} Rain: It will be rainy for {{ rainy_hours | count }}
        hours (max_prob={{ (precip_prob_rainy_hours or [0]) | max }}%,
        avg_prob={{(precip_prob_rainy_hours or [0]) | average }}%). {% endif %}


        {% if snow_alert %} Snow: It will be snowy for {{ snowy_hours | count }}
        hours (max_prob={{ (precip_prob_snowy_hours or [0]) | max }}%,
        avg_prob={{(precip_prob_snowy_hours or [0]) | average }}%). {% endif %}
      notification_title: >-
        Weather alert: {{ ["Temperature" if (cold_alert or hot_alert), "Rain" if rain_alert,
        "Snow" if snow_alert] | select() | join(", ") }}
  - action: notify.{{ notify_group }}
    metadata: {}
    data:
      message: "{{ notification_message }}"
      title:  "{{ notification_title }}"
      data:
        ttl: 0
        priority: high
        tag: WEATHER_ALERT
        sticky: true
        clickAction: entityId:{{ weather_entity }}
        notification_icon: mdi:weather-cloudy-alert
mode: single


Description

This blueprint creates a weather forecast alert automation that sends a notification when the hourly weather forecast meets the specified conditions.

Do you want to be notified when the temperature drops below / rises above a certain threshold, when it’s going to rain, or when it’s going to snow? This blueprint allows you to set up mobile app notifications for these conditions.

How it works

This blueprint operates using the following logic, handled internally by Jinja templates:

  1. Fetch the hourly weather forecast for the next 24 hours using the weather.get_forecasts action (with {"data": {"type": "hourly"}}).
  2. Filter the result into multiple lists of hourly weather conditions which meet the specified conditions (one list for each condition).
  3. If any of the lists have a length greater than the specified threshold (i.e. the condition was met for the required number of hours), send a notification with the details of the alert(s).
    • The notification will include an alert for any list having a length greater than the threshold.

Set-up

  1. Create a weather entity in Home Assistant.
  2. Create a notification service integration in Home Assistant (recommended using Notify Groups).
  3. (Optional) Create a schedule or time helper entity in Home Assistant to trigger the automation.
    • Alternatively, you can use a time-based trigger in the automation editor.
  4. Enable the desired alert conditions (cold, rain, snow) and set the desired thresholds to be used for each condition.

Recommended Use Cases

  • If you live in a snowy climate, notify of upcoming overnight snowfall in order to plan for snow removal.
  • If you have a garden, notify of upcoming rain, or risk of frost/freezing temperatures.

Changelog

  • 2025-01-05: (commit) initial blueprint
  • 2025-01-05: (commit) added heat alerts
  • 2025-01-12: (commit) removed unnecessary linebreaks in message body

I just started to play around with this and I like it.
Wonder if it would be possible to add a couple of other things to it.
You now have snow, rain and cold.
Where I live (Phoenix) snow is typically not a problem!
But we do have heat, dust and poluttion alerts.
Is that something you might think about adding?

Thanks for blueprint.

Hey, yeah, that should be doable in one way or another. I’ll see if i can brainstorm a way to make arbitrary filters on the hourly forecast results to trigger additional alert categories.

In the mean time, I’ve added a heat alert option that acts as the inverse of the cold alert.

Unfortunately the values returned for a weather.get_forecast action can vary between weather providers, so it might be hard to make a “one size fits all” solution for all weather conditions.

Do you maybe have some example values for the conditions field that the blueprint might be able to look for in the forecast response? Right now I’m just doing some regex matching to look for the words “rain”, “snow”, etc, but I’ve mostly tailored the filters to match what I’m seeing from the Environment Canada integration for my Canadian location.

I will try to answer as best as I can.
I currently use a number of “hacs” items to check out conditions.
One is the NWS (National Weather Service) alerts system. Through an automation I have it will alert me of NWS alerts. Wheather they are Heat, Air Quality, or Dust as well as a few more.
I also use Weatherflow to go with my Weather Station I have.
Weatherflow has an IoS and Android App called heat alert, but their regular HA HACS app contains a heat index, which at 9AM is 47.48 (current temp)

state_class: measurement
unit_of_measurement: °F
attribution: Weather data delivered by WeatherFlow/Tempest REST Api
device_class: temperature
friendly_name: 5123home Weatherflow Cloud Heat index

If this is not what you are looking for please let me know.

Here is a sample of an NWS Alert Event, for my daughter who lives in Milwaukee so that you can see what data it provides.

Filter State - Winter Weather Advisory
friendly_name: Milwaukee NWS Alert Event
features: 
- id: >-
    https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.549ec4b75e6e8d6968a70ac7efd2e9feea093e22.001.1
  type: Feature
  geometry: null
  properties:
    '@id': >-
      https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.549ec4b75e6e8d6968a70ac7efd2e9feea093e22.001.1
    '@type': wx:Alert
    id: urn:oid:2.49.0.1.840.0.549ec4b75e6e8d6968a70ac7efd2e9feea093e22.001.1
    areaDesc: Milwaukee; Racine; Kenosha
    geocode:
      SAME:
        - '055079'
        - '055101'
        - '055059'
      UGC:
        - WIZ066
        - WIZ071
        - WIZ072
    affectedZones:
      - https://api.weather.gov/zones/forecast/WIZ066
      - https://api.weather.gov/zones/forecast/WIZ071
      - https://api.weather.gov/zones/forecast/WIZ072
    references:
      - '@id': >-
          https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.0b95c7a5c7084f4d21104c3596e28b8edce6875f.001.1
        identifier: urn:oid:2.49.0.1.840.0.0b95c7a5c7084f4d21104c3596e28b8edce6875f.001.1
        sender: [email protected]
        sent: '2025-01-06T03:36:00-06:00'
    sent: '2025-01-06T09:15:00-06:00'
    effective: '2025-01-06T09:15:00-06:00'
    onset: '2025-01-06T09:15:00-06:00'
    expires: '2025-01-06T16:00:00-06:00'
    ends: '2025-01-06T16:00:00-06:00'
    status: Actual
    messageType: Update
    category: Met
    severity: Moderate
    certainty: Likely
    urgency: Expected
    event: Winter Weather Advisory
    sender: [email protected]
    senderName: NWS Milwaukee/Sullivan WI
    headline: >-
      Winter Weather Advisory issued January 6 at 9:15AM CST until January 6 at
      4:00PM CST by NWS Milwaukee/Sullivan WI
    description: |-
      ...LAKE EFFECT SNOW ONGOING ACROSS SOUTHEAST WISCONSIN THIS
      MORNING...

      .Areas of lake effect snow have moved onshore across southeastern
      Wisconsin this morning. Activity will continue through the morning
      hours, gradually shifting offshore early this afternoon. Additional
      totals between 0.5 and 2 inches are possible in Milwaukee County,
      with highest totals focusing over the far southeast corner of the
      county. Additional totals between 2 and 3 inches are possible to the
      east of I-94 in Racine and Kenosha Counties.

      * WHAT...Lake effect snow. Additional snow accumulations up to two
      inches in southeastern Milwaukee County. Additional totals between
      2 and 3 inches possible east of I-94 in Kenosha and Racine
      Counties.

      * WHERE...Kenosha, Milwaukee, and Racine Counties.

      * WHEN...Until 4 PM CST this afternoon.

      * IMPACTS...Plan on slippery road conditions.
    instruction: |-
      Slow down and use caution while traveling. The latest road
      conditions for the state you are calling from can be obtained by
      calling 5 1 1.
    response: Execute
    parameters:
      AWIPSidentifier:
        - WSWMKX
      WMOidentifier:
        - WWUS43 KMKX 061515
      NWSheadline:
        - >-
          WINTER WEATHER ADVISORY REMAINS IN EFFECT UNTIL 4 PM CST THIS
          AFTERNOON
      BLOCKCHANNEL:
        - EAS
        - NWEM
        - CMAS
      VTEC:
        - /O.CON.KMKX.WW.Y.0001.000000T0000Z-250106T2200Z/
      eventEndingTime:
        - '2025-01-06T22:00:00+00:00'
      expiredReferences:
        - >-
          [email protected],urn:oid:2.49.0.1.840.0.14f808bbc8c7393466fb43284e0dc6eb676f220e.002.1,2025-01-06T00:03:00-06:00
          [email protected],urn:oid:2.49.0.1.840.0.14f808bbc8c7393466fb43284e0dc6eb676f220e.001.1,2025-01-06T00:03:00-06:00
          [email protected],urn:oid:2.49.0.1.840.0.9328c4f9460dbb004e6a16f4d4489bb1297eaf7b.001.1,2025-01-05T21:17:00-06:00
          [email protected],urn:oid:2.49.0.1.840.0.d43abec466d3d16d6e4f8b6f412a50a8d1c40e67.001.1,2025-01-05T21:13:00-06:00
          [email protected],urn:oid:2.49.0.1.840.0.36fd299d85979795c0fa73272426936c53f8ebec.001.1,2025-01-05T15:27:00-06:00
          [email protected],urn:oid:2.49.0.1.840.0.92aa0b6e947698252b18b4a2473d6c71367cffa8.001.1,2025-01-05T11:59:00-06:00


Thank you for the sample data.

After looking a bit closer, I’m not sure I’ll be able to easily integrate this into the current blueprint as it is now; I initially built this for my preferred weather provider’s hourly forecast data, intended to be triggered to fetch that hourly data on a scheduled interval. Reacting to these advisory events as triggers would require a bit of extra complexity in the templating that I’m not sure I’d be able to reliably maintain in a way that keeps the current functionality simple and robust.

It looks like those events would be well suited for one-off automations or perhaps a separate blueprint though. Best of luck!

Thank you for trying.
Appreciate the blueprint otherwise.