Google Text To Speech; data: vs data_template:

I can’t get data_template: configuration to work.
Here is an example of a scripts.yaml file I have:

test_script2:
  sequence:
    service: tts.google_say
    entity_id: media_player.kitchen_home
    data_template:
      message: 'test {{sensor.pollen.state}}'

When I active this script, nothing happens. It loads fine, but doesn’t seem to do anything. I can’t find any logs that could direct me to why it’s not working.

When I swap the data_template: to data: it works, but reads out the words sensor pollen etc. instead of getting the actual value. For example:

test_script2:
  sequence:
    service: tts.google_say
    entity_id: media_player.kitchen_home
    data:
      message: 'test {{sensor.pollen.state}}'

I’ve been googling this for a while, and found lots of various examples of how this should be done. Some put data_template first and then entity_id, some have multiple layers of data_template: nested inside eachother. Sometime people use ‘single’ and “double” quotes for the text, and sometimes they do:

data_template:
  message: >

I’ve been trying all of these permutations, but still can’t get it to say out my text.
Is there anything obvious that I’m missing? Is there some information I could gather to troubleshoot this?

I’m on running on Raspberry Pi 3, if it matters.
Extra edit: some of the guides I tried following to get this to work: 1, 2, 3, 4, 5

It would be easier if you format your code so we can see if spacing is the problem.

script:
  sayevent:
    sequence:
      service: tts.amazon_polly_say
      entity_id: media_player.speaker
      data_template:
        message: >
            "In 15 minutes {{ states.sensor.eventmessage.state }} begins today"
        cache: true

Apologies. First time here.
Fixed the formatting.

I don’t see a problem with your code, perhaps you can check if your media player works. If you put the media player on the front end, you can TTS directly from the front end media components.

Yes, the player works fine. When I modify the commands from “data_template:” to “data:”, everything works (except it’s not dynamically saying the sensor data).

In case someone finds this in their search, I managed to get it to work. Don’t know why, but this is the only permutation that worked for me:

test_script2:
  sequence:
    service: tts.google_say
    entity_id: media_player.kitchen_home
    data_template:
      message: >-
        test one two three {{states('sensor.pollen_level')}}

Needed to also tweak the sensor call a bit.

2 Likes

Not sure if you also intended to change the sensor but you added _level which might have been the issue.

Nah, it’s just a different sensor. It behaved the same with sensor.pollen and sensor.pollen_level. I’ve been working towards automating a morning greeting with pollen being one of the items on it.
Once I got something working (as per example above), I was able to get everything else working as well. Now it’s listing drive time, weather and pollen for me.

I know this is an old thread but I’m hoping someone can help me replicate the solution. I’ve been trying to embed a sensor value in a TTS . The HA Script creation creates the attached script , but I’ve also tried reordering the call to match the original posters script with the same error. I’m sure something has changed and is more than likely very simple.

Here’s my script that when called gives an “Extra keys not allowed” error and points to the Data statement.

'1565530370302':
  alias: Test TTS Sensor Value
  sequence:
  - data:
      data_template:
        message: test one two three {{states('sensor.attic_temperature')}}
      entity_id: media_player.family_room
    service: tts.google_translate_say

I can use a normal Service call to Google.Translate.Say that works fine for this media player. Thanks for any help.

I also have this issue. I can´t make google tts to speak sensor values.

Maybe this is your problem