music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.36k stars 52 forks source link

TTS to sonos group fails. #2122

Closed HA-TB303 closed 4 months ago

HA-TB303 commented 6 months ago

What version of Music Assistant has the issue?

2.0.0b136

What version of the Home Assistant Integration have you got installed?

2024.4.3

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

When casting to a Sonos group created in MASS tts fails.

How to reproduce

  1. Create a Sonos group: CleanShot 2024-04-14 at 14 54 07

  2. Verify if it exists: CleanShot 2024-04-14 at 14 54 55

  3. Verify if music can be played to it: CleanShot 2024-04-14 at 14 55 29

This works...

  1. Verify if I can tts to it: CleanShot 2024-04-14 at 14 56 42

This fails..

Music Providers

n/a

Player Providers

Sonos

Full log output

Logger: homeassistant.components.websocket_api.http.connection
Bron: custom_components/mass/media_player.py:485
integratie: Home Assistant WebSocket API (documentatie, problemen)
Eerst voorgekomen: 14:43:37 (3 gebeurtenissen)
Laatst gelogd: 14:56:43

[139944312487744] Error handling message: Unknown error (unknown_error) Michel from 192.168.207.5 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 794, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1713, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 457, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 509, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 539, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 507, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tts/legacy.py", line 159, in async_say_handle
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/mass/media_player.py", line 438, in async_play_media
    await self._async_play_media_advanced(
  File "/config/custom_components/mass/media_player.py", line 485, in _async_play_media_advanced
    await self.mass.players.play_announcement(
  File "/usr/local/lib/python3.12/site-packages/music_assistant/client/players.py", line 132, in play_announcement
    await self.client.send_command(
  File "/usr/local/lib/python3.12/site-packages/music_assistant/client/client.py", line 174, in send_command
    return await future
           ^^^^^^^^^^^^
music_assistant.common.models.errors.MusicAssistantError: unhandled errors in a TaskGroup (1 sub-exception)

Full mass log:

2024-04-14 15:05:14.185 INFO (MainThread) [music_assistant] Starting Music Assistant Server (97c669c8181e403e8354929b295df38f) version 2.0.0b136 - HA add-on: True
2024-04-14 15:05:14.190 INFO (MainThread) [music_assistant.cache] Initializing cache controller...
2024-04-14 15:05:14.195 INFO (MainThread) [music_assistant.webserver] Starting server on  0.0.0.0:8095 - base url: http://192.168.207.101:8095
2024-04-14 15:05:14.211 INFO (MainThread) [music_assistant.music] Using a sync interval of 77 minutes.
2024-04-14 15:05:14.376 INFO (MainThread) [music_assistant.streams] Detected ffmpeg version 6.0.1 with libsoxr support
2024-04-14 15:05:14.376 INFO (MainThread) [music_assistant.streams] Starting server on  0.0.0.0:8098 - base url: http://192.168.207.101:8098
2024-04-14 15:05:14.662 INFO (MainThread) [music_assistant] Loaded metadata provider TheAudioDB Metadata provider
2024-04-14 15:05:14.662 INFO (MainThread) [music_assistant] Loaded metadata provider fanart.tv Metadata provider
2024-04-14 15:05:14.662 INFO (MainThread) [music_assistant] Loaded metadata provider MusicBrainz Metadata provider
2024-04-14 15:05:14.662 INFO (MainThread) [music_assistant] Loaded music provider URL
2024-04-14 15:05:14.662 INFO (MainThread) [music_assistant.music] Sync task for URL completed
2024-04-14 15:05:14.709 INFO (MainThread) [music_assistant] Loaded player provider SONOS
2024-04-14 15:05:14.713 INFO (MainThread) [music_assistant] Loaded plugin provider Home Assistant
2024-04-14 15:05:14.872 INFO (MainThread) [music_assistant] Loaded music provider RadioBrowser
2024-04-14 15:05:14.873 INFO (MainThread) [music_assistant.music] Sync task for RadioBrowser completed
2024-04-14 15:05:15.359 INFO (MainThread) [music_assistant.providers.spotify] Successfully logged in to Spotify as xxxxx
2024-04-14 15:05:15.359 INFO (MainThread) [music_assistant] Loaded music provider Spotify xxxxxxx
2024-04-14 15:05:18.016 INFO (MainThread) [music_assistant.players] Player registered: RINCON_C4387502BEAA01400/Keuken
2024-04-14 15:05:18.017 INFO (MainThread) [music_assistant.players] Player registered: syncgroup_myqrjkxc/Groep - beneden
2024-04-14 15:05:18.019 WARNING (MainThread) [soco.events_asyncio] Could not bind to 192.168.207.101:1400: [Errno 98] Address already in use
2024-04-14 15:05:18.127 INFO (MainThread) [music_assistant.players] Player registered: RINCON_C43875E1AE2401400/Kantoor
2024-04-14 15:05:18.195 INFO (MainThread) [music_assistant.players] Player registered: RINCON_38420B4BEB0901400/Woonkamer
2024-04-14 15:05:18.256 INFO (MainThread) [music_assistant.providers.spotify] Successfully logged in to Spotify as xxxxxxxx
2024-04-14 15:05:18.256 INFO (MainThread) [music_assistant] Loaded music provider Spotify xxxxx
2024-04-14 15:05:19.259 INFO (MainThread) [music_assistant.providers.spotify] Successfully logged in to Spotify as xxxxxxxx
2024-04-14 15:05:19.259 INFO (MainThread) [music_assistant] Loaded music provider Spotify xxxxxx
2024-04-14 15:05:21.411 INFO (MainThread) [music_assistant.music] Sync task for Spotify xxxxxxx completed
2024-04-14 15:05:41.551 INFO (MainThread) [music_assistant.music] Sync task for Spotify xxxxxx completed
2024-04-14 15:05:45.999 WARNING (MainThread) [music_assistant.music] Sync task for Spotify xxxxx completed with errors
2024-04-14 15:06:00.031 WARNING (MainThread) [music_assistant.players] Detected announcement request to an inactive playergroup, while one or more individual players are playing. This announcement will be redirected to the individual players.
2024-04-14 15:06:00.031 INFO (MainThread) [music_assistant.players] Playback announcement to player Woonkamer (with pre-announce: False): http://192.168.207.101:8123/api/tts_proxy/afa6c8b3a2fae95785dc7d9685a57835d703ac88_nl-nl_6e8b81ac47_cloud.mp3
2024-04-14 15:06:00.031 INFO (MainThread) [music_assistant.players] Playback announcement to player Keuken (with pre-announce: False): http://192.168.207.101:8123/api/tts_proxy/afa6c8b3a2fae95785dc7d9685a57835d703ac88_nl-nl_6e8b81ac47_cloud.mp3
2024-04-14 15:06:00.031 INFO (MainThread) [music_assistant.players] Playback announcement to player Kantoor (with pre-announce: False): http://192.168.207.101:8123/api/tts_proxy/afa6c8b3a2fae95785dc7d9685a57835d703ac88_nl-nl_6e8b81ac47_cloud.mp3
2024-04-14 15:06:00.032 ERROR (MainThread) [music_assistant.webserver] Error handling message: players/cmd/play_announcement: unhandled errors in a TaskGroup (1 sub-exception)

Additional information

Tried other tts servies, same result...

What version of Home Assistant Core are your running

2024.4.3

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

Generic x86-64 (e.g. Intel NUC)

marcelveldt commented 6 months ago

Is this a gen2 or gen 1 sonos device ?

HA-TB303 commented 6 months ago

Gen2 sonos arc, move 2, era 100, era300 and 1 roam

marcelveldt commented 6 months ago

OK, looks like one of the players denied the request - I assume some of the players actually played the message ?

HA-TB303 commented 6 months ago

No, none of the speakers played the message. When i cast music to the same group, that does work on all speakers.

OzGav commented 5 months ago

@HA-TB303 Can you recheck with the latest betas just to confirm there hasn't been any change in behaviour

HA-TB303 commented 5 months ago

Hi, no it still does not work. I also still have trouble getting all my Sonos speakers working within MA (some are found found but are marked with an hourglass) even though they work in HA and in the Sonos app. If I create a new group that contains available speakers only (in this case 'Keuken' en 'Kantoor'), it works most of the time, but that is just not usable, since some speakers are battery powered and thus not always connected to the network.

In MA: CleanShot 2024-05-08 at 10 50 40 in HA: CleanShot 2024-05-08 at 10 51 20

HA: 2024.5.2 Supervisor: 2024.05.1 OS: 12.2 MA addon: 2.0.0b147 ( MA integration: 2024.5.0

OzGav commented 5 months ago

Thanks it will be investigated in due course

vijexa commented 5 months ago

Hi! I've also encountered this when I updated from b144 to 2.0.0. I have a sonos group made up of 3 symfonisk gen 2 and 1 era 100. I don't see any errors in logs though, the TTS just doesn't work. It also doesn't work when I target individual player entities exported by music assistant (but works when I target player entities from HA sonos integration). When I restored b144 from backup it started to work again.

marcelveldt commented 4 months ago

Just tested this with the current version (2.0.6) and its working fine - can someone confirm that the issue is resolved ?

OzGav commented 4 months ago

@HA-TB303 @vijexa Can one of you heck if this is still an issue?

HA-TB303 commented 4 months ago

Wow, great!

This:

service: mass.play_announcement
data:
  use_pre_announce: true
  announce_volume: 35
  url: http://192.168.207.101:8123/local/audio/sire_er_is_post_voor.mp3
target:
  entity_id: media_player.sonos_beneden

and this:

service: tts.cloud_say
data:
  entity_id: media_player.sonos_beneden
  message: Dit is een test.

Work great!

Just this doesn't, but might be unrelated as it also does not work for just one speaker. I took this example from the docs.

service: mass.play_media
data:
  media_type: track
  media_id: Queen - Innuendo
target:
  entity_id: media_player.sonos_beneden

https://music-assistant.io/faq/massplaymedia/

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 977, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/mass/media_player.py", line 438, in _async_play_media_advanced
    media_type=media_type,
               ^^^^^^^^^^^
  File "/config/custom_components/mass/media_player.py", line 500, in _get_item_by_name
    )

  File "/usr/local/lib/python3.12/site-packages/music_assistant/client/music.py", line 199, in get_library_artists
    return PagedItems.parse(
           ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/common/models/media_items.py", line 620, in parse
    items=[item_type.from_dict(x) for x in raw["items"]],
                                           ~~~^^^^^^^^^
TypeError: list indices must be integers or slices, not str
marcelveldt commented 4 months ago

I also found an issue in the HA integration. Can you check the HA integration update 2036.6.2 ?

HA-TB303 commented 4 months ago

I tested all three service calls using versions 2.0.7 and 2024.6.2, and everything works great now!

You all did fantastic work on this! I will start using this in 'production' now, and if anything comes up, I'll report it.

Thanks again!