I'm trying to write an automation that turns on my air conditioner to cool the house if the forecast top temperature for the day is in excess of some value (currently 26 celcius).
To access the value I have to call the built-in weather integration for daily forecasts, then get the "temperature" value out of the first item in the response. However, HomeAssistant doesn't seem to be able to access it because the key is weather.forecast_home which contains a ., so it tries to access an object called weather and then a lower-level object called forecast_home. Here's the YAML:
actions:
- target:
entity_id: weather.forecast_home
data:
type: daily
response_variable: todays_forecast
action: weather.get_forecasts
- if:
- condition: template
value_template: >-
{{ todays_forecast.weather.forecast_home.forecast[0].temperature > 26
}}
then:
- action: remote.send_command
metadata: {}
data:
num_repeats: 10
delay_secs: 0.4
hold_secs: 0
device: lounge_air_conditioner
command: cool_mode
target:
entity_id: remote.lounge_room_broadlink
When I checked the automation traces, I can see that the variable was set correctly:
context:
id: 01JNW37496DBN0B8K2G2Z3MT2H
parent_id: null
user_id: null
todays_forecast:
weather.forecast_home:
forecast:
- condition: partlycloudy
datetime: '2025-03-09T01:00:00+00:00'
wind_bearing: 9.9
uv_index: 8.7
temperature: 32.9
templow: 22.7
wind_speed: 25.2
precipitation: 7.7
humidity: 39
...
But the conditional failed because it couldn't access the value:
Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'weather'
Is there a different way I can instruct HomeAssistant to access this value that doesn't rely on the overloaded . notation?