Using a variable in tts service

Been beating my head against this one for a couple hours. Now that we have a way to get alexa to do tts I’m trying to send basic weather underground information. I’m currently testing in the service development tool with the below.

{"entity_id": "media_player.echo_dot", "message": "The temp is {{ states.sensor.pws_temp_f.state }}"}

No matter what I try for the variable syntax it always reads the variable name instead of getting the value. Ideas?

just my guess, probably with automation and data_template

Yes you’d need a data template to send that over in an automation so I guess it won’t work in the dev tools as this is not data template but a simple data…

Huh. Clearly I need to do more reading. I’d assumed it would just replace it.

here is mine I don’t use alexa as my media_player but i will be doing this very soon.

script:
  james_briefing:
    alias: James Briefing
    sequence:
      - service: tts.google_say
        data_template:
          entity_id: media_player.tts_kodi
          message: >
            {% if now().strftime("%H")|int < 12 %}
            Good morning James.
            {% elif now().strftime("%H")|int < 18 %}
            Good afternoon James.
            {% else %}
            Good evening James.
            {% endif %}
            It's currently {{states.sensor.pws_temp_c.state|round}} degrees in Burleigh but feels like {{states.sensor.pws_feelslike_c.state|round}} degrees. Today will be {{states.sensor.pws_weather_1d_metric.state|replace(".", "")}}.
            {% if now().strftime("%H")|int < 9 and now().strftime("%w")|int > 0and now().strftime("%w")|int < 6 %}
            The current drive to Powertec in traffic is {{states.sensor.commute_to_work.state}}
            {% endif %}
  - service: media_player.alexa_tts
    entity_id: media_player.bedroom_echo_dot
    data_template:
      message: >
        Good morning, Thalles. The time is {{states('sensor.time')}}. It is currently {{states('sensor.dark_sky_apparent_temperature')}} degrees outside. Today's weather is {{states('sensor.dark_sky_summary')}}. There will be a high of {{states('sensor.dark_sky_daytime_high_temperature')}} and a low of {{states('sensor.dark_sky_overnight_low_temperature')}}. We can expect {{states('sensor.dark_sky_hourly_summary')}}
1 Like

Thanks everyone. That did the trick and it works as expected now. Below is what i went with.

temp_briefing:
  alias: Temp Briefing
  sequence:
    - service: media_player.alexa_tts
      data_template:
        entity_id: media_player.echo_dot
        message: >
          {% if now().strftime("%H")|int < 12 %}
          Good morning.
          {% elif now().strftime("%H")|int < 18 %}
          Good afternoon.
          {% else %}
          Good evening.
          {% endif %}
          It's currently {{states.sensor.pws_temp_f.state|round}} degrees.
1 Like