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

Yeah I copied the new script on github after your last post. I start the youtube cast on the Nest Hub, and called the TTS with your script. It stops, played the TTS and returned to Youtube. But then it gave me an error that it couldn’t find the media_position. The youtube video just started from the start.

Okay, I must admit I didn’t properly test it after I changed some things. I will do that within the next hour.

1 Like

Could you test it again?

1 Like

Just tested it on the Nest Hub, works like a charm now! Thanks a lot!

How do I configure players with a screen? I understand I need to add the file directory in ‘fixed_picture’ but is it a case of downloading the image to the stated directory and that image will show when resumed?

If so, is this just for radio or for Spotify artists too?

Hi,

Those fixed_pictures are not related to the players with a screen.
I’ve put that in because many radio stations on TuneIn use the album art for the song which is playing as the entity picture.
That will not work after resuming, as it is not playing via TuneIn anymore. So, without the fixed_picture you will be stuck with the picture of the song when the stream was interrupted.
I’ve added fixed pictures for the TuneIn streams I use frequently to avoid that.

For Spotify it’s not an issue, as Spotify will be still playing and updating the pictures.

The players_screen variable is to make sure the backdrop is shown after it has been interrupted and nothing was playing.

Ahh ok, that makes sense, Thanks. Currently on my display if it is interrupted it returns with a blank screen.

I also just tested youtube with the updated script but it didn’t resume, is there anything I need to amend in the script? the device is a Google home display (before they became nest).

I just published a better way of handling the thumbnails.
But they are just that, a thumbnail. The screen will be black (the thumbnail is shown on your the entity in HA, and maybe in the bottom where the controls are on your speaker).

I also found out that YouTube only resumes on players with a screen. Maybe that was the issue?
I’m trying to do something with the YouTube Music integration on HACS, but I’m not sure if it will work as I would like.

Sorry, I should have said, the Google home display does have a screen but maybe doesn’t work as it’s the oldest version?

No, that should not matter. Can you send share the json of the script trace (via a site like codepile.net)
I will not have time to look into it anymore this week, Monday probably.

The music/radio side works great and I hardly use youtube but just thought I would share. As for the share of json script trace, I’m not entirely sure how to do that (sorry!). Would it be by clicking show trace on the ‘00 :loud_sound: Google Home Resume’ script?

Yep, and then click the download button on the top right.
I do need the trace from when it wasn’t successful.

Thanks, I will get that sorted. Have a good weekend!

@TheFes exactly what I was looking for!
going to try it in the coming week. After reading all info and most of this thread I’m only wondering if it is possible to add 2 spotify acounts to check if music is playing or is it only the primary account?

@djMvT Guess you missed this post then :slightly_smiling_face::

1 Like

Hi,
everything is working as expected (resuming tunein & spotify interrupted by microsoft tts service), but in the log there is a Template variable warning.
I have tried to define “target” twice (as proposed here earlier) - without any change - warning still received.

How to get rid of it?

Logger: homeassistant.helpers.template
Source: helpers/template.py:1822
First occurred: 9:56:35 AM (3 occurrences)
Last logged: 9:56:35 AM

Template variable warning: 'dict object' has no attribute 'target' when rendering '{# determine entities of cast integraton #} {%- set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %} {%- set ns = namespace(entities = []) %} {%- for device in devices %} {%- set ids = device_attr(device, 'identifiers') %} {% set ids = device_attr(device, 'identifiers') | list | first if ids else [] %} {%- if ids and ids | length == 2 and ids[0] == 'cast' %} {%- set ns.entities = ns.entities + device_entities(device) %} {%- endif %} {%- endfor %} {%- set cast_entities = ns.entities + speaker_group_list %} {# create target lists #} {%- if target is defined %} {# create lists based on target input #} {%- set area_list = target.area_id.replace(' ' , '').split(',') if target.area_id is string else target.area_id %} {%- set device_list = target.device_id.replace(' ' , '').split(',') if target.device_id is string else target.device_id %} {%- set entity_list = target.entity_id.replace(' ' , '').split(',') if target.entity_id is string else target.entity_id %} {%- endif %} {# determine targets based on actions #} {%- set ns = namespace(entity = [], device = [], area = [] ) %} {%- for item in service_calls %} {%- set entity_s = item.get('entity_id', []) %} {%- set device_s = item.get('device_id', []) %} {%- set area_s = item.get('area_id', []) %} {%- set entity_d = item.data.get('entity_id', []) if item.data else [] %} {%- set device_d = item.data.get('device_id', []) if item.data else [] %} {%- set area_d = item.data.get('area_id', []) if item.data else [] %} {%- set entity_t = item.target.get('entity_id', []) if item.target else [] %} {%- set device_t = item.target.get('device_id', []) if item.target else [] %} {%- set area_t = item.target.get('area_id', []) if item.target else [] %} {%- set entity = ( [ entity_s ] if entity_s is string else entity_s) + ( [ entity_d ] if entity_d is string else entity_d) + ( [ entity_t ] if entity_t is string else entity_t) %} {%- set device = ( [ device_s ] if device_s is string else device_s) + ( [ device_d ] if device_d is string else device_d) + ( [ device_t ] if device_t is string else device_t) %} {%- set area = ( [ area_s ] if area_s is string else area_s) + ( [ area_d ] if area_d is string else area_d) + ( [ area_t ] if area_t is string else area_t) %} {%- set ns.entity = entity + ns.entity %} {%- set ns.device = device + ns.device%} {%- set ns.area = area + ns.area %} {%- endfor %} {%- set area_list = ns.area + (area_list if area_list is defined else []) %} {%- set device_list = ns.device + (device_list if device_list is defined else []) %} {%- set entity_list = ns.entity + (entity_list if entity_list is defined else []) %} {# create entity list based on device/area input #} {# determine cast entities of areas #} {%- set ns = namespace(area_cast = []) %} {%- for area in area_list %} {%- set ns.area_cast = ns.area_cast + area_entities(area) | select('in', cast_entities) | list %} {%- endfor %} {%- set area_cast = ns.area_cast %} {# determine cast entities of devices #} {%- set ns = namespace(device_cast = []) %} {%- for device in device_list %} {%- set ns.device_cast = ns.device_cast + device_entities(device) | select('in', cast_entities) | list %} {%- endfor %} {%- set device_cast = ns.device_cast %} {# determine cast entities of all entities #} {%- set entity_cast = entity_list | select('in', cast_entities) | list %} {# create list with all entities #} {%- set total_list = (area_cast + device_cast + entity_cast) | unique | list %} {# avoid to target both complete speaker groups and single members #} {%- set target_group = total_list | select('in', speaker_group_list) | list %} {%- set target_single = total_list | reject('in', speaker_group_list) | list %} {%- set ns = namespace(groupmembers = []) %} {%- for group in target_group %} {%- set ns.groupmembers = ns.groupmembers + speaker_groups[group] %} {%- endfor %} {%- set single_not_in_group = target_single | reject('in', ns.groupmembers | unique | list) | list %} {{ target_group + single_not_in_group }}'

Will look into this. Thanks for letting me know.

Could you maybe download the json from the script trace and upload to a website like codepile.net

Here we go: script trace

Hi, I’ve just noticed I’m getting an API error when running the script. It works fine when my other speakers are playing but if music is playing on ‘main_bedroom_speaker’ it plays the TTS but doesn’t resume and give API error. Any ideas what is causing it?

edit: actually it seems other speakers are also doing it now

Hi, could you also upload the json of the trace to codepile.net? I will look into this tomorrow