Created
November 7, 2025 13:14
-
-
Save miklosbagi/2d4993ba3692d76df7bc02269fa1cfb7 to your computer and use it in GitHub Desktop.
Home Assistant freeze alert template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {# ============================ | |
| MOCK DATA FOR TEMPLATE EDITOR | |
| Remove this whole block in the real automation | |
| ============================ #} | |
| {% if not wx %} | |
| {% set wx = { | |
| 'weather.openweathermap_forecast': { | |
| 'forecast': [ | |
| { | |
| 'datetime': '2025-11-07T13:00:00+00:00', | |
| 'condition': 'sunny', | |
| 'temperature': 13.6, | |
| 'pressure': 1018, | |
| 'cloud_coverage': 0, | |
| 'wind_speed': 7.42, | |
| 'wind_bearing': 94, | |
| 'uv_index': 0.9, | |
| 'precipitation_probability': 0, | |
| 'precipitation': 0, | |
| 'apparent_temperature': 12.4, | |
| 'dew_point': 3.7, | |
| 'wind_gust_speed': 9.76, | |
| 'humidity': 51 | |
| } | |
| ] | |
| }, | |
| 'weather.forecast_home': { | |
| 'forecast': [ | |
| { | |
| 'datetime': '2025-11-07T13:00:00+00:00', | |
| 'condition': 'sunny', | |
| 'temperature': 14.3, | |
| 'wind_bearing': 74.9, | |
| 'cloud_coverage': 0, | |
| 'uv_index': 0.7, | |
| 'wind_speed': 7.9, | |
| 'precipitation': 0, | |
| 'humidity': 54 | |
| } | |
| ] | |
| }, | |
| 'weather.home': { | |
| 'forecast': [ | |
| { | |
| 'datetime': '2025-11-07T14:00:00+00:00', | |
| 'condition': 'sunny', | |
| 'temperature': -1, | |
| 'precipitation': 0 | |
| } | |
| ] | |
| } | |
| } %} | |
| {% endif %} | |
| {# ============================ | |
| REAL LOGIC (use this part in automation) | |
| ============================ #} | |
| {% set start = today_at('18:00') %} | |
| {% set end = today_at('06:00') + timedelta(days=1) %} | |
| {% set ns = namespace(any_cold=false, matches=[]) %} | |
| {% if wx is defined %} | |
| {# wx is a dict keyed by entity_id; each value has .forecast (list) #} | |
| {% for v in wx.values() %} | |
| {% for p in (v.forecast | default([])) %} | |
| {% set t = as_local(as_datetime(p.datetime)) %} | |
| {% set temp = (p.temperature | default(p.native_temperature)) %} | |
| {% if t >= start and t <= end and (temp | float(99)) <= 1 %} | |
| {% set ns.any_cold = true %} | |
| {# Safe reassignment instead of .append() #} | |
| {% set ns.matches = ns.matches + [{'t': t, 'temp': temp}] %} | |
| {% endif %} | |
| {% endfor %} | |
| {% endfor %} | |
| {% endif %} | |
| {# ===== Output for automation (boolean) ===== #} | |
| {{ ns.any_cold }} | |
| {# ===== Debug (visible only in Template Editor) ===== #} | |
| {% if ns.matches | length == 0 %} | |
| {# No matches in the window #} | |
| {{ '\n' }}No forecast hours ≤ 1 °C between 18:00 and 06:00. | |
| {% else %} | |
| {{ '\n' }}Matching hours (local time): | |
| {% for m in ns.matches %} | |
| - {{ m.t }} → {{ m.temp }} °C | |
| {% endfor %} | |
| {% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment