home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.51k stars 30.71k forks source link

HomePod cannot play local media or tts #80419

Closed LukasK13 closed 1 year ago

LukasK13 commented 2 years ago

The problem

I set up my HomePod mini using the Apple TV integration and I am able to control the volume of the HomePod and play/pause music from AppleMusic. However I am unable to play music from Home-Assistant's local media. Furthermore tts is not working as well. When trying to play an audio file (either local music or tts), the following error message is shown.

What version of Home Assistant Core has the issue?

2022.10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Apple TV

Link to integration documentation on our website

https://www.home-assistant.io/integrations/apple_tv/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2022-10-16 11:35:05.142 ERROR (MainThread) [frontend.js.latest.202210100] :0:0 Script error.
2022-10-16 11:35:05.904 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281472971080944] RTSP/1.0 method SETUP failed with code 520: Origin Error
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 202, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1738, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1775, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 207, in handle_service
await service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 678, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 931, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 715, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/apple_tv/media_player.py", line 292, in async_play_media
await self.atv.stream.stream_file(media_id)
File "/usr/local/lib/python3.10/site-packages/pyatv/core/facade.py", line 392, in stream_file
await self.relay("stream_file")(file, **kwargs)
File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/__init__.py", line 352, in stream_file
await client.initialize(self.core.service.properties)
File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/raop.py", line 457, in initialize
await self._setup_session()
File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/raop.py", line 486, in _setup_session
resp = await self.rtsp.setup(
File "/usr/local/lib/python3.10/site-packages/pyatv/support/rtsp.py", line 181, in setup
return await self.exchange("SETUP", headers=headers, body=body)
File "/usr/local/lib/python3.10/site-packages/pyatv/support/rtsp.py", line 265, in exchange
resp = await self.connection.send_and_receive(
File "/usr/local/lib/python3.10/site-packages/pyatv/support/http.py", line 414, in send_and_receive
raise exceptions.HttpError(
pyatv.exceptions.HttpError: RTSP/1.0 method SETUP failed with code 520: Origin Error

Additional information

No response

home-assistant[bot] commented 2 years ago

Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


apple_tv documentation apple_tv source (message by IssueLinks)

momoz commented 2 years ago

Same issue.

momoz commented 1 year ago

any news or updates?

MartinSaaby commented 1 year ago

Same issue

acovaci commented 1 year ago

I am also facing the same issue :(. Manually set the internal_url to use http and using the plain IP, with no luck

ballakers commented 1 year ago

Did you guys add the port 8123 after your internal url? - I just changed from having my URLs specified in yaml to back into the UI (because repairs told me to specify my country lol and yaml mode wasn't working for me) and forgot to add the port and it broke my HomePod TTS but I just added :8123 back to the end of the internal url and TTS is back up and running

LukasK13 commented 1 year ago

Yes, I am using IP + port, still no luck

ILiveInAHouse commented 1 year ago

Same issue

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

golles commented 1 year ago

Also reported in the beta integration: https://github.com/postlund/pyatv/issues/1884

postlund commented 1 year ago

Can someone re-test this once the new release is out?

golles commented 1 year ago

Can someone re-test this once the new release is out?

Hi @postlund, thank you for your efforts to smash this bug! I've just installed the dev docker container and now getting a 400 error:

2023-06-29 21:54:35.226 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139883752632080] RTSP/1.0 method SETUP failed with code 400: Bad Request
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1957, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1997, in _execute_service
    return await cast(
           ^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 833, in entity_service_call
    response_data = task.result()  # pop exception if have
                    ^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1191, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 877, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/media_player.py", line 300, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.11/site-packages/pyatv/core/facade.py", line 370, in stream_file
    await self.relay("stream_file")(
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/__init__.py", line 353, in stream_file
    await client.initialize(self.core.service.properties)
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/stream_client.py", line 375, in initialize
    await self._protocol.setup(self.timing_client.port, self.control_client.port)
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/protocols/airplayv2.py", line 42, in setup
    setup_resp = await self.rtsp.setup(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/rtsp.py", line 176, in setup
    return await self.exchange("SETUP", headers=headers, body=body)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/rtsp.py", line 293, in exchange
    resp = await self.connection.send_and_receive(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/http.py", line 473, in send_and_receive
    raise exceptions.HttpError(
pyatv.exceptions.HttpError: RTSP/1.0 method SETUP failed with code 400: Bad Request

Let me know what I can provide to help you with this!

postlund commented 1 year ago

Can someone re-test this once the new release is out?

Hi @postlund, thank you for your efforts to smash this bug!

I've just installed the dev docker container and now getting a 400 error:


2023-06-29 21:54:35.226 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139883752632080] RTSP/1.0 method SETUP failed with code 400: Bad Request

Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service

    await hass.services.async_call(

  File "/usr/src/homeassistant/homeassistant/core.py", line 1957, in async_call

    response_data = await coro

                    ^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/core.py", line 1997, in _execute_service

    return await cast(

           ^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service

    return await service.entity_service_call(

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 833, in entity_service_call

    response_data = task.result()  # pop exception if have

                    ^^^^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1191, in async_request_call

    return await coro

           ^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 877, in _handle_entity_call

    result = await task

             ^^^^^^^^^^

  File "/usr/src/homeassistant/homeassistant/components/apple_tv/media_player.py", line 300, in async_play_media

    await self.atv.stream.stream_file(media_id)

  File "/usr/local/lib/python3.11/site-packages/pyatv/core/facade.py", line 370, in stream_file

    await self.relay("stream_file")(

  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/__init__.py", line 353, in stream_file

    await client.initialize(self.core.service.properties)

  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/stream_client.py", line 375, in initialize

    await self._protocol.setup(self.timing_client.port, self.control_client.port)

  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/raop/protocols/airplayv2.py", line 42, in setup

    setup_resp = await self.rtsp.setup(

                 ^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/pyatv/support/rtsp.py", line 176, in setup

    return await self.exchange("SETUP", headers=headers, body=body)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/pyatv/support/rtsp.py", line 293, in exchange

    resp = await self.connection.send_and_receive(

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/usr/local/lib/python3.11/site-packages/pyatv/support/http.py", line 473, in send_and_receive

    raise exceptions.HttpError(

pyatv.exceptions.HttpError: RTSP/1.0 method SETUP failed with code 400: Bad Request

Let me know what I can provide to help you with this!

Huh, would not have expected that. Is this with pyatv 0.13.2?

golles commented 1 year ago

Yes

0e1b1d444717:/config# pip show pyatv
Name: pyatv
Version: 0.13.2
Summary: A client library for Apple TV and AirPlay devices
Home-page: https://pyatv.dev
Author: Pierre Ståhl
Author-email: pierre.staahl@gmail.com
License: MIT
Location: /usr/local/lib/python3.11/site-packages
Requires: aiohttp, async-timeout, chacha20poly1305-reuseable, cryptography, ifaddr, mediafile, miniaudio, protobuf, requests, srptools, zeroconf
Required-by: 

0e1b1d444717:/config# pip show homeassistant
Name: homeassistant
Version: 2023.8.0.dev20230629
Summary: Open-source home automation platform running on Python 3.
Home-page: 
Author: 
Author-email: The Home Assistant Authors <hello@home-assistant.io>
License: Apache-2.0
Location: /usr/local/lib/python3.11/site-packages
Editable project location: /usr/src/homeassistant
Requires: aiohttp, astral, async-timeout, atomicwrites-homeassistant, attrs, awesomeversion, bcrypt, certifi, ciso8601, cryptography, home-assistant-bluetooth, httpx, ifaddr, Jinja2, lru-dict, orjson, pip, PyJWT, pyOpenSSL, python-slugify, PyYAML, requests, typing-extensions, ulid-transform, voluptuous, voluptuous-serialize, yarl
Required-by: 
RedNo7 commented 1 year ago

Did you guys add the port 8123 after your internal url? - I just changed from having my URLs specified in yaml to back into the UI (because repairs told me to specify my country lol and yaml mode wasn't working for me) and forgot to add the port and it broke my HomePod TTS but I just added :8123 back to the end of the internal url and TTS is back up and running

I've just setup my HomePod with the UI and unable to play local media either. Core 2023.7.2

edit: I should add TTS works (after a significant delay)

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.