I have been thru a lot of very old responses but none are up to date.
I am just trying to say a random phraze via a script.
I am a novice at YAML so I only do scripts and automations. I use the visual editor or jump into the yaml edit ( not Studio Code Server as it never looks the same on my screen with samples people give)
I know the scippting has changed a lot but I need a 2025 solution as I think this would be really cool.
I compiled some code into a script. It runs but does nothing.
sequence:
- alias: Say it again Sam
target:
entity_id: script.google_home_resume
data:
variables:
action:
- alias: “Send TTS Message”
service: tts.google_translate_say
target:
entity_id: media_player.spanish_hub
data:
message: >
{{ [ "Hey there PERSON Welcome Home, during your stay, don't be
a asshole!", "Sometimes you feel like a nut, Sometimes you
don't, Sometimes you feel like PERSON, l o l Welcome Back",
"Hello PERSON, damn, I wonder, how many people, we can fit in
this, tiny house?"
] | random }}
extra:
volume: 0.4
action: script.turn_on
alias: aa random speech i
description: ""
I don’t even get some of the services, action, targets in the above code.
Can anyone help get this small script working, then I can have a lot of fun replicating it.
Developer Tools - Actions.
Select tts, the rest is done with the mouse.
Insert the template expression at the end, after that you will be switched to yaml and you will get the required code. Just paste it into a new script.
You may actually find it easier to dip your toe into templates and define your random expression separately. For example, this generates a random phrase to insert at the beginning of a TTS statement. It changes once a minute:
You are getting the error because template sensors do not have a platform - if you have both sensors.yaml and templates.yaml in your configuration, the code I posted should go in templates.yaml.
I added this into a script. But I get the error tts.google_en_com cannot be found?
And it does nothing but HA will configure ok in Developer tools.
Can you suggest anything in either script I need to change to get this to work?
sequence:
- action: tts.google_en_com
data:
cache: false
entity_id: media_player.spanish_hub
message: "{{ states('sensor.starter_phrase') }} This is a test"
alias: aa Play it again Sam
description: ""
Well i have gotten closer with this script which looks similar to yours. The only problem is the sensor.starter-prrase is announced as unknown by google.
Betweem this script and the template I documented earlier, can you spot a problem?
sequence:
- action: tts.speak
target:
entity_id: tts.google_en_com
data:
cache: false
media_player_entity_id: media_player.spanish_hub
message: "{{ states('sensor.starter_phrase') }} This is a test"
alias: aa Google speaks again
description: ""