My guess would be it has something to do with the delays. After sending the TTS command, it takes some time to process (generate the audio file, send the command to the speaker, download & play the audio file). If you send a new command in the meantime, like setting the volume, it might interfere.
So I would add some bigger delays after your tts.google_say commands.
You should be posting the error youâre getting in the log to help people diagnose your issue. In this case the problem is easy to spot. Youâre missing some quotes. Volume level parameter also requires a float value.
Thanks, @jazzyisj & @Emphyrio. Indeed it was a combination of issues - the quotes were missing, I had to do a cast to float, and a major issue was that the variable was never defined. Making use fo the log certainly helps here ⌠beginnerâs fault
Is there a way to define a variable within a script locally so that it only exists there, that there are no conflicts with potentially equally named variables in other scripts, and to make sure that it is always defined for that script independent of any âglobalâ setups? I am not referring to variables that should be passed to that script, but indeed only ones to be used within the script, like the current volume one here.
Thanks, Jason. I am still stuggling (as a newbie) with the basics of setting a specific value to a variable. As some code snippets, I would have assumed that it works like the following, but obviously some major flaws in there as it doesnât even recognize the service:
Would anybody be able to point me to the (probably obvious) mistakes here and how to handle such variables? Unfortunately the âScriptsâ link doesnât explain that and also some additional searching hasnât led to anything. Thanks again!
Looks like you are mixing up automation/script variables and one of the custom variable integrations. Where did you come up with the set_variable service you tried to use? You also didnât name your script!
You really need to read the link I sent before and this link carefully. If youâre trying to write scripts and donât understand the basic format youâre going to be in for a very frustrating time!
Once youâve read those if you still have questions, fire awayâŚ
Hereâs a quick example to demonstrate how to change a variable value within a script. Put this in your config, reload your scripts, execute this script, then look at your log to see the result.
Thanks again, Jason - now fully clear. Really appreciate your help.
I obviously read the documentation intensively as well as searched the forum but nowhere found how to set these number variables in scripts, therefore fell back to experimenting with a format similar to input_numbers or the custom variables component. Now it is clearer (and obviously much simpler). I understood the example in the âscript syntaxâ documentation originally as how to define the variables and not how to set them within the sequence of the script. I will suggest a slight update to it on GitHub to make it clearer.
Thanks for the great content here for the google home broadcast.
Iâ'm stuck on one thing though - where do I store the local MP3 files and how do I reference them? I have tried putting them in the config share, in the local media share, in the www folder, but I cannot get the files to play from this script.
I guess with that comes the question of how to reference local files on the HA installation from a script? If the following line is used:
Does that mean files go in the www folder in the config share and that /local/sounds are folders that I create and upload files too?
If I donât use the input_text.home_assistant_url_internal, how to I reference a file path?
I have HA installed in a VM on a Hyper-V VM so itâs a full installation.
The Google Cast only accepts an external url. So you need to use that in your call. The audio files go in the config\www folder. In the external url, the www folder is referred to as âlocalâ. They are one and the same folder.
This applies in my situation, YMMV. I would suggest simply replacing your internal url with external one.
Thanks for that. I think I have almost figured it out. One thing I donât understand though, the input_text bit. Where does the input_text get defined? Is it a helper, is it from the General configuration of HA, or something else I need to create myself?
Also, when you say external URL, does that mean something that is publicly addressable (so a website on the internet), or just addressable by the Google speaker internally to my network?
About the input_text: this is my way to keep my base_url at a central location. It is not required in any way. My baseurl is: https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.ui.nabu.casa. You can just use one string, e.g.: media_content_id: "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.ui.nabu.casa/local/audio/1sec.mp3"
With âexternal urlâ I mean an URL that is not in your local network. An URL like this doesnât seem to work for casting: 192.168.0.10/local/audio/1sec.mp3. Because that is an IP-address on your local network. For casting to work, the URL needs to be reachable from the internet, not just on your local network.
service: tts.google_translate_say
data:
entity_id: media_player.all
message: "there is someone at the door"
volume: 0.7
Now it errors - but if I remove the âvolume: 0.7â it works.
There are scripts in this thread which would help if I was addressing a single media_player, recording/restoring the volume, but it is going to be tedious doing that for every media_player in the house.
Added to which media_players which are switched off donât have a âvolume_levelâ attribute.
If I go simple and just want to output to all media_players - I now have no idea what volume it will come out at.
I need to create a script for TTS Cloud announcements, through which to set a certain volume level for the TTS announcement, but at the same time to pause what was playing (if was something playing at that moment) on that media player and after the announcement has been played, to resume what was playing before on that media player, at the same volume level as before the announcement (again if there was something playing at moment of the announcement) and if nothing was playing at the announcement time to restore the previous volume level of that media player.