Strange behaviour - Kodi connection refused reported

Since migrating to 0.115 I am having problems with Kodi controls. Integrations has successfully detected my Kodi device but HASS is doing some very weird things.

If I restart HASS I get the following error in the log…

Log Details (ERROR)
Logger: homeassistant.components.kodi.config_flow
Source: components/kodi/config_flow.py:51
Integration: Kodi (documentation, issues)
First occurred: 18:16:31 (1 occurrences)
Last logged: 18:16:31

Cannot connect to Kodi
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 936, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 1025, in create_connection
raise exceptions[0]
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 1010, in create_connection
sock = await self._connect_sock(
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 924, in _connect_sock
await self.sock_connect(sock, address)
File “/usr/local/lib/python3.8/asyncio/selector_events.py”, line 494, in sock_connect
return await fut
File “/usr/local/lib/python3.8/asyncio/selector_events.py”, line 526, in _sock_connect_cb
raise OSError(err, f’Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed (‘192.168.1.115’, 8080)

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

Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/jsonrpc_async/jsonrpc.py”, line 32, in send_message
response = await self._request(data=message.serialize())
File “/usr/local/lib/python3.8/site-packages/aiohttp/client.py”, line 480, in _request
conn = await self._connector.connect(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 858, in _create_connection
_, proto = await self._create_direct_connection(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 1004, in _create_direct_connection
raise last_exc
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 980, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 943, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.1.115:8080 ssl:default [Connect call failed (‘192.168.1.115’, 8080)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/pykodi/kodi.py”, line 161, in ping
response = await self._server.JSONRPC.Ping()
File “/usr/local/lib/python3.8/site-packages/jsonrpc_async/jsonrpc.py”, line 34, in send_message
raise TransportError(‘Transport Error’, message, exc)
jsonrpc_base.jsonrpc.TransportError: (“Error calling method ‘JSONRPC.Ping’: Transport Error”, ClientConnectorError(ConnectionKey(host=‘192.168.1.115’, port=8080, is_ssl=False, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=269936207), ConnectionRefusedError(111, “Connect call failed (‘192.168.1.115’, 8080)”)))

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

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 49, in validate_http
await kodi.ping()
File “/usr/local/lib/python3.8/site-packages/pykodi/kodi.py”, line 167, in ping
raise CannotConnectError from error
pykodi.kodi.CannotConnectError

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

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 220, in async_step_import
await validate_http(self.hass, data)
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 51, in validate_http
raise CannotConnect from error
homeassistant.components.kodi.config_flow.CannotConnect
Home Assistant has started!

OK so the port on Kodi @ 192.168.1.115 is actually 9090 I can prove this because I can connect to Kodi OK using browser to http://192.168.1.115:9090;

Lets change it (on kodi) to 8080 (I can now connect to kodi OK using browser to http://192.168.1.115:8080)

Do nothing to HASS except restart.

I now get the following error in the log (having never touched HASS Settings at all):

Logger: homeassistant.components.kodi.config_flow
Source: components/kodi/config_flow.py:82
Integration: Kodi (documentation, issues)
First occurred: 18:24:01 (1 occurrences)
Last logged: 18:24:01

Unexpected exception
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 936, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 1025, in create_connection
raise exceptions[0]
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 1010, in create_connection
sock = await self._connect_sock(
File “/usr/local/lib/python3.8/asyncio/base_events.py”, line 924, in _connect_sock
await self.sock_connect(sock, address)
File “/usr/local/lib/python3.8/asyncio/selector_events.py”, line 494, in sock_connect
return await fut
File “/usr/local/lib/python3.8/asyncio/selector_events.py”, line 526, in _sock_connect_cb
raise OSError(err, f’Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed (‘192.168.1.115’, 9090)

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

Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/jsonrpc_websocket/jsonrpc.py”, line 56, in ws_connect
self._client = await self.session.ws_connect(
File “/usr/local/lib/python3.8/site-packages/aiohttp/client.py”, line 721, in _ws_connect
resp = await self.request(method, url,
File “/usr/local/lib/python3.8/site-packages/aiohttp/client.py”, line 480, in _request
conn = await self._connector.connect(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 858, in _create_connection
_, proto = await self._create_direct_connection(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 1004, in _create_direct_connection
raise last_exc
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 980, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File “/usr/local/lib/python3.8/site-packages/aiohttp/connector.py”, line 943, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.1.115:9090 ssl:default [Connect call failed (‘192.168.1.115’, 9090)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/pykodi/kodi.py”, line 135, in connect
await self._ws_server.ws_connect()
File “/usr/local/lib/python3.8/site-packages/jsonrpc_websocket/jsonrpc.py”, line 59, in ws_connect
raise TransportError(‘Error connecting to server’, None, exc)
jsonrpc_base.jsonrpc.TransportError: (‘Error connecting to server’, ClientConnectorError(ConnectionKey(host=‘192.168.1.115’, port=9090, is_ssl=False, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=1902911753), ConnectionRefusedError(111, “Connect call failed (‘192.168.1.115’, 9090)”)))

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

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 75, in validate_ws
await kwc.connect()
File “/usr/local/lib/python3.8/site-packages/pykodi/kodi.py”, line 137, in connect
raise CannotConnectError from error
pykodi.kodi.CannotConnectError

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

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 221, in async_step_import
await validate_ws(self.hass, data)
File “/usr/src/homeassistant/homeassistant/components/kodi/config_flow.py”, line 82, in validate_ws
raise WSCannotConnect from error
homeassistant.components.kodi.config_flow.WSCannotConnect

Any help on this gratefully received!

Have you deleted your Kodi yaml configuration?

Even though my yaml configuration was imported into integrations home assistant still “discovered” my two Kodi boxes again after I deleted my yaml and restarted. :roll_eyes:

So I deleted all four of the Kodi integrations (two duplicates), restarted and added and configured the 2 newly discovered integrations.

Been running well since.

@tom_l, thanks for the reply.

I’m not entirely sure what is meant by Kodi yaml configuration? I have some configs for kodi as a media_player… is this what is meant my this? (sorry for being a dummy)

My setup is Here

That is exactly what I meant. It is no longer required now that the Kodi integration is set up via the UI.

@tom_l. This fixed it (I also upgraded to 115.2). Thanks for your help.

I also ended up with duplicates! (I just ignored them). :crazy_face:

I guess the documentation needs to be updated “The preferred way to set up the Kodi platform is by through discovery” should be changed to “The only way to set up the Kodi platform is by through discovery” it is, after all, what they mean :laughing:

1 Like