You can test it by checking the attributes of the media player in developer tools > states.
If you then use the service media_player.play_media in developer tools > services with the media_content_id and the media_content_type from the previous step, and that works, the script should work as well.
(1.7.5) Replaces fixed delays with wait templates so there is no unneeded delay in resuming (for example when only a short TTS is sent)
Bug fixes
Added a check if all members of a speaker group are idle or off before resuming the stream to avoid resuming to early (in case a group was playing, but the action causing the interruption was only sent to one of the members) (possible fix for the issue of @bomba23 )
(1.7.5) Fixed retrieving volume for players which were in state off
Thank you very much for you work, I just discovered and implemented your script and it works like a charm!
What I would like to know is how people fix the issue with delayed and cut off TTS messages in groups?!
I have 8 nest mini speakers in one group and when playing TTS messages some always start a bit later and therefore skip the first 1-2 seconds or so. I tried different things like setting the volume for all devices and adding stuff like “@ @ @” before my messages but this is either annoying or doesnt work every time…
Just wanted to let you know I really like your integration. I was thinking how I could solve the problem of the interruption and found your script. Thanks for your work!
UPD: played a bit with the variables. Looks like if I leave the variable empty e.g. players_screen: it breaks.
btw, i am not sure why, but my nest mini takes some time to buffer the radio stream, however the script above speeds it up drastically. So whenever I try to use your calls service it is a long wait before it resumes, with playing my script inside your script makes it way better (or you could potentially add media_play part inside your script.
Could you send a trace of the Resume script (by uploading it to a site like codepile.net). I can use that to determine where the error is caused.
My script uses the same service call as your script, so there should be no delay caused by the script. Did you use the last version, because the versions before could indeed have a short delay.
variables:
players_screen:
speaker_groups:
primary_spotcast: pavel
default_volume_level: 0.25
in the script, which maybe is completely wrong (out of touch with yaml), but I assumed it will see it as empty and will simply continue. After removing these empty variables it works.
About the delay. I am not sure why it happens, but for some reason radio streams are buffering ~20 seconds taking into account I have gigabit internet. I read that some people had this issue on some other radio stations as well and they recommended to use this workaround by adding media_play command explaining it as there is some magic delay between google nest executing cast command and actually playing the sound, thus by forcing it manually fixes the problem. Strange tho. Can you try my script and see if you get a delay or is it instant?
I can’t reproduce this, I can see in the trace where it goes wrong, but with players_screen: null and fixed_picture: null that template renders without issues for me. However I did add additional checks for a value in those variables now, so please give 1.7.6.1 a try (will update topic start after confirmation if this helps)
Regarding the service call, the script uses media_player.play_media. The main difference is that I use the entity_id and not the device_id.
This would have been the service call for resuming in your case, could you check if that works without delay?
service: media_player.play_media
target:
entity_id: media_player.living_room_speaker
data:
media_content_id: https://radiorecord.hostingradio.ru/chillhouse96.aacp
media_content_type: no type
extra:
metadata:
metadataType: 3
title: no title
artist: no artist
I’ve tested this myself in developer tools > services with an entity_id of my own, and it works without delay.
Could you send a trace of script.google_home_resume_perform_resume as well, so I can check if something is going wrong there?
Can you point me where exactly is the updated script? I didn’t find it in the github (checked PRs, branches, forks, commits )
I have tried your service call in a vacuum without any resume scripts and it doesn’t change anything. I still get ~20 sec delay before music starts playing. It is something with the HA itself and how it handles music streams.
I then tried to launch the script you sent, launch TTS with the resume script and I got the same result. It took about 20 seconds to launch the music back. It is not a big deal, i can always incorporate the workaround in the music launch script, but it is strange tho.
I’m not sure what is causing this delay then, for me it starts within a second using the service call I posted above from developer tools > services. But I can add a short delay and the media_player.media_play service call.
Disabled my automation (delayed call to media_player.media_play), tried resume on 1.7.6.2, this error appears:
Logger: homeassistant.core
Source: components/cast/media_player.py:658
First occurred: 4:27:10 PM (1 occurrences)
Last logged: 4:27:10 PM
Error executing service: <ServiceCall media_player.play_media (c:450f2dc30e4abde9f61072971d28e73b): entity_id=['media_player.google_home'], extra=, media_type=audio/mp4, media_id=https://stream......../.......mp3>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 1654, in catch_exceptions
await coro_or_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1673, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 671, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 949, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 708, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 658, in async_play_media
await self.hass.async_add_executor_job(
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.9/site-packages/pychromecast/quick_play.py", line 77, in quick_play
controller.quick_play(**data)
File "/usr/local/lib/python3.9/site-packages/pychromecast/controllers/media.py", line 665, in quick_play
self.play_media(media_id, media_type, **kwargs)
File "/usr/local/lib/python3.9/site-packages/pychromecast/controllers/media.py", line 566, in play_media
raise PyChromecastError()
pychromecast.error.PyChromecastError
Hmm, there seems to be something wrong with a service call for media_player.play_media but I did not make any change to that service call. I only added media_player.media_play.
Are you sure this is caused by the script? Can you use media_player.play_media from developer tools > service with similar arguments without errors?
@TheFes
Ok, 7.6.1 changes are working. Now the script is executing even if I have empty variables. I guess this one is fixed.
However 7.6.2 did nothing. Again, it is not your script problem, but HA acting strange. Like if you say it is instant on your side then it is definitely some HA problem or chromecast. Maybe because I run it as a docker container etc.
Btw, are you using nest mini? Maybe it is nest problem.
7.6.2 should do the same as your script does, so first send the url to stream, and then send a media play command.
It could be that the media player doesn’t show as idle, could you send another trace maybe?