Script to resume Google Cast devices after they have been interrupted by any action

Thank you soo much!! That seems to work for Spotify music now, although it doesn’t seem to work for radio, is it possible to resume radio after the announcements?

How do you play radio? It should work for TuneIn streams.
I will look into your previous question though, it should have worked without specifying the target.

It uses ‘Global Player Live’ as the default but if I ask google to play via Tunein the script works fine. Tbh If it means I only need to mention Tunein I’m not too fussed.

Do you start that by voice command, or by use of an app? I could give it a try if I know how the attributes look like while playing.
If you start it by voice command, could you tell me which command?

Yes, the command is ‘Play LBC London’ which uses Global Player Live as default but does not resume after TTS announcement.

If I use the command ‘Play LBC London on TuneIn’ it plays via TuneIn with no issues resuming.

I don’t know if this helps but if I look at my media player in google home it looks like this:

Could you check developer tools > states for the speaker while it is playing via Global Player Live?
I tried the voice command, but it didn’t work for me.

But if TuneIn works fine for you, that is also fine.
You coud set up a routine with the voice command LBC London and link that to the custom command play LBC London on TuneIn. Then you only have to say LBC London

volume_level: 0.550000011920929
is_volume_muted: false
media_content_id: ''
media_position: 1.575375
media_position_updated_at: '2022-02-03T14:06:03.899501+00:00'
media_title: Shelagh Fogarty
app_id: CD7B9F59
app_name: Global Player Live
entity_picture_local: >-
  /api/media_player_proxy/media_player.dressing_room_speaker?token=f5e3669bcb3f35353bbd909b2ef656bbb075001a1b02bafa5c6b9be4f9fde709&cache=0c2c942e6566bd64
entity_picture: https://herald.musicradio.com/media/0240518b-4ae5-4c70-ac0e-6837af210509.png
friendly_name: Dressing Room speaker
supported_features: 152461

I was thinking the same with the routine, thanks.

Ah, without a media_content_id there isn’t much I can do.
I gave it a try with the cast functionality and the app_name and app_id you gave above, but that did not work.

1 Like

nevermind, it’s easily solved with routines anyway. Thanks for all your efforts.

Is it possible to add multiple Spotify accounts to this script?

@jvalst

Update

4 February 2022

  • (Limited) support for YouTube and YouTube music. The active video/song will be resumed at the position (minus 2 seconds) when it was interrupted. However, it will only resume that video/song. Not the full playlist/album/whatever.
  • Fix in template where speaker groups were not seen as cast entities.

Yes, but you have to add the Spotify integration for all users, and you have to add them all to the spotcast configuration.

Spotify (account Pepijn not shown):
image

Spotcast (pepijn is primary):


spotcast:
  sp_dc: !secret sp_dc
  sp_key: !secret sp_key
  country: NL
  accounts:
    martijn:
      sp_dc: !secret sp_dc_martijn
      sp_key: !secret sp_key_martijn
    marleen:
      sp_dc: !secret sp_dc_marleen
      sp_key: !secret sp_key_marleen
    floris:
      sp_dc: !secret sp_dc_floris
      sp_key: !secret sp_key_floris

and the media_players connected to the Spotify integration are named (matching the spotcast configuration and the primary_spotcast variable in the script):

media_player.spotify_floris
media_player.spotify_martijn
media_player.spotify_marleen
media_player.spotify_pepijn
1 Like

Once again, Thank you!! that seems to be working perfectly.

1 Like

Awesome! Gonna try this tonight :wink:

Oh, one thing. It is not possible to immediately send it to the right position. So it will first start at the beginning of the video, and after a short delay move to the right position.

2 Likes

This is awesome! Nice work. I use Nodered for my automations so need to work out how I can implement it there :worried:

Create the automation in automations section on HA and link to it from node red.

1 Like

Update

5 February 2022

  • Improved and fixed template for resuming YouTube at the right media position.

Today I had some time to test the new script out. It works like a charm depending the resume option for Youtube. The media_position is not working yet. I get the following error:

Logger: homeassistant.components.script.google_home_resume
Source: helpers/script.py:1375
Integration: Script (documentation, issues)
First occurred: 11:44:39 (16 occurrences)
Last logged: 11:50:16

00 🔊 Google Home Resume: Anything to resume?: choice 1: Resume players: Resume needed?: choice 1: Resume playing: YouTube?: Error executing script. Error for call_service at pos 4: Error rendering data template: UndefinedError: 'media_position' is undefined
00 🔊 Google Home Resume: Anything to resume?: choice 1: Resume players: Resume needed?: choice 1: Error executing script. Error for choose at pos 3: Error rendering data template: UndefinedError: 'media_position' is undefined
00 🔊 Google Home Resume: Anything to resume?: choice 1: Resume players: Error executing script. Error for choose at pos 2: Error rendering data template: UndefinedError: 'media_position' is undefined
00 🔊 Google Home Resume: Anything to resume?: choice 1: Error executing script. Error for repeat at pos 1: Error rendering data template: UndefinedError: 'media_position' is undefined
00 🔊 Google Home Resume: Error executing script. Error for choose at pos 9: Error rendering data template: UndefinedError: 'media_position' is undefined

Are you using today’s update? There was a small issue with the template.