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

Background

This package started somewhere in 2020 as a simple script to resume a Google Cast device after it was interrupted by a TTS message. During the years more functionality was added, the Cast devices can also be resumed after playing an audio file, or casting a Home Assistant Dasboard.

In the past years I also created others scripts using the Google Home Resume script. There is a script to determine on which device a question was asked and send a TTS or play a file on that specific device. Another script stores the state of the cast devices in a template sensor, so it can be resumed in later (for example store it when you leave home, and restore it when you arrive home again).

All these scripts are now combined in one package


:rotating_light: NEW REPOSITORY FOR THE PACKAGE :rotating_light:

The package has been moved to an own dedicated GitHub repo: GitHub - TheFes/Google-Home-Resume: Google Home Resume package for Home Assistant. Update your bookmarks accordingly!


:rotating_light: USAGE OF THE AUTOMATION :rotating_light:

The automation to start the resume is intended to be used as a backup. If you already know you are going to send (like a TTS or mp3) and know you want to resume what was playing afterwards, I strongly advice to start the script yourself, and not rely on the automation, as it is a bit flaky.

See here for instructions how to do that.


Latest version

2023.8

:radio: GENERAL

:rotating_light: BREAKING

  • (2022.8.0) Removed support for Music Assistant. The integration is broken for a couple of months already, and the new version is still in beta. Will look at it again if the final version of MA2 is released

:recycle: RESUME SCRIPT

:sparkles: New features

  • Added support for resuming BBC streams (BBC Sounds and BBC Iplayer (for players with a screen))

:bug: Bug fixes

  • (2022.8.0) Fix bug in target determination
  • (2022.8.0) Actually use the correct setting for enabling the automation, so now setting this to false actually works.

Previous changes can be found here:


How to install and use the package

As of version 2023.8 the instructions how to install the package are moved to the GHR GitHub repository, so it is easier for me to keep them up to date.


Buy me a coffee

If you like this script, please feel free to buy me a coffee (I might spend it on another beverage though).
In case you decide to do so, thanks a lot!

Buy Me A Coffee

48 Likes

That looks great @TheFes . However it is not clear no me how to call the script. I have automation that use google say to broadcast a message to google nest hub everytime the garage door is opened. How could I use the script to resume spotify music or youtube video after the message is played?

@jpleite What is the current YAML code to perform that action? If it is service call (so service: some.service) you can use it directly with this script. If not, you need to create a script and call that.

If you want you can paste the YAML code here, and I can show how it should work in cooperation with the script.

BTW, if you are sending a TTS message, you can also use the TTS specific script linked in the Background section.

So is this script also usable without spotify?
I don’t use speakergroups, can is just delete those lines?

Hi @TheFes. Thanks for your prompt reply. As an example, when the garage door is opened I have an automation to notify several devices including google nest via tts.cloud_say. Bellow the automation

alias: Garage Door Open (Tileboard; TTS; iOS; WebOS)
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 127dea8fbf242d4f9a0f2b849474aec9
    entity_id: binary_sensor.garage_door_sensor
    domain: binary_sensor
condition: []
action:
  - event: tileboard
    event_data:
      command: open_garagedoorentry
  - service: notify.mobile_app_milkphone_13_pro_max
    data:
      title: Attention!
      message: Garage is door is open!
      data:
        entity_id: camera.garage
  - service: notify.milkhome
    data:
      message: O portão da garagem foi aberto!
  - service: notify.living_room_tv
    data:
      message: O portão da garagem foi aberto!
  - service: notify.basement_room_tv
    data:
      message: O portão da garagem foi aberto!
  - service: tts.cloud_say
    data:
      entity_id: media_player.kitchen_google_hub
      message: O portão da garagem foi aberto!
mode: single
initial_state: true

Yes, just remove the variables speaker_groups and primary_spotccast

@jpleite
As far as I can see, the only action which will stop Google Cast devices, and will need resuming, is the last one (the TTS).
You could also use the TTS specific script in that case, but this script will also work.
After you included the script in your HA setup, and amended the variables for your needs, you can amend the automation to this:

