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

Quick fix on your end, comment out the settings you left empty, and reload customizations and scripts from Developer Tools > YAML

I will fix it on in the templates so that is not needed

Thanks, it works!

Hello,

sorry for bothering you, but I do not know where to look.
Here a picture of the spotcast config and the spotify one.

How to understand if there is an error? Where should I look further?

Update

Version 2022.11.5 - 24 November 2022

:star2: Improvements

  • Improved the template to get the entities to resume

:bug: Bug fixes

  • Better handling of empty settings

The problem is media_player.spotify_milena_dacheva doesn’t match with the account name you’ve set in spotcast.
You’ve named the account milena
The account name the script uses is milena_dacheva because the spotify account has that entity_id.

So if you rename the entity_id to media_player.spotify_milena it should work.
You can also adjust the spotcast config so the account is named milena_dacheva

Either way, the entity_id of the Spotify media_player needs to match with the name of the Spotcast account.

Ok,

I made what you told me, but it still does not work. Could you check what’s going wrong?

{ “trace”: { “last_step”: “sequence/20”, “run_id”: "1b9166f000bb5cb - Pastebin.com
{ “trace”: { “last_step”: “sequence/0/then/8/then/1/choose/3/sequence/2” - Pastebin.com

Hi, be sure the one you set on the spotcast config (primary_spotcast) is the same name in your spotify integration.

Here’s the screenshot of my setup in order to give you an idea.





Update

Version 2022.11.6 - 24 November 2022

:bug: Bug fixes

  • Small fix and improvement for players_to_resume

I don’t see any issues in the trace, do you see any issues in your log regarding spotcast maybe? Something regarding tokens maybe?
Open your Home Assistant instance and show your Home Assistant logs.

It seems to be ok, could you take a look? Probably I am missing something…

Yes, this part is fine.
I can also see all this information in the trace. And I can see that the spotcast service call didn’t return errors.
However, after that the script kept waiting until the speaker started playing again, and that didn’t happen…

Could you try to go to Developer Tools > Services Open your Home Assistant instance and show your service developer tools. and enter the following (in YAML mode)

service: spotcast.start
data:
  entity_id: media_player.ufficio_milena
  account: milena_dacheva
  force_playback: true

Does it start playing then? Because this is the exact service call the script performed.

If I enter the mentioned code, yes, it starts again to play.

Then I don’t have a clue.
The issue right now is that the scripts didn’t complete, and therefor are still in a waiting state, and the entity will still be in a group as already being resumed, so if you test now, it won’t be resumed anyway.

Could you restart, and test again? Prior to HA 2022.11 you could simply do a script reload to stop them, but that only reloads changed scripts now. You can also cancel all runs of the script, but it might be easier to just do a restart.

I will add a timeout on the wait so the scripts will finalize anyway if the resume fails

Please:)

Logger: homeassistant.components.script.google_home_resume
Source: helpers/script.py:409
Integration: Script
First occurred: 6:04:57 PM (4 occurrences)
Last logged: 6:28:05 PM

00 - Google Home Resume: Error executing script. Error rendering template for variables at pos 6: UndefinedError: 'None' has no attribute 'items'

Trace: dpaste/PdG8k (Python)

Update

Version 2022.11.7 - 24 November 2022

:star2: Improvements

  • Added a timeout on wait_templates after resume to prevent the script staying active

:bug: Bug fixes

  • Stupid copy/paste error in previous bugfix

@Manazer Thanks for updating so quickly and sending these reports! Sorry for the mistakes on my hand, I think I’ll go to bed early today :slight_smile:

1 Like

No problem :slight_smile:

Working again! Only some warning appears:

Logger: homeassistant.helpers.template
Source: helpers/template.py:135
First occurred: 9:00:44 PM (1 occurrences)
Last logged: 9:00:44 PM

Template variable warning: 'medadata' is undefined when rendering '{{ medadata if picture_url == 'no pic' else dict(metadata, **picture) }}'

I’ll look into that, thanks again

Update

Version 2022.11.8 - 24 November 2022

:bug: Bug fixes

  • Typo fix when applying metadata to service call to resume stream

@Manazer that one must have gone unnoticed for a long time. medadata should have been metadata

yes, my logging level is “info” only, therefore not noticed.
is this part of your code necessary if nobody cares?

It’s medadata (with typo) was only used in really specific cases, when a stream was resumed and the source didn’t provide a picture.

1 Like