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

Yes no probs. It seems it is only happening when playing Spotify, just tested on Tunein and it worked fine.

Ok, so I did a bit of testing and I have realised the issue only happens if the music was sent from the Spotify app (iOS). If you ask google home to play the Spotify music the script works fine, it is only if it has been casted from my phone.

Should the script work if it has been sent from a phone or does it only work if asking the google device?

That should not make any difference. The trace can probably show me where itā€™s going wrong.

ok cool, here is the trace

Hi, I need the trace of my script (script.google_home_resume). Not for the script you now sent the trace of.

Sorry that should be here

Was this an example from where you got this error? The timestamp doesnā€™t seem to match with the time mentioned in your log item. It seems to have completed successful in this trace.
What I do notice is this "primary_spotcast": "Manazer". What you entered here can not be correct, sas it should match with the Spotify media player entity id (the part after media_player.spotify_)
That can not contain a capital character. So probably this should be manazar.

And you can completely remove the lines with players_screen and fixed_picture.

First things I noticed:

  • "primary_spotcast": "jacobsach1987,Home" this can not be correct, there can be only one primary spotcast account, not two.
  • You can remove the fixed_picture part if you donā€™t use I. I do assume you donā€™t listen to these two Dutch radio stations, and have the picture for them on the same locations as I have.
  • Is the entity_id of your Google Home speaker group really "media_player.huis_groep"?

I think the wrong input for primary_spotcast also caused your error. It now tried to start spotcast using the account jacobsach1987, but I assume that is your primary spotcast account, and you have no named account set up for this Spotify media player entity.

So I think your problem will be fixed if you change primary_spotcast: jacobsach1987,Home to primary_spotcast: jacobsach1987

Thank you. No that isnā€™t my speaker group name, as far as Iā€™m aware I didnā€™t have a Google Home speaker group, is it possible to have no group? if so, do I still list the individual speakers?

If you did not define a speaker group, and only have use individual speakers, you can completely remove that part.

Still not working.
Changed spotify do manazer (spotify resuming worked event with cap M).
If those 2 lines deleted completely, another warnings will emerge:

Template variable warning: 'players_screen' is undefined when rendering '{{ [] if not players_screen else target_not_playing | select('in', players_screen) | list }}'
Template variable warning: 'fixed_picture' is undefined when rendering '{%- if fixed_picture %} {%- if player.media_artist in fixed_picture %} {%- set p = fixed_picture[player.media_artist] %} {%- elif player.media_title in fixed_picture %} {%- set p = fixed_picture[player.media_title] %} {%- else %} {% set p = player.entity_picture %} {%- endif %} {%- else %} {% set p = player.entity_picture %} {%- endif %} {%- set t = iif(player.app_name.startswith('TuneIn'), player.media_artist, player.media_title) %} {{ iif(p == 'no pic', dict(title = t), dict(title = t, thumb = p)) }}'

Hmm, I will look into that. You can put fixes_picture and players_screen back for now then.

But Spotify can resume with an incorrect input for theprimary_spotcast in case there is only one Spotify account active at the time. But it will cause issues when there are multiple accounts playing at the same time.

But anyway, to help you with the other issue, I will need a trace from an script run when the warning was logged.

Warning still persistent:
script trace

Iā€™ve looked into the 2 warnings you got when you removed the variables completely. I can reproduce them, but the template still gives the correct result. It is a warning not an error.
I have changed the templates to avoid those warnings in my local version of the script. I will upload it tomorrow.

The other waning is part of a larger template, and less easy to spot. I will have a look at that tomorrow as well.
Time for bed now :slight_smile:

haha yeah I did miss that part. Added the spotcast configuration to home assistant now, gonna check if it works when Iā€™m back home.

Thanks for the script, this was something that needed to be added to my Home assistant setup :+1:

Hi, Iā€™ve updated some templates, could you check again?

THANK YOU: There are no new issues! :ok_hand:

Script working (Spotify & TuneIn resuming after Microsoft TTS interruption) - even without fixed_picture and players_screen definitions (if you donā€™t use them); BUT speaker_groups must be defined at least as null.

I think thatā€™s fixed as well now.

Update

7 February 2022

  • Due to limitations of the cast implementation, the previous way of resuming YouTube Music only worked on players with a screen. To avoid errors, Youtube will only be resumed on the entities listed in players_screen. I did implement support for YouTube music via the ytube_music_player custom integration, however that will only work if YouTube music is started using that integration.
  • Made some changes to several templates to avoid warnings in the log.

Confirmed! All warnings disappeared.
:clap::+1:

1 Like