Looking for some help here. Any idea if this will work with YouTube Music? It’s clear the script is working (based on the state of the device), but it doesn’t resume playing music.
Here’s the state before and after the script:
Before:
Looks like the source is restored correctly but the most basic which is the state is not.
We verify that if you manually start playing on the device and check if it plays the correct, media. Please do the test and tell me the result.
The script has been under development and is shared here in different versions.
From which post nr did you copy it?
I am not sure which of these exactly but probably the app_id / name
But don’t worry this can be done. We can backup and restore all these attributes.
To be able to do that, I have installed and use a python script, and I do it successfully in my version of the script. But i just cant remember which script it is and where to find it.
I’ll search for it and get back to you
In the meanwhile you can work identifying which attribute we still need to adjust.
You can start changing the app_Id
you can do that from the developer tool, in the state attributes window, and then hit “Set state”
Then try to start playing from the lovelace or any other place you can control the media_player and see if it works.
if not, then try another attribute and so on.
you have to save the script into a file example set_state.py and save that file in the python_scripts folder under the configuration directory. if you don’t have that folder already then create it.
and in the configuration.yaml file you have to add the line:
python_script:
then restart HA.
Let me know when you get that far, then we can proceed from there .
Eventually I got the script to work, however I changed it quite a lot. As I am using Sonos for my TTS, fortunately there is an option to snapshot most settings in one go and restore the settings after the TTS message. By using sonos.snapshot it remembers also how far along in a song you were and at resume does not start the song from the beginning. I got the wait_template working, although I still use a small delay before the resume.
@ghassan ,
My main challenge was that I could not get the original script to remember how far along in a song the player was. After the TTS it would start the right track, but it would start from the beginning. The snapshot solution makes the script very compact, but it also makes it sonos specific and not well suited for a generic solution.Come to think of it, I didn’t test yet if volume settings are also ‘snapshotted’. In that case you could even reduce it further. KR, Tankdoz
I’m looking for long time for an option to use TTS with my HomePod Mini. As HomePod Mini is now available as an Mediaplayer i can use TTS. I tried to use the provided Script-Code:
Sorry I’m chiming in late on this thread but I just tried to set this up with the Sonos Ones running Alexa. The announcement works fine but nothing resumes playing after the announcement. Any insight?
Were you able to get this script to work for youtube music. If so can i see your final script. Side not @ghassan does this script support resuming music on previously playing speakers or just resuming music on the speakers used for tts. For example if im listening to music on media_player.xyz, media_player.abc, media_player.lol, and media_player.trx and i get and anoucement on xyz & and abc will all players resume music afterwards?
my code work now in the 2022.9
resume playing in my 3 media player , each one the independent player previous to the tts.
in my case , the tts is play y all the media players. you can add a variable indicate the media player you want to use to the tts, or create a script to each media player.
my code include a day/night time select ,. to change the volume off TTS accord to the hour.
regards.
@ghassan Thank you a lot for this work. Works very well for me and solved an issue!
I have one question:
I’m using the script to control a google nest hub with a display and I’m using 2 modified versions of your script to 1) resume after tts announcement and 2) resume after streaming videos from IP cameras (e.g. when someone rings the doorbell it streams the campera for 30 seconds and than resumes). This works fine in case one is playing music etc. However, it doesn’t stop the media_player (state: off) when it was off prior to the tts announcement or stream. Since I’m using the hub with display it needs to stop media_player at the end if it was stopped/off prior because otherwise it will not return to the photo frame mode of the nest hub.
I tried to solve this by modifying the end of the script but this does not work:
In case of an tts announcement it ends with the media_player state “idle” and in case of the stream (code shown above) it keeps showing the stream without stopping it (even if the same script returns to the playing source succesfully if it was playing something before).
Any suggestion how to turn off the media player in the end in case it was turned off before starting the script?
@ArielBaravalle
Thank you for helping!
Tried this but it regrettably didn’t change the outcome: Stream keeps streaming and after TTS status is “idle” instead “off”…