I first started to create a script to send actions to a Google Home and resume the stream (TuneIn / Spotify) which was playing afterwards. It also restores the volume, and you can work with Google Home speakers groups.
In my home I have several Google Nest/Home speakers, and I had some scripts where a TTS would be sent which was triggered by a Google Home routine. However, I could only set it to a predefined Google Home speaker, and not to the specific speaker on which I gave the voice command.
This made me thinking, and I found a solution for this, using the ambient sounds which you can start in your routines.
So I made a new script, which can be used in cooperation with the other script, to send a TTS or other actions, like e.g. an image, or a cast of your Lovelace dashboard to specific Google Home after you ask a question to it.
Excellent stuff, something that’s bugged me forever. So, am I right in saying, these scripts, use the ‘trailing’ playing of ambient sounds for us uniquely identify the speaker in that state and therefore direct the TTS back to it?
Hi, just wanted to say this is a brilliant idea - specifically, passing the TTS to the right Google Home
Unfortunately I am have an issue with this. I’ve gone through the debug and the issue seems to be that I am not passing a tts_volume (I would like the TTS volume to be whatever the media_player. is set to).
This is the error I am getting, which is generated on this part of the code:
Stopped because an error was encountered at January 2, 2022, 15:08:20 (runtime: 0.04 seconds)
Error rendering data template: TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’
Kudos for this idea. I have wanted to do that quite some time.
Does this also work with your new script, or do I need to use the one stated in the first post?
Made several changes in how data is sent from this script to the Google Home Resume script. So if you update this script, make sure to also update the other one. However, as of this version, it is also possible to use this script without the Google Home Resume script
New feature
It is now possible to use target_conversion. This means you can give your voice command, and perform your actions on another target eg the speaker group the target belongs to.
By setting the use_resume variable to false you can send the actions without using the Google Home Resume script. This can be used if you for example want to start a radio stream which is not in TuneIn, and do not want to resume other streams in case that one is stopped.
The target determined by the ambient sound will only be used in case you omit the target in your service call. If you provide it, that target will be used. This can be useful if you also want to provide other actions, for example setting the state of an input_boolean.
In case you don’t have the need to use the Google Home Script at all, you can set use_resume: false in the variables of the Google Home Voice script, and it will just send the actions.
Improvements
Information is shared with the Google Home Resume script in a better way. This was also needed because now multiple targets or groups as target are possible, where in the old version there was always only one target.
Information on for the ytube_music_player integration is now also shared.
Changes in the way data is shared with the Google Home Resume script. So if you update this script, make sure to also update the other one. However, as of this version, it is also possible to use this script without the Google Home Resume script
Improvements
The ytube music player integration will now resume at the right position in the track
Support for extra variables in service calls added. This is a new feature of the Google Home Resume script. Version 2.0.0 or higher of the Google Home Resume script is required for this. For more information see here
Hello!
I’m really thankfull for your work, but I haven’t been able to modify all the settings of both script to make them work; seems that there are a lot of scripts inside, with radios and all, lots of diferrent entities that I don’t have, and I really don’t want that. All that I really wanted was to know the entity_id of the media_player that was used to call a script, is there any way to simplify this, without thinking in youtube / spotify or any other integration for that matter? I thisnk that would be very usefull, for a lot of people, on it’s own.
For instance, I have this list of media_players, and is possible to know the “last_changed”, but that doesn’t quite work as expected:
{% set colunas = ['media_player.coluna_da_sala', 'media_player.coluna_da_cozinha', 'media_player.coluna_da_cave'] %}
{{ expand(colunas) | sort(attribute='last_changed', reverse=true) | map(attribute='entity_id') | first }}
Is there something that I could do before just to get the correct media_player ?
Thanks in advance!
The script is intended to actually send an action to the right Google Home.
The Google Home Resume script is not required, you can use this script without the Google Home Resume script if you use: use_resume: false
I don’t know what you actually mean with your template example, because it doesn’t seem related to starting an action by voice on your Google Home, and knowing which one you asked it to in Home Assistant.
What your template does is determine which media_player was changed last, which of course could be because of the question asked, but also because someone changed the volume or whatever. So that might be the reason why it doesn’t work as expected.
I know you are right, and I’m thankfull for your approach. I will try to make both scripts work, but mainly understand the sequence to send the white noise and get the media_player from there. That’s mainly what I want.
I managed to replicate the white noise and possibly get the player, but as it goes last in the sequence in Google Home app it has to wait for it to be identified, as I understand. Don’t know any better aproach, so I will try to addapt your scrits to my entities. Thanks again.