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

Update

Version 1.1.1 - 10 February 2022

:star2: Improvements

  • Changed some templates to a more efficient version

Hi,
I have this warning in the log:

Logger: homeassistant.components.group
Source: components/group/__init__.py:292
Integration: Group (documentation, issues)
First occurred: 3:17:50 PM (3 occurrences)
Last logged: 3:17:50 PM

remove:Group 'resume_script_active' doesn't exist!
remove:Group 'resume_active' doesn't exist!
remove:Group 'resume_action_false' doesn't exist!

group: enabled in config

Thanks, i already know what causes this. I will fix this asap.

Update

Version 1.1.2 - 10 February 2022

:star2: Improvements

  • Temporary fix to avoid log warnings when the script tries to remove non existing groups (will replace these 3 choose blocks with a repeat in the next version. (Thanks for reporting this @Manazer )
  • Groups will also be removed when the last instance of the script finishes.

HI

Thanks for this !

have you considered a blueprint ?

Yes, but it wasn’t working. See also this comment I made in the comments on the topic of the TTS-only version of this script: Script to resume radio (TuneIn) and Spotify after TTS on Google Home speakers - #68 by TheFes

1 Like

Sorry, but after update 1.1.2 another error occures:

Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 8:20:07 AM (3 occurrences)
Last logged: 8:20:07 AM

Template variable error: 'integration_enities' is undefined when rendering '{{ 'group.resume_script_active' in integration_enities('group') }}'
Template variable error: 'integration_enities' is undefined when rendering '{{ 'group.resume_active' in integration_enities('group') }}'
Template variable error: 'integration_enities' is undefined when rendering '{{ 'group.resume_action_false' in integration_enities('group') }}'

and warning:

Logger: homeassistant.helpers.script
Source: helpers/script.py:659
First occurred: 8:20:07 AM (3 occurrences)
Last logged: 8:20:07 AM

Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'integration_enities' is undefined

Sorry, that’s what you got when you quickly want to change something on mobile.
There was a typo in the template function. Should be fixed now in 1.1.3.

Update

Version 1.1.3 - 11 February 2022

:bug: Bug fixes

  • Fixed typo in templates. Mental note: do not edit on mobile :wink:

Fully agree :+1:

#Update

Version 1.1.4 - 11 February 2022

:star2: Improvements

  • Better way of removing groups at start and end of script

Hey @TheFes, great work on the comprehensive script.

Any light at the end of the tunnel for no-screen devices playing YouTube Music ? i.e. Google Home Mini.
Why doesn’t it work when there is no screen ? I can see my mini speaker has media_content_id when playing YouTube music, app_name shows “Youtube Music” and I can control the player through Home Assistant when it’s already “loaded” (started by voice and playing something). I’ve been trying different ways to get it to play something using the media_player.play_media service but no luck. When using app_name: Youtube Music then nothing happens but when using app_name: Youtube then it loads the youtube player in Home Assistant (but nothing starts playing because youtube and youtube music content id’s probably don’t match). Anyways, if you have ideas how to get this to work, that would be super cool, probably many other people looking for this solution as well.

Hi. What you describe here is exactly what I do in the script as well, and what does work for devices with a screen. So the problem is not that the media_content_id doesn’t match, the problem is that the app_name: youtube is not supported on devices without a screen.

I’ve tried everything I could think of as app_name for YouTube Music, but nothing worked.
The only way I could get it to work is using the ytube_music_player custom integration, but only if the stream was started using that integration.

Do note that resuming the stream using cast is limited as well, as it will only resume the video/song which was playing, and not the complete playlist/album/channel

Then that might be a dead end.

A somewhat workaround solution might be to send a text command from HA to Google Assistant speaker: “play the last song on youtube music”. Then it should at least restart the last played song. Could even try something like “continue playing the last song from where it was last stopped”. Google Assistant is pretty smart and something like this might work, haven’t tested tho. I know there were some addons and ways to send text commands this way, don’t remember exactly. Something to do with webhooks and IFTTT. Maybe you get some good ideas through this angle :stuck_out_tongue:

Could also be done with something like Assistant Relay, but that will be difficult because people will use different languages for their Google Home. So you can’t just use a command in English.

You will also run in issues when there are different people in the same house all using their own account, how will you know which account was used to play it.

For YouTube Music the best solution at this moment is ytube_music_player. But then you can’t start it by voice command, you’ll have to use the media browser of HA.

It’s unfortunate that the same information as is available though the Spotify integration is not visible.

I use your script, it works well! Great work, thak you! I have two small problems with it. I only use to resume to tunein, and the resume is a bit slow(start to conect to stream quickly, but the connecting is slow). It’s a lot slower, like I’m just starting tunein. Why? The other problem is that after resume, on my hub, the screen is blank, not showing what it is playing(not showing anything). Am i doing something wrong, or is it normal?

It doesn’t show it like before, because it uses the default media player to resume the stream, and not the TuneIn cast functionality like Google does.

What do you exactly mean with slow? It tries to resume as soon as your player is idle or off, it could be that there is a delay in getting this state.

The resume is fast, but the connection to the stream is slow. But I think it’s because of the different application behavior (default media player vs tunein app)

Update

Version 1.2.0 - 13 February 2022

:red_circle: BREAKING

  • Made several changes in how data is sent from the Google Home Voice script to this one. So if you update this script, make sure to also update the other one

:star2: Improvements

  • When speaker groups are changed, the volume of the individual group members will now be restored, instead of the volume of the group.
  • Several changes in templates, and how data of cast entities is gathered and stored

:receipt: Docs

  • Added section on why this is not a blueprint
3 Likes

Sorry for all the updates :slight_smile:

Update

Version 1.2.1 - 14 February 2022 :heart_decoration:

:star2: Improvements

  • Added volume restore for ytube_music_player

:bug: Bug fixes

  • Fix for resuming ytube_music_player after Google Home Voice script
1 Like