Good afternoon,
I am running home assistant core 2024.3.1. My initial implementation was with HassOS on a Raspberry Pi 4. I am using various SONOS speakers as media players.
I am trying to run the following script, which is part of a much larger script, but I have narrowed my issue down to this piece
alias: Testing
sequence:
- service: media_player.play_media
target:
entity_id: media_player.den
data:
media_content_id: >-
media-source://tts/amazon_polly?message= Good day sunshine. It is now
{{now().strftime('%-H %M on %A %-d %B %Y')}}
media_content_type: music
mode: single
When I run the script for the first time I get a message “Triggered Testing” but there is no output to the media player. Looking through the log files the following is generated
Logger: homeassistant
Source: components/tts/legacy.py:244
First occurred: 13:34:29 (1 occurrences)
Last logged: 13:34:29
Error doing job: Exception in callback SpeechManager._async_get_tts_audio.<locals>.handle_error(<Task cancell...nit__.py:691>>) at /usr/src/homeassistant/homeassistant/components/tts/__init__.py:757
Traceback (most recent call last):
File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 759, in handle_error
if audio_task.exception():
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 697, in get_tts_data
extension, data = await engine_instance.async_get_tts_audio(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/tts/legacy.py", line 244, in async_get_tts_audio
return await self.hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError
Looking at the trace files it shows all is in order.
This is where it gets weird. If I run the same script again it works perfectly. And will continue running perfectly until I leave it for about 3 hours, when it will again not work for the first iteration, but will continue working after that.
As a test I added a notification immediately before the play media sequence, and the notification was created, but not the play media part. I have also added additional play media sequences before and after this piece, and they will execute correctly, but not this particular one.
I have also tried
alias: Testing
variables:
sunrise: >-
{% set ynow = now().strftime('%-H %M on %A %-d %B %Y') %} Good day sunshine. It is now {{ ynow }}
sequence:
- service: media_player.play_media
target:
entity_id: media_player.den
data:
media_content_id: >-
media-source://tts/amazon_polly?message= {{ sunrise }}
media_content_type: music
mode: single
with the same results.
For what its worth the actual issues lies in the now() call. The good day sunshine and the strftime() are there to make it more palatable.
I have the same response from any of my media players.
Please can someone help me figure out what is going on and why my script will not work properly on the first iteration.
Thank you,
Mark