georgezhao2010/apple_airplayer

Cannot connect to host

kaffolder7 opened this issue · 3 comments

Was excited to stumble across this custom integration. I am trying to get this to work. Followed your README documentation, but am still having issues with getting this to function via the tts.cloud_say service. Seems like the TTS side of things is working—I can confirm that my media file is being generated. However, when I presume this component goes to play the MP3 file over my HomePod mini, it logs the following error to my HA logs:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/apple_airplayer/media_player.py:110
Integration: Apple AirPlayer (documentation, issues)
First occurred: 3:16:16 PM (1 occurrences)
Last logged: 3:16:16 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 865, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/resolver.py", line 31, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 856, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/apple_airplayer/media_player.py", line 110, in async_play_stream
    r = await session.get(url)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1011, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host hasspi.local:8123 ssl:default [Name does not resolve]

It seems like the issue is that there is a connection issue between my HomePod mini and HA URL ("hasspi.local:8123")? Could you provide a little more clarity/direction on how to get this integration added to HA? I have tried this from both my internal URL (http://hasspi.local:8123) and also from my public Nabu Casa external URL (https://g4xwh71234567890.ui.nabu.casa/) <- obfuscated for security.

Thank you so much for your work on this and any help/suggestions you may provide!

Did you add the integration to HA or it couldn't work after added to HA?

  1. When you added integration, that will search and added HomePod automatically in networks. You could complete the steps easily following the instruction.
  2. If you have added, try to connect the HA with IP address rather than URL.
  3. Try to set base_url in configuration.yaml, eg. base_url: http://hasspi.local:8123

I have the same issue as @kyleaffolder.

I added the repo in HACS and added the integration in HA. It found both of my HomePods successfully. If I try to send a TTS-message I get the same exception mentioned above.

As suggested from @georgezhao2010 I tried to connect to HA via IP, but the error is still the same. The option set_url is no longer available (see e.g. here. But even if I put my urls inside internal and external url the error will remain.

Any idea what to try next? Could it be an issue with 2 factor auth?

I was having this same issue but after seeing @georgezhao2010's suggestions I was finally able to get it to work. Since I have most stuff set up via the GUI I went to Configuration -> Settings -> General -> Internal URL and changed that from http://homeassistant.local:8123 to http://192.168.1.24:8123 and saved. Obviously, you'll need to use the IP address of the device running HA for you but that's all it took to fix this same error message that I was getting.