Thank you, @Tinkerer, that was an excellent flight level and very helpful in this specific instance.
For the next person running into this, here is a more detailed rundown of what I did to fix my automations:
- Here is the precise code I inserted into
configuration.yaml
:
Code Example (no longer functional)
template:
- trigger:
- platform: time_pattern
minutes: "*"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
action:
- service: weather.get_forecast
target:
entity_id: weather.home
data:
type: hourly
response_variable: hourly_forecast
- service: weather.get_forecast
target:
entity_id: weather.home
data:
type: daily
response_variable: daily_forecast
sensor:
- name: "Weather Hourly"
unique_id: home_hourly
state: "{{ states('weather.home') }}"
attributes:
temperature: "{{ state_attr('weather.home', 'temperature') }}"
dew_point: "{{ state_attr('weather.home', 'dew_point') }}"
temperature_unit: "{{ state_attr('weather.home', 'temperature_unit') }}"
humidity: "{{ state_attr('weather.home', 'humidity') }}"
cloud_coverage: "{{ state_attr('weather.home', 'cloud_coverage') }}"
pressure: "{{ state_attr('weather.home', 'pressure') }}"
pressure_unit: "{{ state_attr('weather.home', 'pressure_unit') }}"
wind_bearing: "{{ state_attr('weather.home', 'wind_bearing') }}"
wind_gust_speed: "{{ state_attr('weather.home', 'wind_gust_speed') }}"
wind_speed: "{{ state_attr('weather.home', 'wind_speed') }}"
wind_speed_unit: "{{ state_attr('weather.home', 'wind_speed_unit') }}"
visibility: "{{ state_attr('weather.home', 'visibility') }}"
visibility_unit: "{{ state_attr('weather.home', 'visibility_unit') }}"
precipitation: "{{ state_attr('weather.home', 'precipitation') }}"
precipitation_unit: "{{ state_attr('weather.home', 'precipitation_unit') }}"
forecast: "{{ hourly_forecast.forecast[:5] }}"
- name: "Weather Daily"
unique_id: home_daily
state: "{{ states('weather.home') }}"
attributes:
temperature: "{{ state_attr('weather.home', 'temperature') }}"
dew_point: "{{ state_attr('weather.home', 'dew_point') }}"
temperature_unit: "{{ state_attr('weather.home', 'temperature_unit') }}"
humidity: "{{ state_attr('weather.home', 'humidity') }}"
cloud_coverage: "{{ state_attr('weather.home', 'cloud_coverage') }}"
pressure: "{{ state_attr('weather.home', 'pressure') }}"
pressure_unit: "{{ state_attr('weather.home', 'pressure_unit') }}"
wind_bearing: "{{ state_attr('weather.home', 'wind_bearing') }}"
wind_gust_speed: "{{ state_attr('weather.home', 'wind_gust_speed') }}"
wind_speed: "{{ state_attr('weather.home', 'wind_speed') }}"
wind_speed_unit: "{{ state_attr('weather.home', 'wind_speed_unit') }}"
visibility: "{{ state_attr('weather.home', 'visibility') }}"
visibility_unit: "{{ state_attr('weather.home', 'visibility_unit') }}"
precipitation: "{{ state_attr('weather.home', 'precipitation') }}"
precipitation_unit: "{{ state_attr('weather.home', 'precipitation_unit') }}"
forecast: "{{ daily_forecast.forecast[:5] }}"
(This code is based on the mentioned GitHub post and will work without any changes needed as long as you are using the weather.home
entity.)
Above code example does no longer work since it still uses the weather.get_forecast
service call, which has been deprecated. See my post below for the updated, working version of this code.
This should create an entity sensor.weather_hourly
(and also an entity sensor.weather_daily
), which should contain the following:
temperature: 5.7
dew_point: -0.7
temperature_unit: °C
humidity: 63
cloud_coverage: 0
pressure: 1016.4
pressure_unit: hPa
wind_bearing: 97
wind_gust_speed: null
wind_speed: 18
wind_speed_unit: km/h
visibility: null
visibility_unit: km
precipitation: null
precipitation_unit: mm
forecast:
- condition: sunny
datetime: '2024-03-08T11:00:00+00:00'
wind_bearing: 98.8
cloud_coverage: 0
temperature: 7.4
wind_speed: 19.4
precipitation: 0
humidity: 59
- condition: sunny
datetime: '2024-03-08T12:00:00+00:00'
wind_bearing: 96.2
cloud_coverage: 0
temperature: 8.6
wind_speed: 22
precipitation: 0
humidity: 54
- condition: sunny
datetime: '2024-03-08T13:00:00+00:00'
wind_bearing: 97.5
cloud_coverage: 0
temperature: 9.4
wind_speed: 23
precipitation: 0
humidity: 52
- condition: partlycloudy
datetime: '2024-03-08T14:00:00+00:00'
wind_bearing: 108.1
cloud_coverage: 17.2
temperature: 9.9
wind_speed: 25.2
precipitation: 0
humidity: 50
- condition: sunny
datetime: '2024-03-08T15:00:00+00:00'
wind_bearing: 103.3
cloud_coverage: 0
temperature: 9.6
wind_speed: 22.3
precipitation: 0
humidity: 51
friendly_name: Weather Hourly
- In automations, change the value template. Where I previously had this:
{{ (states.weather.home_hourly.attributes.forecast[3].temperature) | float < 16 }}
I changed into this:
{{ (states.sensor.weather_hourly.attributes.forecast[3].temperature) | float < 16 }}
Note: I had to both change weather
to sensor
(because the above code does provide an entity of the type sensor
while the previous entity was of the type weather
) and home_hourly
to weather_hourly
(because the above code specifies the unique_id
as weather_hourly
).
Another way would be to use state_attr()
as strongly suggested in the documentation:
{{ state_attr('sensor.weather_hourly','forecast')[3]['temperature'] | float < 16 }}
If you test the condition inside automations, please note that if you are running “Test” on a condition while it is disabled, the test will always fail. This did cost me the better part of an hour to figure out.
- Save the file, check the syntax, restart Home Assistant.