I’m using Google Cloud TTS, check the TTS service call to make sure this matches your setup. It could be that your TTS service also requires service data like language (lines 265 - 269 in the script).
But I’m also planning to put the TTS-service in a variable, to make it more easy to change it.
Thanks, this now works correctly. Only thing I am running into now is that if my google hub is not playing anything, the volume is set to default (=0.25) instead of the old volume. Any idea where this issue is caused and what I should change?
Thanks, I will try. The only thing still bothering me is the sound each google device makes if it was in the off state. Not sure however if this can be solved when you want to return to the old volume.
Love this script and implemnted it in my set-up.
Did find a bug though. Not sure if it’s an Spotify API issue, but while playing a podcast, I got an error:
Executed: 1 december 2021 10:01:34
Error: TypeError: 'NoneType' object is not iterable
With the following being feed back from Spotify API:
players_to_resume:
- entity_id: media_player.living_group
media_content_id: spotify:episode:4lJrP8lm5uULHjzQTwuUSW
media_title: 'Daan Roosegaarde: kunst als redmiddel voor de toekomst?'
media_artist: NRC Future Affairs
media_content_type: no type
app_name: Spotify
entity_picture: https://i.scdn.co/image/ab6765630000ba8a83a356a105529f1eee416986
volume_level: 0.49
As you can see it does not hold a media_type and thus the script fails to run.
Also I found the script not resuming the music on the correct speaker group, although I have defined them in the script. What happens when playing music on media_player.living_group, the automation first resumes on living_room_speaker and then switches to office_speaker.
- service: script.google_home_say
data:
tts_message: Hello, you left the fridge door open!
tts_target:
- media_player.home_group
tts_volume: 40
speaker_group_split: false
Could you set debug: True and post the output from the debug log action in the script (you can eiter copy it from the log if your log level is set to info, or copy it from the script trace).
The part you posted seems to be the players_to_resume variable from the script. Why should the Spotify API return this? However, the media_content_type should return music. But for Spotify this should not be relevant, as it just uses the spotcast service, and only uses the app_name to determine if Spotify was playing.
Could you also show a screenshot of the trace, or let me know in which action the script stopped because of this error (as shown in the trace).
If you want, you can also send me a direct message, or find me on Discord (same username). We can talk in Dutch then
Also I found the script not resuming the music on the correct speaker group, although I have defined them in the script. What happens when playing music on media_player.living_group, the automation first resumes on living_room_speaker and then switches to office_speaker.
This is fixed now
Executed: 1 december 2021 10:01:34
Error: TypeError: ‘NoneType’ object is not iterable
And I think this is solved as well, however it was not related to Spotify.
Thanks for the fix I check out the revisions and copied your new script. Checked if the error appeared again with a different podcast on Spotify and seems to be working fine!
However, the bug off not resuming music to correct speaker group still seems to be apparent. I have added the full trace file below for you reference.
It determines that those two speakers should be resumed, where that should be the speaker group.
I think I did not take into account your use case where you send the tts to the house group, in which a speaker group is playing. I will do some tests.
Should be fixed now, see the changelog in the start post.
An additional variable sub_groups has been added, and the template to determine which entities to resume has been changed to take these sub_groups into account.
Was hoping that this was the solution I needed, however too confusing for me as newbie to understand what part needs to go where (configuration.yaml, scripts.yaml, GUI, etc…)…
But for further answers I need to know how you are planning to use it. Do you want to use it in automations? Or do you want to have it on your dashboard?
I’m absolutely loving this script, however only managing to get it to work about 25% of the time.
Not entirely sure if my use-case is just bizarre, but I keep getting errors. I’ll keep an eye on your updates, and after digging some more, I’ll pester you with some logs
Thanks for sharing this with us - can’t believe it’s not something already built into the default media players/tts!
The indentation of your code is incorrect. Is this because of your copy/paste or is it like this in your script.yaml? Becasue in that case that could explain some issues.
Could you go to Configuraton > Automations & Scenes (assuming you are on HA 2021.12) > Scripts
Then find the Google Home Say script on this page, and press the debug button (the one with the clock and the arrow around it).
In the trace, there is a download button. Can you share that with me (maybe not in a post here, share the contents on something like https://www.codepile.net/)
Last check, did you install spotcast, and is it working?
So I have tested your latest script but somehow it still resumes the music on one of the speakers in the group first and then it stops on that device because it then starts on another speaker in that group.
I did put in every speaker separately in the automation, script from sequence: onwards is an exact copy from yours. My automation is:
alias: Fridge Door Left Open
description: Alert to notify the fridge door is left open for 1 minute, repeat until closed
trigger:
- platform: state
entity_id: binary_sensor.aqara_fridge_sensor_contact
from: 'off'
to: 'on'
for:
hours: 0
minutes: 1
seconds: 0
condition: []
action:
- repeat:
until:
- condition: state
entity_id: binary_sensor.aqara_fridge_sensor_contact
state: 'off'
sequence:
- service: notify.mobile_app_oneplus_a5000
data:
message: You left my door open!
title: The Fridge
- service: script.google_home_say
data:
tts_message: Hello, you left the fridge door open!
tts_target:
- media_player.living_room_speaker
- media_player.office_speaker
- media_player.kitchen_speaker
tts_volume: 35
restore_volume_all: true
speaker_group_split: false
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
mode: single
max: 10
Could you upload the trace for script.google_home_say to pastebin like you did last time?
Of course I need a script run when the resuming part did not properly work.
Edit: I can see that was when it triggered but nothing was playing on my speakers. Will manually trigger one when I get home while Spotify is playing on my speakers.