Help with TTS Weather Annoucment

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:

  - service: weather.get_forecasts
    data:
      type: hourly
    target:
      entity_id: weather.home
    response_variable: hourly

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
4 Likes

Thank you very much, exactly what I was looking for, does anyone here happen to know how I can get this translated into German? Unfortunately, my announcements are played back in English.

I have tried it with

state_translated , unfortunately I can’t get it to integrate into the template.

https://www.home-assistant.io/blog/2024/03/06/release-20243/#translating-states-in-your-templates

I am grateful for any help.

You need another dictionary from which you will get the translation into your language

        {% set weather_condition = {
          'clear': 'und klar',
          'clear-night': 'und klare Nacht',
          'cloudy': 'und bewölkt',
          'exceptional': 'und außergewöhnlich',
          'fog': 'mit Nebel',
          'hail': 'mit Hagel',
          'lightning': 'mit Gewitter',
          'lightning-rainy': 'mit Gewitter und Regen',
          'partlycloudy': 'und teilweise bewölkt',
          'pouring': 'und strömender Regen',
          'rainy': 'und regnerisch',
          'snowy': 'und verschneit',
          'snowy-rainy': 'mit Schnee und Regen',
          'sunny': 'und sonnig',
          'windy': 'und windig',
          'windy-variant': 'mit Wind und Wolken'
        } %}

{{ weather_condition[daily['weather.forecast_home'].forecast[0].condition]  }}
1 Like

Thanks a lot for your help, got it working now :slight_smile:

data:
  entity_id: media_player.sonos_lautsprecher_schlafzimmer
  message: |-
    {% set weather_condition = {
           'clear': 'und klar',
           'clear-night': 'und klare Nacht',
           'cloudy': 'bewölkt',
           'exceptional': 'und außergewöhnlich',
           'fog': 'mit Nebel',
           'hail': 'mit Hagel',
           'lightning': 'mit Gewitter',
           'lightning-rainy': 'mit Gewitter und Regen',
           'partlycloudy': 'und teilweise bewölkt',
           'pouring': 'und strömender Regen',
           'rainy': 'und regnerisch',
           'snowy': 'und verschneit',
           'snowy-rainy': 'mit Schnee und Regen',
           'sunny': 'und sonnig',
           'windy': 'und windig',
           'windy-variant': 'mit Wind und Wolken'
         } %}  
     Heute ist das Wetter voraussichtlich {{ weather_condition[tageswetter['weather.forecast_home'].forecast[0].condition]  }}, 
     mit einer Höchsttemperatur von {{
     tageswetter['weather.forecast_home'].forecast[0].temperature }} Grad
     und einer Tiefsttemperatur von {{
     tageswetter['weather.forecast_home'].forecast[0].templow }} Grad. 
     Die maximale Windgeschwindigkeit wird bei {{
     tageswetter['weather.forecast_home'].forecast[0].wind_speed }} km/h liegen.
     Die Regenwahrscheinlichkeit liegt bei ca. {{
     tageswetter['weather.forecast_home'].forecast[0].precipitation }}%.
  cache: true
action: tts.cloud_say