Created
August 14, 2025 12:04
-
-
Save JohanAlvedal/48fb8b3e1ef5fc3a70b5c473be54e2fe to your computer and use it in GitHub Desktop.
A comprehensive Home Assistant blueprint that extracts the next 24 hours of temperature forecasts from any weather entity and saves them as a comma-separated string in an input_text entity.
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
blueprint: | |
name: Extract 24 Hourly Temperatures (Sorted) | |
description: > | |
Fetches the next 24 hours of temperature forecasts from any weather entity | |
and saves them to an input_text in comma-separated format "26.8,26.6,26.8,...". | |
Sorts the forecast by datetime to ensure chronological order from current time forward. | |
Perfect for feeding temperature data to other automations, scripts, or dashboards. | |
domain: automation | |
input: | |
weather_entity: | |
name: Weather Entity | |
description: Select the weather entity to extract hourly temperature forecasts from. Tested and verified with SMHI and Met.no weather integrations. | |
selector: | |
entity: | |
domain: weather | |
target_input_text: | |
name: Target Input Text Entity | |
description: The input_text entity where the comma-separated temperature string will be stored | |
selector: | |
entity: | |
domain: input_text | |
default: input_text.hourly_forecast_temperatures | |
interval_pattern: | |
name: Update Interval Pattern (minutes) | |
description: > | |
Specify a time pattern value for minutes. Examples: | |
"/30" (every 30 minutes), "0,30" (at :00 and :30), "15" (at :15 every hour). | |
More frequent updates ensure fresher data but may increase system load. | |
default: "/30" | |
selector: | |
text: | |
multiline: false | |
mode: single | |
max_exceeded: silent | |
variables: | |
weather_eid: !input weather_entity | |
target_entity: !input target_input_text | |
triggers: | |
- trigger: time_pattern | |
minutes: !input interval_pattern | |
- trigger: homeassistant | |
event: start | |
- trigger: event | |
event_type: event_template_reloaded | |
actions: | |
# Fetch hourly forecast using weather.get_forecasts | |
- action: weather.get_forecasts | |
data: | |
type: hourly | |
target: | |
entity_id: "{{ weather_eid }}" | |
response_variable: weather_response | |
# Debug logging for raw weather response | |
- action: system_log.write | |
data: | |
message: "Weather forecast response: {{ weather_response }}" | |
level: info | |
- variables: | |
# Extract forecast data from response (first entity) | |
forecast_data: "{{ weather_response[weather_eid].forecast or [] }}" | |
# Sort by datetime to ensure chronological order | |
sorted_forecast: "{{ forecast_data | sort(attribute='datetime') }}" | |
# Extract temperatures, round to 1 decimal, limit to 24 hours | |
temps: > | |
{{ | |
(sorted_forecast | |
| selectattr('temperature', 'ne', none) | |
| map(attribute='temperature') | |
| map('round', 1) | |
| list)[:24] | |
}} | |
temperature_string: "{{ temps | join(',') }}" | |
# Debug logging to show old vs new values | |
- action: system_log.write | |
data: | |
message: > | |
Temperature update: | |
OLD: {{ states(target_entity) }} | |
NEW: {{ temperature_string }} | |
Forecast entries: {{ forecast_data | length }}, | |
Valid temperatures: {{ temps | length }} | |
level: info | |
# Save the temperature string to input_text entity | |
- action: input_text.set_value | |
target: | |
entity_id: "{{ target_entity }}" | |
data: | |
value: "{{ temperature_string }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment