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

I made the update at home, I started the script…again nothing, so I executed the code you gave me in the developer mode: Imgur: The magic of the Internet
It popups an error from the bottom which is unknown.

Is there a way to add in your code like a tracing variable or like a try & catch, so we can take this error and see what is it? Some sort of debugs…

Any error while running the script, will be logged in the Home Assistant log
Open your Home Assistant instance and show your Home Assistant logs.

But as you can clearly see, the error is not caused by the sript, it is caused by spotcast. I can’t help you with that. You can create an issue on the Spotcast GitHub repository.

Hi TheFes,
everything working (resuming) just perfectly
:+1: :+1: :+1:
Big THANK YOU for merging everything into one package
:pray: :pray: :pray:
v2022.12.1

2 Likes

Great, thanks for letting me know!

I saw you sent a message and was expecting a lot of log warnings to fix, but this is much better :smiley:

Well… there is something that needs to be checked…
No resuming Spotify…

2022-12-03 17:00:45.188 ERROR (SyncWorker_4) [custom_components.spotcast.spotcast_controller] No device with id "6a498c3ad44ebe4eec27648c02813098" known by Spotify
2022-12-03 17:00:45.198 ERROR (SyncWorker_4) [custom_components.spotcast.spotcast_controller] Known devices: [{'id': '59a3d3a1bce5662ba535971fb10fa84db39cbd83', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'S21 používateľa Martin', 'type': 'Smartphone', 'volume_percent': 100}]
2022-12-03 17:00:45.201 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: If at step 2: Parallel action at step 1: parallel 1: Resume needed?: Resume playing: Spotify?: Repeat at step 2: Error executing script. Error for call_service at pos 1: Failed to get device id from Spotify
2022-12-03 17:00:45.203 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: If at step 2: Parallel action at step 1: parallel 1: Resume needed?: Resume playing: Spotify?: Error executing script. Error for repeat at pos 2: Failed to get device id from Spotify
2022-12-03 17:00:45.206 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: If at step 2: Parallel action at step 1: parallel 1: Resume needed?: Error executing script. Error for choose at pos 2: Failed to get device id from Spotify
2022-12-03 17:00:45.211 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: If at step 2: Parallel action at step 1: parallel 1: Error executing script. Error for if at pos 9: Failed to get device id from Spotify
2022-12-03 17:00:45.213 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: If at step 2: Error executing script. Error for parallel at pos 1: Failed to get device id from Spotify
2022-12-03 17:00:45.216 ERROR (MainThread) [homeassistant.components.script.google_home_resume_helper] 00 - Google Home Resume - Helper Script: Error executing script. Error for if at pos 2: Failed to get device id from Spotify
2022-12-03 17:00:45.221 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved

Trace:
https://dpaste.org/tZXci

1 Like

That’s a spotcast error.
For me this helped: Cast device not launching properly, but works if timeout is ignored · Issue #365 · fondberg/spotcast · GitHub

Yep. Everything back in normal :+1:
NONE WARNINGS

1 Like

I just upgraded from an older version (2.8.6) of this script to the latest package version (2022.12.1). Two questions:

  1. Was the player’s screen setting retired? It was an aspect of my older configuration not seemingly included in the packages version. I never understood that setting, but I always assumed it was for media players with screens (ie Google Hub).

  2. I’m having difficulty with the Spotify resume function of the scripts. I’m assuming I have @Manazer problem based on similar errors concerning “Failed to get device id from Spotify”. I attempted to employ the spotcast error fix @TheFes mentioned above, however I have persistent issues that I do not understand.

Contextually:
Spotcast_controller.py was modified as such

    def startSpotifyController(self, access_token: str, expires: int) -> None:
        sp = SpotifyController(access_token, expires)
        self.castDevice.register_handler(sp)
        sp.launch_app()

        if not sp.is_launched and not sp.credential_error:
            # raise HomeAssistantError(
            #     "Failed to launch spotify controller due to timeout"
            # )
            _LOGGER.warning("Spotify controller did not launch properly before timeout, this might not be a problem")

        if not sp.is_launched and sp.credential_error:
            raise HomeAssistantError(
                "Failed to launch spotify controller due to credentials error"
            )

And spotify_controller.py was modified as such:

        counter = 0
        while counter < (timeout + 1):
            if self.is_launched:
                return
            self.waiting.wait(1)
            counter += 1

        if not self.is_launched:
            # raise LaunchError(
            #     "Timeout when waiting for status response from Spotify app"
            # )
            self.logger.warning("Timeout when waiting for status response from Spotify app")

    # pylint: disable=too-many-locals
    def quick_play(self, **kwargs):
        """
        Launches the spotify controller and returns when it's ready.
        To actually play media, another application using spotify connect is required.
        """
        self.access_token = kwargs["access_token"]
        self.expires = kwargs["expires"]

Did I implement the fix incorrectly or is there another issue?

Spotcast version: 3.6.30

It seems I indeed forgot to mention that players_screen is no longer needed.
It was mainly used for two reasons:

  1. To make sure they were turned off after the TTS or other action if nothing was playing before, to prevent the Home Assistant media player screen showing on the screen when it was not needed.
  2. If YouTube Music was started by voice command or by casting it from the YouTube Music app, the only way I found to resume it, is by using the YouTube cast method, which only works on screens.

The setting is no longer needed because I noticed the devices with a screen don’t have device_class: speaker, so I now use this to determine the device type.

Regarding the Spotcast issues, the changes you made look fine. I assume you did a restart after applying them?
As I’m not involved in Spotcast itself, I just use it, there is really nothing I can do here

Thanks for the swift reply! I’m glad the players_screen setting is no longer needed.

As for the Spotcast issue, yes I’ve tried to restart homeassistant entirely, but it hasn’t fixed itself. I appreciate your aid!

You messed up your settings.
All the settings are now under voice_settings, where only the settings specifically for the Voice script should be under that key.

Can you post what you now have at the top of the package, before the script starts

Now look at my version

For some reason you have voice_settings: directly under settings:. That’s not where it should be

I’ll try to make that more clear

It is mentioned in the instructions

I will also add it as a breaking change and make the placement of the line more clear

Update

Version 2022.12.2

:bug: Bug fixes

  • Add default to provide empty dictionary for settings in case no settings are provided.

There is something strange going on here, I’ll look into this tomorrow

Looks like your automation is still on an old version, I think you only reloaded scripts, but not automations.
Please reload automations in Developer tools > YAML Open your Home Assistant instance and show your server controls.

BTW, your setting for primary_spotcast is wrong, that should be bennett_campbell. Not that it really matters as you only have one Spotify account set up.

The automation is included in the package, you should remove it from any other location.

Update

Version 2022.12.3

:star2: Improvements

  • The automation is now also triggered if a Home Assistant group is targeted which has cast entities as its members

These traces don’t help me, as they are not related to the script.
They will trigger the automation, but they don’t show anything I can work on.

BTW your automation fails because you are using mode: single and it was triggered a second time while it was still completing the first run. But that has nothing to do with my script.

I need:

  • a trace of the automation (one that actually triggers the script, so use the arrows to go through them and pick the last one which doesn’t fail on the conditions).
  • a trace of the main Google Home Resume script
  • a trace of the Google Home Resume helper script which tried to resume the player which was playing Spotify