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

thank you so much. I’ll try that.

aha, it looks like if you open up the script in the UI and then view the yaml, it copies the anchored values then strips the anchor out. I must have done this prior to configuring them in the main script.

might want to add a note about not using the UI to save changes, and to set variables directly in scripts.yaml.

So that’s resolved, but there is still the bug with it not reading volumes from “off” speakers.

Okay, will look into that next week (Monday I think)

Thanks for your suggest on last post. It works great.
I have one more questions.
On resume script why don’t you add delay at the end of alias Perform service calls defined in action @TheFes ?.
For example, when i play media_player service and after that play tts service
if I don’t add delay between them, there is only tts service playing.

You mean a delay between each service call defined in the action field? That would mean a lot more configuration variables for something maybe only a few people need.

Using a script like you are doing now is better then.

1 Like

That mean each automation we have to make invidually script for that. I think it unnecessary if just few call services invidually. If using complicate services conditions or repeat…I agree create script is the best and make code not duplicate between automation and script
I think no need to create variable for this. Just add it as default. I try to edit your code and add it in repeat loop. I worked :slight_smile:

- delay: 00:00:05
      - timeout: "{{  state_attr('media_player.home','media_duration') |float }}"
        wait_template: '{{ not is_state ( "media_player.home", "playing")}}' 

Finally, thanks alots for makeing create script.

That won’t work in cases like this for example:

action:
  - service: tts.google_voice
    target:
      entity_id: media_player.jack
    data:
      message: Jack, dinner is ready!
  - service: tts.google_voice
    target:
      entity_id: media_player.jones
    data:
      message: Jones, dinner is ready!

I want to keep the script as versatile as possible, and when I would implement your suggestion, that would mean the message to Jones will be sent when the message to Jack is completed, and the player is idle again.
So, it should at least be optional.

I also think it could cause to unexpected results if you include more then one target, e.g. both to Jack and Jones. If Jack is already finished, but Jones not, they will have to wait for each other, of one of them might be cut of early.
That is what I wanted to avoid by creating a separate script for performing the resume.

So your suggestion could work in your use case, but not for others. That’s why additional configuration values are needed, and I suggest to use a script instead.

You could create a generic script and use variables like I do in mine, so you’ll only have to create one.

1 Like

Update

Version 1.7.0/1.7.1 - 21 March 2022

:star2: Improvements

  • No need for YAML anchors anymore, all data in the variables will be applied in the main script now.
  • Several changes to work better with the Google Home Event script

:bug: Bug fixes

  • Fix for volume restore
  • (1.7.1) Template fixes for fixed_picture and for determining group members for non playing devices

Your issue should be fixed now.
I also removed the need for the YAML anchors.

I think I got lost after the last update to 1.7.0:

Logger: homeassistant.components.script.google_home_resume
Source: helpers/script.py:1365
Integration: Script
First occurred: 8:07:19 PM (1 occurrences)
Last logged: 8:07:19 PM

00 🔊 Google Home Resume: Error executing script. Error rendering template for variables at pos 7: UndefinedError: 'None' has no attribute 'keys'
Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 8:07:19 PM (1 occurrences)
Last logged: 8:07:19 PM

Template variable error: 'None' has no attribute 'keys' when rendering '{%- set ns = namespace(info=[]) %} {%- for entity in player_data %} {%- set members = speaker_groups[entity.entity_id] if speaker_groups is defined and entity.entity_id in speaker_group_list else [] %} {%- set screen = players_screen is defined and entity.entity_id in players_screen %} {%- set type = iif(members != 'no group','group',iif(screen,'screen','no screen')) %} {%- if entity.volume_level == 'no volume' %} {%- set volume = state_attr(entity.entity_id, 'volume_level') %} {%- set volume = volume if volume | is_number else default_volume_level %} {%- else %} {%- set volume = entity.volume_level %} {%- endif %} {%- if entity.state == 'playing' %} {%- set picture = fixed_picture[entity.media_artist] if fixed_picture is defined and entity.media_artis in fixed_picture.keys() else entity.entity_picture %} {%- set list_check = [ entity.entity_id ] + members %} {%- set names_check = expand(list_check) | map(attribute='name') | list %} {%- set spotcast = spotify_data | selectattr('source', 'in', names_check) | map(attribute='entity_id') | join | replace('media_player.spotify_', '') %} {% set spotcast = iif(spotcast, spotcast, primary_spotcast) %} {% set spotcast = iif(spotcast == primary_spotcast, 'primary_account', spotcast) %} {%- set ns.info = ns.info + [ dict( entity_id = entity.entity_id, friendly_name = entity.friendly_name, members = members, state = entity.state, media_content_id = entity.media_content_id, media_title = entity.media_title, media_artist = entity.media_artist, media_content_type = entity.media_content_type, app_name = entity.app_name, spotcast = iif(entity.app_name == 'Spotify', spotcast, 'no spotify'), entity_picture = picture, volume_level = volume, media_position = entity.media_position, type = type, data_source = entity.data_source ) ] %} {%- else %} {%- set ns.info = ns.info + [ dict( entity_id = entity.entity_id, friendly_name = entity.friendly_name, members = members, state = entity.state, volume_level = volume, type = type, data_source = entity.data_source ) ] %} {%- endif %} {%- endfor %} {{ ns.info }}'

I accidentally (stupidly) deleted all my scripts and had to create them again. Not sure what I’m doing different this time around but I’m getting the following error after running the script.

Failed to call service script/washing_on_line. Error rendering data template: UndefinedError: 'player' is undefined

Everything works fine from what I can see but unsure why this error is appearing. Any ideas?

Could you send a trace? Probably something I did not take into account when the variable is not provided.

Is script/washing_on_line something you provided? Could you also provide a trace of the resume script?

Yes. The trace is here

https://www.codepile.net/pile/aZQ5V0ZW

@Jakesa, @Manazer
Both issues should be fixed in 1.7.1

1 Like

Update

Version 1.7.2/1.7.3 - 22 March 2022

:star2: Improvements

  • Added a update of Spotify entities before data is stored, so the most recent data is used
  • Only relevant data of entities is stored (depending on state and playing app)

:bug: Bug fixes

  • (1.7.3) Template fix

Thank you. Working like a charm.

I’m using this too, works like a charm. only beef I have with it that it’s sometimes start a bit into the message, I used to put in a delay, but that might be due to the cast speaker group.

Hi I’m using minidlna integration in homeassistant which will play over my google minis, onlt one track at a time so far but … sometimes i will get an announcement like “the kettle has boiled” which stops the music and I would like it to resume.

Will this project help me achieve this
I think with the spotify integration you must have a full not free account so that part will probably not function.
I do have the radio integration in media so that could be useful.
I was trying to play around with your script last night but to be honest I don’t understand it yet.

So essentially will this project let me resume or restart a song streaming from minidlna ?
Are there sections i don’t need if i’m not using the functionality like spotify.

all the best

John