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

Thanks for the quick answer! I have looked into it. I was just wondering since if you send more than one TTS message back to back to any google home device, it will make the beep twice using your code. If you use the standar TTS feature, you will hear it the first time, then the second TTS message wont have a beep until it automatically goes off after 4-5 mins of inactivity.

I tested it very quickly last night, I’ll have to do some more testing.

My script doesn’t do anything different to cause the bleep, if it is already awake, it won’t bleep.
It could be that what you are hearing is the volume adjust sound, it adjust the volume before the TTS starts, and then back to the original value after the TTS.
That also causes some (maybe annoying) sound.

I’ll test it again when I get home, thank you for all the work!

Some errors after upgrade:

Error doing job: Task exception was never retrieved
6:26:05 PM – (ERROR) core.py
00 🔊 Google Home Resume - Restore non playing: Error executing script. Invalid data for call_service at pos 5: invalid slug resume_active__32a633f7fb2fb7e001a09d0a7b772914 (try resume_active_32a633f7fb2fb7e001a09d0a7b772914) for dictionary value @ data['object_id']
6:26:05 PM – (ERROR) Script
Template variable warning: 'group_id' is undefined when rendering 'resume_active_{{ group_id }}_{{ context.id }}'
6:26:05 PM – (WARNING) helpers/template.py
Error in 'choose[0]' evaluation: In 'template' condition: TypeError: first argument must be string or compiled pattern
6:26:05 PM – (WARNING) helpers/script.py

Double underscore

I am testing this, but then the (spotify) song is resumed, it doesnt resume from when it was interrupted, but from a much earlier point (sometimes 30 seconds, sometimes more). Volume is restored correctly.
Any ideas?
Thanks!

Still now with 1.5.1?

I actually let Spotcast handle that.
Never noticed it myself, but I’ll do a check.

It’s OK now. Thank you

I’ve been tring to get this script integrated in my setup but I cannot get it to work properly.
From what I’m guessing I’ve got 2 different problems:

  1. A google speaker pair doesn’t seem to display what it is playing anymore (the google app will say it’s playing but doesn’t display the contents (eg name of the radiostation) anymore) so when trying the resume script it doesn’t resume playback. with single speakers or in a group that doesn’t include a speaker pair it is working as expected.

  2. there are 2 camerastreams being started, one of them is on the google hub in the kitchen so looks like to get that working I need to incorporate the same solution you suggested for “the cobra 666”?

this is the automation I’m using at the moment:

alias: Melding Deurbel
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.deurbel
    from: 'off'
    to: 'on'
condition: []
action:
  - service: camera.snapshot
    data:
      filename: /config/www/images/deurbel.jpg
    target:
      device_id: 10eb922exxxxxxxxxxxxxxx318c3eafc38
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
  - service: notify.mobile_app_yvette_gsm
    data:
      message: Er staat iemand aan de deur! 🚪
      title: Hoi Yvette,
      data:
        image: /local/images/deurbel.jpg
  - service: notify.mobile_app_mvt_gsm
    data:
      message: Er staat iemand aan de deur! 🚪
      title: Hey Maurice,
      data:
        image: /local/images/deurbel.jpg
  - service: notify.lg_webos_tv_ym
    data:
      message: ER STAAT IEMAND AAN DE DEUR. 🚪
  - service: script.google_home_resume
    data:
      action:
        - service: media_player.volume_set
          data:
            volume_level: 0.25
          target:
            entity_id:
              - media_player.kantoor
              - media_player.badkamer
              - media_player.woonkamer_speakers_2
        - service: media_player.play_media
          data:
            media_content_id: http://192.168.2.3:8123/local/audio/duckbell.mp3
            media_content_type: music
          target:
            entity_id:
              - media_player.kantoor
              - media_player.badkamer
              - media_player.woonkamer_speakers_2
  - service: browser_mod.popup
    data:
      command: popup
      title: De deurbel gaat
      large: 'true'
      card:
        entity: camera.voordeurcamera_profile_000
        type: picture-entity
        camera_view: live
        deviceID:
          - 06xxxx-xxxx0ec
  - service: camera.play_stream
    target:
      device_id: 10eb922e29xxxxxxxxx18c3eafc38
    data:
      media_player: media_player.keuken
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: media_player.media_stop
    data: {}
    target:
      device_id: 18f56952xxxxxxxxxxx682d6a05d38d
  - service: browser_mod.close_popup
    data: {}
mode: single

Speaker pairs indeed seem to have some issues with displaying the data. There is nothing I can do about that, best would be to log an issue for Home Assistent Core related to the cast integration.

For you second the approach I suggested earlier to create two scripts seems best for your automation as well.

1 Like

I don’t think it’s an issue with home assistant. the google home app doesn’t display the data either. As far as I can find it has something to do with the patent case from google/sonos.

I will try out the suggested scripts for the automation, thanks!

Sorry… I’m new in HA and Node red. How do i “install” this script so the music repeats when the TTS has been played from Node red? The announcement work from Node red to speakers, but it stops ex. playing TuneIn Radio

I have no experience with node red, but I assume you can call the script like shown above from Node-Red as well.

When I just copy past the script in a new script create window (in yaml mode) it always says: Message malformed: extra keys not allowed @ data[‘google_home_resume’]

What am I doing wrong?

You should paste it directly in script.yaml, not in the GUI.
If you want to do it in the GUI, you need to make sure you paste only 1 script at the time (as there are 3 now) and you need to remove the first line with the script name (eg google_home_resume).
But it is a lot easier if you just paste the whole thing in script.yaml

1 Like

doh… does it say this on the github page? I probably have missed that :smiley: works now, thanks!

Good point, I will make that more clear

1 Like

Thanks for the script! Its working very well for me except with speaker groups, at least with TTS cloud say.

If I don’t define the speaker group i’m currently playing to, then send a TTS, it resumes playing on only the speaker the TTS went to. Fine, as expected. So i add the following:

  speaker_groups:
    media_player.basement_speakers:
      - media_player.rec_room_speaker
      - media_player.basement_office_speaker

Now it doesn’t resume at all, and I see the following error logged:

Google Home Resume - Perform Resume: Resume needed?: choice 1: Set volume to old volume if needed: choice 1: Player is group?: choice 1: Restore volume of members: Error executing script. Invalid data for call_service at pos 1: expected float for dictionary value @ data[‘volume_level’]
Google Home Resume - Perform Resume: Resume needed?: choice 1: Set volume to old volume if needed: choice 1: Player is group?: choice 1: Error executing script. Invalid data for repeat at pos 2: expected float for dictionary value @ data[‘volume_level’]
Google Home Resume - Perform Resume: Resume needed?: choice 1: Set volume to old volume if needed: choice 1: Error executing script. Invalid data for choose at pos 1: expected float for dictionary value @ data[‘volume_level’]
Google Home Resume - Perform Resume: Resume needed?: choice 1: Error executing script. Invalid data for choose at pos 2: expected float for dictionary value @ data[‘volume_level’]
Google Home Resume - Perform Resume: Error executing script. Invalid data for choose at pos 3: expected float for dictionary value @ data[‘volume_level’]

I’m not quite sure what the issue is… the speaker group has a volume_level attribute, and its set to like 0.400012 or whatever.

I’m calling the script like this:

service: script.google_home_resume
data:
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.rec_room_speaker
        message: testing 1 2 3

Not sure as well based on this data, can you send upload a trace of the google_home_resume script, and of the google_home_resume_perform_resume script to a webiste like codepile.net

I need to see what the script stored as data, and how you set it up.

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

Thanks!