alias: Garage Door Open (Tileboard; TTS; iOS; WebOS)
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 127dea8fbf242d4f9a0f2b849474aec9
    entity_id: binary_sensor.garage_door_sensor
    domain: binary_sensor
condition: []
action:
  - event: tileboard
    event_data:
      command: open_garagedoorentry
  - service: notify.mobile_app_milkphone_13_pro_max
    data:
      title: Attention!
      message: Garage is door is open!
      data:
        entity_id: camera.garage
  - service: notify.milkhome
    data:
      message: O portão da garagem foi aberto!
  - service: notify.living_room_tv
    data:
      message: O portão da garagem foi aberto!
  - service: notify.basement_room_tv
    data:
      message: O portão da garagem foi aberto!
  - service: script.google_home_resume
    data:
      action:
        - service: tts.cloud_say
          data:
            entity_id: media_player.kitchen_google_hub
            message: O portão da garagem foi aberto!
mode: single
initial_state: true

Hi @TheFes . It worked like a charm! Thanks for your help and great work!

Added To Do section to first post

To Do

  • Dynamic creation of the group.resume_active, so it is possible to track for which entities the script is active
  • Make it possible to queue actions if the script is called multiple times for the same entity (this will requre the script to be cut into different scripts)
  • Add some information on how do the TTS actions like I did in the Google Home Say script which is no longer maintained. (basically it is calling this script as an action in the Google Home Resume script and provide the target (example)).

Update

1 February 2022

  • The script will now create a group (group.resume_active) and add the entties which are going to be resumed there. It will remove the entity from the group after it has been resumed. Entities which are listed in this group will be ignored, so only the original stream will be resumed.
  • Replaced persistant notifications with log messages. In case no valid service calls are provided, the script will abort and an error will be logged. In case thre are valid service calls, but also other invalid actions, a warning will be logged.
  • Adjusted some templates to avoid warnings in the log.

I’m trying to give this one a try. I’ve added the script in the scripts section of my Home Assistant and can call the script by a call. When I use the google_translate_say there, it works like a charm and tts my message. If I was playing a Youtube cast on my Nest Hub, will this resume afterwards or? That’s the thing I still can’t get to work.

1 Like

Well, not at this moment, I originally focused on audio (Spotify/TuneIn)
I can have a look, I think the most tricky part will be to get the the right moment the video was stopped.

That should be really awesome. I gave the broadcast function a try as well, so the TTS messages are just an ‘overlay’ of the content behind it. That is in my opinion the best approach, but I believe that’s even more difficult :wink: I tried it with: Assistant Relay

I’ve tried Assistant Relay, not it is not maintained anymore. And as Dutch is not supported, it was no solution for me.

Also it always sends the broadcast to all devices in your home, and it announced the broadcast, which can be annoying.

Hi, I’m having some issues implementing this script and getting the error ‘Failed to call service script/google_home_resume_wip. Error rendering data template: UndefinedError: ‘iif’ is undefined’.

No doubt it is something I have or haven’t done but any ideas where I’m going wrong, please? Would love to get this set up, my family get quite annoyed with my announcements interrupting their music and have to start the music from the beginning.

Oh, sorry, should have waited to after today to publish it. The iif function is new in 2022.2 which will be released today.
I also forgot to remove the _wip part

Yeah, got the same issue with that :wink: All devices & no dutch language. But the overlay was nice though. I’m interested if you can manage to let something like the youtube stream continue after TTS. Will follow this one :wink: Thanks for your effort!

Update

3 February 2022

  • Added requirements (HA Version 2022.2) to first post, also added requirements for Spotify resume there.
  • Removed WIP (work in progress) references in script object_id and alias.

The script now fires up with no errors after the HA core update but I’m still facing some issues.

if I fire up:

service: script.google_home_resume
data:
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.dressing_room_speaker
        message: test

It plays the TTS announcement, makes a few google sounds but the music does not resume, any idea where I’m going wrong please?

I’m currently debugging a bit myself, but could you try if it works like this:

service: script.google_home_resume
data:
  target:
    entity_id: media_player.dressing_room_speaker
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.dressing_room_speaker
        message: test
1 Like