I am lost in the sauce while trying to make my old TTS weather announcement work with the new changes to weather and forecast. I am hoping someone could give me a quick hand to adjust.
The below returns a “None has no element 0” error, and while I understand why, I can’t figure out what adjustments I need to make this work. I appreciate any guidance, I am still very new to jinja. TIA
service: tts.cloud_say
data:
entity_id: media_player.master_bathroom_display
message: >-
{% set state = states('weather.home') %} {% set temperature =
state_attr('weather.home', 'temperature') %} {% set humidity =
state_attr('weather.home', 'humidity') %} {% set windspeed =
state_attr('weather.home', 'wind_speed') %} {% set forecast =
state_attr('weather.home', 'forecast')[0] %} {% if state == 'partlycloudy'
%}
{% set state = 'Partly Cloudy' %}
{% endif %} Good Morning Brian! It looks like the weather today will be
{{state}}, with a temperature of {{temperature}} degrees. A high of
{{forecast.temperature}} degrees and a low of {{forecast.templow}} degrees,
with humidity of {{humidity}}%, wind speed of {{windspeed}} miles per hour
and a {{forecast.precipitation}}% chance of rain.
You have to call the get_forecasts now to get the forecast date. So before your call to the tts.cloud_say you need to pull the weather into a response variable:
You’ll have to do a lot of modification to your script to read the hourly (or whatever you call it) response variable. It is available as if you performed a {% set hourly = ... %} command in your script, but it’s not formatted as you would think, but you can see what the format is if you run the get_forecasts by hand in the development service page.
Just in case someone needs help with this, here is the full script YAML code I used to get this working:
alias: Get Weather info
sequence:
- service: weather.get_forecasts
metadata: {}
data:
type: daily
target:
entity_id: weather.home
response_variable: daily
- service: tts.cloud_say
data:
entity_id: media_player.smart_speaker
message: >-
It looks like the weather today will be {{
daily['weather.home'].forecast[0].condition }}, with a temperature of {{
daily['weather.home'].forecast[0].temperature }} degrees and a low of {{
daily['weather.home'].forecast[0].templow }} degrees,
with humidity of {{ daily['weather.home'].forecast[0].humidity }}%, wind speed of {{ daily['weather.home'].forecast[0].wind_speed }} miles per hour
and a {{ daily['weather.home'].forecast[0].precipitation }}% chance of rain.
options:
cache: true
description: ""
icon: mdi:weather-cloudy