A somewhat workaround solution might be to send a text command from HA to Google Assistant speaker: āplay the last song on youtube musicā. Then it should at least restart the last played song. Could even try something like ācontinue playing the last song from where it was last stoppedā. Google Assistant is pretty smart and something like this might work, havenāt tested tho. I know there were some addons and ways to send text commands this way, donāt remember exactly. Something to do with webhooks and IFTTT. Maybe you get some good ideas through this angle
Could also be done with something like Assistant Relay, but that will be difficult because people will use different languages for their Google Home. So you canāt just use a command in English.
You will also run in issues when there are different people in the same house all using their own account, how will you know which account was used to play it.
For YouTube Music the best solution at this moment is ytube_music_player. But then you canāt start it by voice command, youāll have to use the media browser of HA.
Itās unfortunate that the same information as is available though the Spotify integration is not visible.
I use your script, it works well! Great work, thak you! I have two small problems with it. I only use to resume to tunein, and the resume is a bit slow(start to conect to stream quickly, but the connecting is slow). Itās a lot slower, like Iām just starting tunein. Why? The other problem is that after resume, on my hub, the screen is blank, not showing what it is playing(not showing anything). Am i doing something wrong, or is it normal?
It doesnāt show it like before, because it uses the default media player to resume the stream, and not the TuneIn cast functionality like Google does.
What do you exactly mean with slow? It tries to resume as soon as your player is idle or off, it could be that there is a delay in getting this state.
The resume is fast, but the connection to the stream is slow. But I think itās because of the different application behavior (default media player vs tunein app)
Made several changes in how data is sent from the Google Home Voice script to this one. So if you update this script, make sure to also update the other one
Improvements
When speaker groups are changed, the volume of the individual group members will now be restored, instead of the volume of the group.
Several changes in templates, and how data of cast entities is gathered and stored
Iām trying to implement your script to my install but it wonāt resume the music after tts. Neither Tunein nor Spotify is working. No errors in logs.
Here is a trace from my last try.
The code I used to try it is the one pointed out by you above:
I donāt think youāre doing anything wrong. From the trace I can see that it determined that there was nothing to resume. But i can also see that the targeted media player was indeed playing.
So there might be something wrong in the template.
Found the reason, however, youāre speaker groups are acting different then mine.
If my speaker group is playing, all members are also shown as playing in Home Assistant.
According to the data in the trace, your speaker group was indeed playing, but the members were idle.
This caused that the speaker group was not recognized as a player to resume.
However, in v1.2.2 this is now changed.
You are indeed right! Interestingly both of the members are stereo pairs, actually. If I select another group containing individual speakers too:
a) stereo paired speakers still show as idle
b) individual speakers show as playing
So seems like a pattern here. Anyone here can confirm this?
Anyway: thanks for implementing this edge use case!
Fixed unusual case (at least as far as I know) where a speaker group is playing, but the members are not shown as such. In case the speaker group was the target of the script, it would have caused the template to not recognize it as a player to resume
Version 1.2.3 - 19 February 2022
Bug fixes
Addition to v.1.2.2 to make sure the speaker group is also resumed when the target is not the group, but a member of the group
Great! Hope others will chime in and give something back!
Another feature request if I may? Ultimately Iād like to use your script to āsaveā currently playing media and resume same streams/Spotify later on. For example I could resume music at the exact same spot when leaving home and coming back later.
Also I could turn off the Google homes faster when leaving home. Currently I have a 10 minutes delay before turning music off in case I just went to bring out the trash. if Iām able to save current state I could turn everything off instantly and resume later in case I come back within minutes.
Is this possible with how the script works at the moment?
If this is not inside what you are planning for the script I can fully understand, just would find it useful
Totally unrelated: regarding the last section of your intro post: wouldnāt this make perfectly sense as an integration? I have no idea of how different the programming would work, I just see that itās more or less a integration from users perspective. It has a service call, it could generate entities (last playing, last playing entities) and so on.
This could be updated via hacs so the easier updating you wanted could be achieved. As I said: no idea of this would need complete rewrite. Just came to my mind reading what you said about blueprints. If itās a lot of work, itās probably better to stay with the current form as its working great!
The resume based on home status, or other events is actually a very good idea. Iāll look into that.
For the integration part, those are written in python, and thatās something I donāt have any experience with. Maybe somewhere in the future, but not in short or middle long term.
iām using an automation with google tts and a camera feed when someone has pushed the doorbel. it first says someone is at the door and then pushes the camera feed onto the hubs. Because these are 2 actions with a delay in between, would this script still work to resume what was playing before? since the last action would be a camera stream and not google tts/spotify,etcā¦
Yes, you can sure make that work, however delays are not service calls, so you can not use them directly in the script. I think this will work.
Note that I have split it up into one automation and two scripts. One script could also work, but this will work better with the update Iām about to publish (hopefully later today).
It could be that the nest hubs are resumed before the camera feed starts, in that case you might need to increase the delay at the end of the first script.
### YOUR NEW "DE BEL GAAT" SCRIPT"
de_bel_gaat:
alias: Script voor als de bel gaat
sequence:
- service: media_player.volume_set
target:
entity_id:
- media_player.nest_hub
- media_player.badkamer
- media_player.google_opslagkamer
- media_player.grote_slaapkamer_hub
data:
volume_level: 0.5
- service: tts.google_translate_say
data:
entity_id: media_player.nest_hub
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.grote_slaapkamer_hub
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.badkamer
message: DE BEL GAAT
cache: true
- service: tts.google_translate_say
data:
entity_id: media_player.google_opslagkamer
message: DE BEL GAAT
cache: true
- service: script.camera_als_de_bel_gaat
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
### SEPARATE SCRIPT FOR THE CAMERA FEEDS, TO NOT DELAY THE OTHERS
camera_als_bel_gaat:
alias: Script voor de camera feed als de bel gaat
sequence:
- wait_template: >
{{
states('media_player.nest_hub') in [ 'idle', 'off']
and states('media_player.grote_slaapkamer_hub') in [ 'idle', 'off']
}}
- data:
media_player: media_player.nest_hub
target:
entity_id: camera.dome_camera
service: camera.play_stream
- data:
media_player: media_player.grote_slaapkamer_hub
target:
entity_id: camera.dome_camera
service: camera.play_stream
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- data: {}
service: media_player.turn_off
target:
entity_id:
- media_player.nest_hub
- media_player.grote_slaapkamer_hub