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

Hi, I’m having some issues implementing this script and getting the error ‘Failed to call service script/google_home_resume_wip. Error rendering data template: UndefinedError: ‘iif’ is undefined’.

No doubt it is something I have or haven’t done but any ideas where I’m going wrong, please? Would love to get this set up, my family get quite annoyed with my announcements interrupting their music and have to start the music from the beginning.

Oh, sorry, should have waited to after today to publish it. The iif function is new in 2022.2 which will be released today.
I also forgot to remove the _wip part

Yeah, got the same issue with that :wink: All devices & no dutch language. But the overlay was nice though. I’m interested if you can manage to let something like the youtube stream continue after TTS. Will follow this one :wink: Thanks for your effort!

Update

3 February 2022

  • Added requirements (HA Version 2022.2) to first post, also added requirements for Spotify resume there.
  • Removed WIP (work in progress) references in script object_id and alias.

The script now fires up with no errors after the HA core update but I’m still facing some issues.

if I fire up:

service: script.google_home_resume
data:
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.dressing_room_speaker
        message: test

It plays the TTS announcement, makes a few google sounds but the music does not resume, any idea where I’m going wrong please?

I’m currently debugging a bit myself, but could you try if it works like this:

service: script.google_home_resume
data:
  target:
    entity_id: media_player.dressing_room_speaker
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.dressing_room_speaker
        message: test
1 Like

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: