Hey experts,
I’ve been stuck working this issue now for a few hours and looking to see if anyone might have a quick fix. Working to create a template that pulls in weather data using weather.get_forecasts and uses response variables to get both daily and hourly data. When using the template I get UndefinedError: ‘hourly’ is undefined even though my format is the exact same as is in the Home Assistant documentation for weather. Any ideas are greatly appreciated!
- trigger:
- platform: time_pattern
minutes: "0" # Runs hourly at minute 0
- platform: homeassistant
event: start # Triggers when Home Assistant starts
action:
- service: weather.get_forecasts
target:
entity_id: weather.forecast_home
data:
type: hourly
response_variable: hourly
- service: weather.get_forecasts
target:
entity_id: weather.forecast_home
data:
type: daily
response_variable: daily
- service: persistent_notification.create
data:
title: "Forecast Output"
message: "{{ hourly }}"
sensor:
- name: Weather Forecast
unique_id: weather_forecast
state: "{{ now().isoformat() }}"
attributes:
now_condition: "{{ hourly['weather.forecast_home'].forecast[0].condition }}"
now_icon: >
{% set weather = hourly['weather.forecast_home'].forecast[0].temperature %}
{% if is_state('sun.sun', 'above_horizon') %}
{{ '/local/weather' + weather|string + '.svg' }}
{% else %}
{{ '/local/weather' + weather|string + '_night.svg' }}
{% endif %}
now_temp: "{{ hourly['weather.forecast_home'].forecast[0].temperature }}"
now_wind_speed: "{{ hourly['weather.forecast_home'].forecast[0].wind_speed }}"
now_wind_bearing: "{{ hourly['weather.forecast_home'].forecast[0].wind_bearing }}"
now_precipitation: "{{ hourly['weather.forecast_home'].forecast[0].precipitation }}"
#now_precipitation_probability: "{{ hourly['weather.forecast_home'].forecast[0].precipitation_probability }}"
now_humidity: "{{ hourly['weather.forecast_home'].forecast[0].humidity }}"
now_feels_like: >
{% set temperature = hourly['weather.forecast_home'].forecast[0].temperature %}
{% set humidity = hourly['weather.forecast_home'].forecast[0].humidity %}
{% set windspeedmps = hourly['weather.forecast_home'].forecast[0].wind_speed / 3.6 %}
{% set e = 2.71828 %}
{% set wvp = (humidity/100) * 6.105 * e**((17.27*temperature) / (237.7 + temperature)) %}
{{(temperature + 0.33 * wvp - 0.70 * windspeedmps - 4.00)|round(2)}}
now_wind_direction: >
{% set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %}
{% set degree = (hourly['weather.forecast_home'].forecast[0].wind_bearing | float) %}
{{ direction[((degree + 11.25) / 22.5) | int] }}
now_wind_desc: >
{% from 'weather_wind.jinja' import get_wind_description %}
{{ get_wind_description(hourly['weather.forecast_home'].forecast[0].wind_speed | float) }}
today_condition: "{{ daily['weather.forecast_home'].forecast[0].condition }}"
today_icon: >
{% set weather = daily['weather.forecast_home'].forecast[0].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
today_temp: "{{ daily['weather.forecast_home'].forecast[0].temperature }}"
today_wind_speed: "{{ daily['weather.forecast_home'].forecast[0].wind_speed }}"
today_wind_bearing: "{{ daily['weather.forecast_home'].forecast[0].wind_bearing }}"
#today_precipitation_probability: "{{ daily['weather.forecast_home'].forecast[0].precipitation_probability }}"
today_humidity: "{{ daily['weather.forecast_home'].forecast[0].humidity }}"
today_feels_like: >
{% set temperature = daily['weather.forecast_home'].forecast[0].temperature %}
{% set humidity = daily['weather.forecast_home'].forecast[0].humidity %}
{% set windspeedmps = daily['weather.forecast_home'].forecast[0].wind_speed / 3.6 %}
{% set e = 2.71828 %}
{% set wvp = (humidity/100) * 6.105 * e**((17.27*temperature) / (237.7 + temperature)) %}
{{(temperature + 0.33 * wvp - 0.70 * windspeedmps - 4.00)|round(2)}}
today_wind_direction: >
{% set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'] %}
{% set degree = (daily['weather.forecast_home'].forecast[0].wind_bearing | float) %}
{{ direction[((degree + 11.25) / 22.5) | int] }}
today_wind_desc: >
{% from 'weather_wind.jinja' import get_wind_description %}
{{ get_wind_description(daily['weather.forecast_home'].forecast[0].wind_speed | float) }}
forc1_datetime: "{{ daily['weather.forecast_home'].forecast[1].datetime}}"
forc1_condition: "{{ daily['weather.forecast_home'].forecast[1].condition }}"
forc1_icon: >
{% set weather = daily['weather.forecast_home'].forecast[1].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
forc1_temp: "{{ daily['weather.forecast_home'].forecast[1].temperature }}"
forc1_precipitation: "{{ daily['weather.forecast_home'].forecast[1].precipitation }}"
forc2_datetime: "{{ daily['weather.forecast_home'].forecast[2].datetime}}"
forc2_condition: "{{ daily['weather.forecast_home'].forecast[2].condition }}"
forc2_icon: >
{% set weather = daily['weather.forecast_home'].forecast[2].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
forc2_temp: "{{ daily['weather.forecast_home'].forecast[2].temperature }}"
forc2_precipitation: "{{ daily['weather.forecast_home'].forecast[2].precipitation }}"
forc3_datetime: "{{ daily['weather.forecast_home'].forecast[3].datetime}}"
forc3_condition: "{{ daily['weather.forecast_home'].forecast[3].condition }}"
forc3_icon: >
{% set weather = daily['weather.forecast_home'].forecast[3].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
forc3_temp: "{{ daily['weather.forecast_home'].forecast[3].temperature }}"
forc3_precipitation: "{{ daily['weather.forecast_home'].forecast[3].precipitation }}"
forc4_datetime: "{{ daily['weather.forecast_home'].forecast[4].datetime}}"
forc4_condition: "{{ daily['weather.forecast_home'].forecast[4].condition }}"
forc4_icon: >
{% set weather = daily['weather.forecast_home'].forecast[4].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
forc4_temp: "{{ daily['weather.forecast_home'].forecast[4].temperature }}"
forc4_precipitation: "{{ daily['weather.forecast_home'].forecast[4].precipitation }}"
forc5_datetime: "{{ daily['weather.forecast_home'].forecast[5].datetime}}"
forc5_condition: "{{ daily['weather.forecast_home'].forecast[5].condition }}"
forc5_icon: >
{% set weather = daily['weather.forecast_home'].forecast[5].temperature %}
{{ '/local/weather' + weather|string + '.svg' }}
forc5_temp: "{{ daily['weather.forecast_home'].forecast[5].temperature }}"
forc5_precipitation: "{{ daily['weather.forecast_home'].forecast[5].precipitation }}"
Thanks again!