I had posted this thread a while back and I thought I had understood the suggestions there but now that I’m trying this, I’m having some major problems getting this to work.
tl;dr - HA has removed the forecast attribute from weather providers in favor of a service call. I’m attempting to re-create existing blueprints to use the new approach.
I’ve created an MVP blueprint where I’m attempting to select a weather provider, a forecast interval, a forecast index, and a specific attribute. It should then display the result as a notification. Here is a working example that will display the entire forecast object as returned by the service call:
blueprint:
name: "Weather forecast notification"
domain: automation
input:
weather_provider:
name: "Weather provider"
description: "Select the weather provider to obtain the forecast"
selector:
entity:
domain: weather
forecast_interval:
name: "Forecast interval"
description: 'Forecast interval, one of "hourly", "twice daily", or "daily". Not all intervals are available for all providers.'
default: "daily"
selector:
select:
options:
- "hourly"
- "twice_daily"
- "daily"
forecast_index:
name: "Forecast index"
description: 'Select a specific forecast, the current time interval will be index "0". Increment this number for future forecasts based on the interval above. For example, a "daily" interval with index 2 will be the daily forecast 2 days from now'
default: 0
selector:
number:
min: 0
max: 48
mode: slider
unit_of_measurement: index
forecast_attribute:
name: "Enter the desired forecast attribute"
description: 'Type in the name of the desired forecast attribute for your provider. "condition" is a common attribute for many providers.'
default: "condition"
selector:
text:
variables:
weather_provider: !input weather_provider
forecast_interval: !input forecast_interval
forecast_index: !input forecast_index
forecast_attribute: !input forecast_attribute
trigger:
action:
- service: weather.get_forecasts
target:
entity_id: !input weather_provider
data:
type: "{{forecast_interval}}"
response_variable: weather_forecast
- service: notify.persistent_notification
data:
title: "Weather Forecast"
message: "Forecast: {{ weather_forecast }}"
For test purposes, I’ve selected the following:
weather_provider: weather.home
forecast_interval: daily
forecast_index: 2
This works and displays something like:
Forecast: {'weather.home': {'forecast': [{'condition': 'sunny', 'datetime': '2024-05-08T16:00:00+00:00', 'wind_bearing': 297.0, 'temperature': 72, 'templow': 57, 'wind_speed': 9.38, 'precipitation': 0.0, 'humidity': 58}, {'condition': 'cloudy', 'datetime': '2024-05-09T16:00:00+00:00', 'wind_bearing': 68.8, 'temperature': 61, 'templow': 49, 'wind_speed': 15.66, 'precipitation': 0.16, 'humidity': 71}, {'condition': 'cloudy', 'datetime': '2024-05-10T16:00:00+00:00', 'wind_bearing': 305.9, 'temperature': 62, 'templow': 43, 'wind_speed': 9.63, 'precipitation': 0.06, 'humidity': 47}, {'condition': 'rainy', 'datetime': '2024-05-11T16:00:00+00:00', 'wind_bearing': 318.9, 'temperature': 59, 'templow': 49, 'wind_speed': 11.43, 'precipitation': 0.25, 'humidity': 58}, {'condition': 'partlycloudy', 'datetime': '2024-05-12T16:00:00+00:00', 'wind_bearing': 272.7, 'temperature': 65, 'templow': 43, 'wind_speed': 6.28, 'precipitation': 0.0, 'humidity': 43}, {'condition': 'partlycloudy', 'datetime': '2024-05-13T16:00:00+00:00', 'wind_bearing': 236.2, 'temperature': 68, 'templow': 56, 'wind_speed': 12.74, 'precipitation': 0.07, 'humidity': 60}]}}
What I’d like to do is to display the specific forecast details as selected by the user, so I want to substitute “weather.home” and “forecast[2]” and “condition” with the settings selected by the user.
Things that don’t work
- service: notify.persistent_notification
data:
title: "Weather Forecast"
message: "{{ weather_forecast }}"
Error: template value should be a string for dictionary value @ data['message']
I can’t just dump the object itself, I have to add some text to make this a string.
- service: notify.persistent_notification
data:
title: "Weather Forecast"
message: "Forecast: {{ weather_forecast.weather_provider }}"
Error: Template variable warning: 'dict object' has no attribute 'weather_provider' when rendering 'Forecast: {{ weather_forecast.weather_provider }}'
The notification displays as just “Forecast:” Not sure how I can use a variable name here for the weather_provider
The eventual goal is to grab the specified forecast as text, do some manipulation on that text, and then save that variable for use later (mostly, being sent out via MQTT). Here’s an example of what that might look like:
action:
- variables:
text: {{ weather_forecast.weather_provider.forecast[forecast_index][forecast_attribute]|replace("windy-variant","windy")|replace("clear-night","clear night")|replace("partlycloudy","partly cloudy")|replace("lightning-rainy","lightning & rain")|replace("snowy-rainy","snow & rain") | title }}
Is there any way to do this at runtime with a user-selected weather provider?