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

Hi @TheFes,

Thank you for taking a look. There certainly is an error I’m getting with the Google Home Resume - Perform Resume (CodePile | Easily Share Piles of Code) script. I don’t see an error with the Google Home Resume (CodePile | Easily Share Piles of Code) script.

Some background:
My Spotify account is the only one used and as your Setup states there should be no additional settings needed for a single account. Even still, I did put primary_spotcast: “spotify_entity_id” as you described in your setup. After each run it appears there is an error in my spotcast setup (CodePile | Easily Share Piles of Code) running 3.6.29 though I’ve uninstalled and reinstalled twice removing and readding sp_dc and sp_key each time to make sure I didn’t have inaccurate cookies.

What other information would be helpful for you?

You’ve been super helpful, regardless of whether I can get this fixed. Do you get much sleep?

I have indeed mentioned in the docs that you don’t have to specify the Spocast account if you have only one account, however, there was a bug which was fixed in 2.2.0. According to the trace you are running 2.1.0.

So please update to the last version (2.4.3) which will hopefully fix your problem.

@TheFes still no luck. It appears Spotcast is still having issues so maybe once those are resolved I can get this Script to work. Thank you for all your support!

Could you send a new trace of both scripts after update to 2.4.3.

Just tested Spotify resume, and it works fine for me

Update

Version 2.4.4 - 16 May 2022

:star2: Improvements

  • Script now also correctly recognizes Google Cast devices when using a Home Assistant speaker group as target. It will expand the group and check the group members for cast entities.

Did you get it working already?

Hello @TheFes,

Sorry life is getting in the way. No, still not working but I’m not seeing errors in the trace like I did before, so I’m fairly confident that it’s my setup with Spotcast. The trace jsons are attached below. I really appreciate the care that you take when replying. :slight_smile:

trace script.google_home_resume_perfomr_resume CodePile | Easily Share Piles of Code
trace script.google_home_resume CodePile | Easily Share Piles of Code

The error seems quite clear: "error": "Expired sp_dc, sp_key",
Check for your current keys following the steps in the Spotcast installation description, and update your spotcast integration configuration.

1 Like

Update

Version 2.4.5 - 20 May 2022

:star2: Improvements

  • Spotify songs will be resumed at the right position in the track
2 Likes

Thank you @TheFes. The sp_dc, and sp_key are correct. Spotcast is just not working for me. On reboot I get several errors in the logs regarding Spotcast. I integrated it properly as far as I can tell, just not working for me. I believe this is an issue with Spotcast and not with your script.

Again, you’ve been so helpful. Thank you for all your support.

For anyone else who is having this issue, I found if Spotify is configured using Nabu Casa Cloud, Spotcast will not function properly. Now no errors in my logs regarding Spotcast or Spotify. However, I still have the error stating "error": "Expired sp_dc, sp_key"

@TheFes I feel as though I’m making progress. Steps taken:

  1. I reset the sp_dc and sp_key through chrome://settings/cookies/detail?site=spotify.com and clicking on the ‘X’ next to the drop down.
  2. Copy and pasted the new cookies into the file editor
  3. Commented them out
  4. Removed Spotcast from HA
  5. Reset HA
  6. Redownload Spotcast
  7. Uncommented sp_dc, sp_key
  8. Reset HA

I’m no longer seeing "error" : "Expired sp_dc, sp_key" but now seeing "error": "'NoneType' object is not subscriptable"

script.google_home_resume_perform_resume: CodePile | Easily Share Piles of Code
script.google_home_resume: CodePile | Easily Share Piles of Code

I’m continuing to dig into Spotcast, when I run the script in the Log it shows Spotcast error Error doing job: Task exception was never retrieved. I’ve reached out the Spotcast repository owner for support. Would love to get this working for multiple automations.

Indeed the seems to be related to Spotcast.
I see the same error mentioned in the latest posts on the Spotcast topic here on the community forum.

Hi!

It works like a charm. Thank you for the efforts!

