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

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.

Yeah I copied the new script on github after your last post. I start the youtube cast on the Nest Hub, and called the TTS with your script. It stops, played the TTS and returned to Youtube. But then it gave me an error that it couldn’t find the media_position. The youtube video just started from the start.

Okay, I must admit I didn’t properly test it after I changed some things. I will do that within the next hour.

1 Like

Could you test it again?

1 Like

Just tested it on the Nest Hub, works like a charm now! Thanks a lot!

How do I configure players with a screen? I understand I need to add the file directory in ‘fixed_picture’ but is it a case of downloading the image to the stated directory and that image will show when resumed?

If so, is this just for radio or for Spotify artists too?

Hi,

Those fixed_pictures are not related to the players with a screen.
I’ve put that in because many radio stations on TuneIn use the album art for the song which is playing as the entity picture.
That will not work after resuming, as it is not playing via TuneIn anymore. So, without the fixed_picture you will be stuck with the picture of the song when the stream was interrupted.
I’ve added fixed pictures for the TuneIn streams I use frequently to avoid that.

For Spotify it’s not an issue, as Spotify will be still playing and updating the pictures.

The players_screen variable is to make sure the backdrop is shown after it has been interrupted and nothing was playing.