Below is my automation, it's intended to send me a notification whenever the temperature will freeze later in the evening. I'm using the National Weather Service as my weather provider.
alias: Check for Freezing Temperatures After Sunrise
description: >-
Queries weather forecast 1 hour after sunrise to check for freezing temps
tonight/tomorrow morning
triggers:
- event: sunrise
offset: "01:00:00"
trigger: sun
conditions: []
actions:
- alias: Get hourly weather forecast
action: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.kgpm
response_variable: weather_forecast
- alias: Check for freezing temperatures
choose:
- conditions:
- condition: template
value_template: >
{% set forecast_data = weather_forecast['weather.kgpm'].forecast %}
{% set now = now() %}
{% set tomorrow_morning = now.replace(hour=12, minute=0, second=0) + timedelta(days=4) %}
{% set weather_entity = states['weather.kgpm'] %}
{% set temp_unit = weather_entity.attributes.temperature_unit %}
{% set freezing_found = false %}
{% for entry in forecast_data %}
{% set forecast_time = as_datetime(entry.datetime) %}
{% if forecast_time >= now and forecast_time <= tomorrow_morning %}
{% if temp_unit == '°F' and entry.temperature <= 32 %}
{% set freezing_found = true %}
{% elif temp_unit == '°C' and entry.temperature <= 0 %}
{% set freezing_found = true %}
{% endif %}
{% endif %}
{% endfor %}
{{ freezing_found }}
sequence:
- alias: Notify mobile
action: notify.phone
data:
message: "It's gonna freeze tonight, pull in the bug's sleep medicine."
title: "Shit's getting cold"
default:
- alias: Log no freezing conditions
data:
title: No Freezing Forecast
message: |
No freezing temperatures forecasted for tonight/tomorrow morning.
action: persistent_notification.create
mode: single