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

Found it, fixed in 1.6.0

Update

Version 1.6.0 - 7 March 2022

:red_circle: BREAKING

  • I’ve added YAML anchors to copy the variables set in the main resume script to the helper scripts, this means you need to keep the scripts in one yaml file, otherwise the anchors will not work.
  • The variable group_id whichis used for the group creation is moved to the config variables, because it was also used in the helper scripts

:star2: Improvements

  • Other changes to make the script work with the new Google Home Event script which I will publish soon.

:bug: Bug fixes

  • Fix for volume restore of group members

Seems substantially more broken now, sorry - doesn’t even work for single speakers. Different error:

Think this was my fault - its working after a restart! Thanks so much

Ah, solved already. :slight_smile:

I did see you only changed the primary_spotcast variable, and left the rest unchanged, but you changed it to jeremy.herbison instead of jeremy_herbison.
The error was coming from Spotcast, since there is no account for jeremy_herbison set up (as it is your primary, non named, account).

1 Like

My music resumes great and the camera feed also works. The only thing missing is the meta data. So the music starts playing but the screen is black. Below is what I initially send to the cast device.

media_content_type: music
media_content_id: http://icecast.vrtcdn.be/mnm-high.mp3
extra:
  metadata:
    metadataType: 3
    title: Music and More
    artist: VRT MNM
    images:
      - url: https://cdn-profiles.tunein.com/s10861/images/logoq.png?t=161772
1 Like

UPDATE

Version 1.6.1 - 9 March 2022

:star2: Improvements

  • Changed service call to resume audio streams so it will display the image on players with a screen as suggested by @thecobra666
1 Like

Excellent suggestion, I have been searching how to achieve this (showing the picture on a Google Nest Hub screen) but never found a working solution.
As you can see, I immediately implemented this :slight_smile:

1 Like

Hi, I have noticed recently that the volume is low on the announcements (2.5), I’ve edited the script to a volume of 6 but I’m still finding some of my players going back to 2.5. Is there something I’m missing? it’s strange as some media players remain at the volume they were set at while others revert back to 2.5 and will only play announcements at 2.5

2.5 and 6 are a bit strange values, it should be either 0.25 and 0.6 or 25 (%) and 60 (%)
If you enter 2.5 as volume, or 6 for that matter, that will result in 0.025 or 0.06 which is the same as 2.5% or 6%

Basically, TTS is no longer part of this script, as you can send any service call now, but I’m happy to help if I can, could you send the yaml code of how you now send the TTS and apply the TTS volume?

Sorry, I typed it incorrectly on here it was originally 0.25 and changed to 0.6 (default_volume_level: 0.6) I’m going to update the script in case I’m running an older version and update HA and see if that resolves it. If that doesn’t work I will post the yaml code, thanks.

The default_volume_level is not used for sending TTS, it is only used in case the script could not determine the volume of your speaker before it was interrupted (by the TTS, or something else) and will then be used as the volume after the interruption is over.

Example:

  • Player was off
  • Script was started, but could not retrieve the volume of the player
  • TTS was played on volume level 0.4
  • TTS is finished
  • Volume is set to default_volume_level setting, because volume before TTS was unknown

Update

Version 1.6.1 - 14 March 2022

:star2: Improvements

  • Do not store unnecessary data of non playing devices

I’m not sure default_volume_level is working right. Two issues:

If i use your script to send a TTS to a speaker that’s “off” (isn’t otherwise playing Spotify et al.) but has a volume of 50%, the volume level changes to 25%. Why? I didn’t do anything to change the volume.

If i set default_volume_level: 0.5 it still seems to change it to 25%. Shouldn’t it at least default to 50%? i mean, ideally it wouldn’t change it at all.

Could you upload a trace (json) to codepile.net (or a similar code upload site)
I can then see what’s happening.

Basically, it should change the volume back to the old volume, and if it is not known it should use the default_volume_level set.

CodePile | Easily Share Piles of Code | Pile

It appears this only occurs if the speaker is off when your script is called - i set the volume to 50%, turn it off, then called this “test” automation. The volume is now at 25%.

Tried again with the speaker on, and it stayed at 50%.

Sorry, I need a trace of the Google Home Resume script, not of the automation in which you call it.
And of course from when it doesn’t work properly, so when the speaker is off.

Basically the script should turn the speaker on first, and then retrieve the volume. And if that is not working, it should at least use the default_volume_level you’ve set.

Right, of course - duh.

I just realized the restore non-playing script also needs variables defined, so that’s where the 0.25 is coming from. So the bug is just that it can’t read the volume out of an “off” speaker, i guess.

CodePile | Easily Share Piles of Code | Pile
CodePile | Easily Share Piles of Code | Pile

Are you using different files per script? Because the default_volume_level setting should be the same as for the main script as YAML anchors are used.

But I think you gave me a push in the right direction, I have to check, but I think I can solve this quite easily.

Hi @TheFes, I have a question.
I’m succefull add your script Resume to my HA. But I have some confuse on the way script working, can you find out my issue for me.
I have script with multi TTS and media play queued and I make automation to play this script.

The problem is that. After play first service ( a script to play media with delay ).
It resume media before activate automation and after that continue play media on script.
After finsish script nothing was resume.
The length of TTS is about 100 seconds
I don’t know why the Resume script activated while my script have still not finished yet
I don’t find out any error and all script finished successful
P/s: My script play_audio very simple. It’s just play message and add delay, timeout same as in example

On script part:

 - choose: 
       - conditions: .....
   default:
       - service: script.play_audio
        data:
          message: !include speech/notify.yaml    
      - service: media_player.play_media
        data:
          entity_id: media_player.loa
          media_content_id: ' {{ [ 
          				"http://local/media/ringtone/A.mp3",
          			        "http://local/media/ringtone/B.mp3",
            			 ] | random}} '
          media_content_type: music
      
      - delay: 00:00:05
      - timeout: "{{  state_attr('media_player.loa','media_duration') |float + 5 | round(0)}}"
        wait_template: '{{ not is_state ( "media_player.loa", "playing")}}'       

On automation part:

 - service: script.google_home_resume
    data:
      action:
        - service: script.turn_on
          target:
            entity_id: script.my_script
 
      target:
        entity_id: media_player.loa

Don’t use script.turn_on, but use service: script.my_script.
With script.turn_on the resume_script will go to the next step immediately. When you call the script directly, the resume script will wait until it is finished to go to the next step.

1 Like