Script to resume radio (TuneIn) and Spotify after TTS on Google Home speakers

Okay, I should have a trace from a script run when it went wrong.
However, I can see from the previous trace that is is truncated, and that the information I need might not be in it.
I can see the settings (in the variables) you set. Could you tell me what the target for the message is, and which entities are playing, when it does not work properly?

I think I already see it. You did not include the sub_groups variable I created based on your previous posts.

You should inlcude:

    sub_groups:
      media_player.home_group:
        - media_player.living_group
        - media_player.kitchen_group

Both members of the living_group are inlcuded in home_group, and the same applies to kitchen_group.

I can try to create this variable automatically based on the speaker_groups variable, but for now you will have to do this manually.

@tivoo I made some changes to the code in which the players to be resumed are determined.
The sub_groups variable is no longer needed now.
If you update your script with the version on my GitHub page, it should work better now.

1 Like

Apologies it took me a while to revert back.
Indeed, the code was a copy/paste, hence explaining the incorrect indentation. But that is not the problem, as this is correct in my script.yaml file.

Please find my script here: CodePile | Easily Share Piles of Code

Also, to your question, I indeed did not yet had Spotcast installed, but installed in the meantime. However, still no success. Hence, looking forward to know if you see anything weird or missing in the shared script.

Thanks for your time.

Unfortunately also here the script is truncated before it gets interesting :slight_smile:

Some things I can see:

  • The speaker_groups you have set up should match with the speaker groups set up in the Google Home app. I don’t think media_player.spotify_nonkelsue is set up as a member of your beneden_groep in Google Home.
  • If you update to the last version of the script, sub_groups is no longer needed.

In the part I can see, I see that the script had an error: "script_execution": "error", And the error message is "Error rendering data template: Result is not a Dictionary". According to the trace it is in sequence/7 but that is the step in which the TTS is sent. Does it actually send the TTS?
If it does, what is the last step which is performed according to the trace?

Hi, just wanted to say this is a brilliant idea.

Unfortunately I am have an issue with this. I’ve gone through the debug and the issue seems to be that I am not passing a tts_volume (I would like the TTS volume to be whatever the media_player. is set to).

This is the error I am getting, which is generated on this part of the code:

Stopped because an error was encountered at January 2, 2022, 15:08:20 (runtime: 0.04 seconds)
Error rendering data template: TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’

alias: Apply TTS volume
service: media_player.volume_set
target:
  entity_id: '{{ tts_target_list }}'
data:
  volume_level: '{{ tts_volume if tts_volume < 1 else tts_volume / 100 }}'

According to the debug, the tts_volume is being set as:

tts_volume: ‘’

The media player volume is being picked as

volume_old_not_playing:
  - entity_id: media_player.living_room_speaker
    volume_level: 0.05
screen_not_playing: []

I think the TTS is set correctly as per the example. But looks like it is being taken as a string where it defaults to undefined?

    - alias: "TTS"
      service: script.google_home_say
      data:
        voice_tts_target: "{{ tts_target }}"
        tts_message: "{{ tts_message }}"
        tts_volume: "{{ tts_volume if tts_volume is defined else undefined }}"

Really out of my depth here - not sure whats causing the error nor how to fix it.
Thank you in advance.

Hi,
I made a change in how I check if the volume should be set, it should be fixed now if you use the last version on Github.

2 Likes

That fixed it, thank you.
Have to say again, really ingenious solution you came up!

2 Likes

Thanks, and good to hear it’s solved

Giving it a go right now - Excellent share!

Just wanted to report back to you that I am enjoying your script a lot. I got it working flawelessly in my set up! Thank you very much, I’ll keep an eye out on future versions.

1 Like

Wonderful script. Is it possible to make it a blueprint script?

Thanks!

I could look into that, but right now I don’t really see the need for it.
As far as I understand blueprints are for cases where you would reuse code for several scripts/automatons. That is not the case here, because you only need this script. No need to create one per media_player for example.

:+1:

Thanks for the quick answer!
I thought it could simplify the updates of the script.

This looks brilliant - I was really excited to see it but then noticed the discussion on YouTube Music - which is what I use. Did anyone find a solution?

Did a quick search, but it looks like Youtube Music Player is still the only option to use it in Home Assitant, and resuming that requires the stream to be started using that integration.
There is already an example about resuming it on the Github page

1 Like

Thanks - I’ll keep an eye out for new integrations for YouTube music…

Very nice work!

When there is no players_screen defined (I don’t have any) script stops with error.

It would also be very nice to include “night mode” to not bother doing it every time in automations.

Thank you for sharing this amazing script :smiley:

I’m still happily using Assistant Relay (while it still works), but watching this with interest.

Nice work.

1 Like

Will have a look at this, probably tomorrow.

Should be fixed now.