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

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

Thank you soo much!! That seems to work for Spotify music now, although it doesn’t seem to work for radio, is it possible to resume radio after the announcements?

How do you play radio? It should work for TuneIn streams.
I will look into your previous question though, it should have worked without specifying the target.

It uses ‘Global Player Live’ as the default but if I ask google to play via Tunein the script works fine. Tbh If it means I only need to mention Tunein I’m not too fussed.