I only have one thnig that is annoying me, but it could be my fault. I have three speakers, and when I send to message to one of them, it plays one chime and then the message. The problema is that now I have the three speakers in one group. When I send a message to the group, it plays at the same time in every speakersm so that’s working fine. The problema is the chimes. They play not at the same time, but one after another. And the big problem is that, I don’t know why, each speaker plays the chime more than one time. So I have three speakers in a group and the play five or six chimes one after the other before the message.

Could it be something that I did wrong?

Thank you!

No Idea what causes this.
But do they all chime six times, or do they all chime twice, and because it is not at the same time, you hear 6 chimes?

Got this working for tune in,
However I mostly listen to BBC radio, this script doesn’t seem to work for that.

On developer the speakers show as:

volume_level: 0.5
is_volume_muted: false
media_content_id: bbc_radio_two
media_content_type: music
media_duration: -1
media_position: 25851.715167999268
media_position_updated_at: '2022-05-28T08:08:09.697799+00:00'
media_title: BBC Radio 2
app_id: D350F6A9
app_name: BBC Sounds
entity_picture_local: >-
  /api/media_player_proxy/media_player.downstairs?token=776433f308005842a7a2adcd28d5e1fe991fb8a815aefa9454044216801e18c3&cache=4a1364155d3fc164
entity_picture: https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_two/colour_450.png
friendly_name: Downstairs
supported_features: 152461

All it NEEDS to resume it is app_name and media_content_id. For context, this works fine

service: media_player.play_media
target:
  entity_id: media_player.lounge_speaker
data:
  media_content_type: cast
  media_content_id: ' { "app_name": "bbcsounds", "media_id": "bbc_radio_two"}'
metadata: {}

From my understanding of how your magic it needs a new variable much like “youtube” and then a specific resume service call.

Ok so I seem to have got to a stage where it works for at least live BBC radio broadcasts. I’ve added two sections in the helper script,

bbcsounds: |
    {{player.app_name == 'BBC Sounds'}}type

alias: BBC?
conditions: '{{ bbcsounds }}'
sequence:
  - alias: Resume bbc
    service: media_player.play_media
    target:
      entity_id: '{{ player.entity_id }}'
    data:
      media_content_id: '{ "app_name": "bbcsounds", "media_id": "{{ player.media_content_id }}" }'
      media_content_type: cast

I’m frankly afraid to break it now so haven’t sorted the title or images. But functional for me

They chime two times each.

One of them has a screen, and I see that after the first chime it shows the “Welcome to home assistant” blue screen, then the normal idle screen again, and after that it comes the second chime and starts paying the message (showing the reproductor). It’s like it connects with home assistant, the disconnects, and then connect again.

When I use the speaker with the screen alone, not within a group, it chimes, show the “Welcome to home assistant” screen and inmediately after that start de message with the reproductor.It doesn’t show the idle screen between home assistant and the reproductor (nor chimes).

Upgrade to 2.4.5:

Source: helpers/script.py:1718
Integration: Script ([documentation](https://rc.home-assistant.io/integrations/script), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+script%22))
First occurred: 8:28:58 PM (1 occurrences)
Last logged: 8:28:58 PM

00 🔊 Google Home Resume: Error executing script. Invalid data for call_service at pos 11: invalid slug resume_script_active_ghresume_01G45YVEV85K8ZS1HSNEGV7M8F (try resume_script_active_ghresume_01g45yvev85k8zs1hsnegv7m8f) for dictionary value @ data['object_id']

Trace:
https://www.codepile.net/pile/Pl88XOlv

Are you on the HA 2022.6 beta already? It seems they have changed something which now allows uppercase characters in context.id.
I use this for the unique identifier for the group, and uppercase characters are not allowed there.
I was already working on this, but I’m also including some other changes.

Yes, you could do it like that, but that would mean you’ll have to add another option for each channel.
Easiest would be if you’d listen to BBC Radio 2 using TuneIn :slight_smile:

Just ask the Google Home: “Hey Google, listen to BBC Radio 2 on Tunin” and it will work with the original version of the script.