Cannot start HA when specifying Kodi media player

Hi,

I’m trying to connect HA to Kodi (Isengard) but am not able to do so successfully.

In my configuration I’ve added:

media_player:
  - platform: kodi
    host: http://192.168.178.44
    port: 9090
    user: kodi
    password: kodi

When I start HA it get stuck when trying to connect:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 192.168.178.44

If I then kill the process I get this stack trace:

^CTraceback (most recent call last):
  File "/Users/shoekstra/hass/bin/hass", line 11, in <module>
    sys.exit(main())
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/__main__.py", line 330, in main
    exit_code = setup_and_run_hass(config_dir, args)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/__main__.py", line 247, in setup_and_run_hass
    log_rotate_days=args.log_rotate_days)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/bootstrap.py", line 313, in from_config_file
    skip_pip=skip_pip)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/bootstrap.py", line 282, in from_config_dict
    _setup_component(hass, domain, config)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/bootstrap.py", line 156, in _setup_component
    result = component.setup(hass, config)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/components/media_player/__init__.py", line 289, in setup
    component.setup(config)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 53, in setup
    self._setup_platform(p_type, p_config)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 98, in _setup_platform
    discovery_info)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/components/media_player/kodi.py", line 40, in setup_platform
    turn_off_action=config.get('turn_off_action', 'none')),
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/components/media_player/kodi.py", line 62, in __init__
    self.update()
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/components/media_player/kodi.py", line 96, in update
    self._players = self._get_players()
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/homeassistant/components/media_player/kodi.py", line 73, in _get_players
    return self._server.Player.GetActivePlayers()
  File "/Users/shoekstra/git/shoekstra/home-assistant-config/deps/jsonrpc_requests/jsonrpc.py", line 112, in __call__
    return self.__request_method(self.__method_name, args, kwargs)
  File "/Users/shoekstra/git/shoekstra/home-assistant-config/deps/jsonrpc_requests/jsonrpc.py", line 96, in __request
    return self.send_request(method_name, is_notification, args or kwargs)
  File "/Users/shoekstra/git/shoekstra/home-assistant-config/deps/jsonrpc_requests/jsonrpc.py", line 37, in send_request
    response = self.request(data=request_body)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/sessions.py", line 617, in send
    r.content
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/models.py", line 741, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/models.py", line 664, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/packages/urllib3/response.py", line 353, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/Users/shoekstra/hass/lib/python3.5/site-packages/requests/packages/urllib3/response.py", line 310, in read
    data = self._fp.read(amt)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 448, in read
    n = self.readinto(b)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 488, in readinto
    n = self.fp.readinto(b)
  File "/usr/local/Cellar/python3/3.5.2/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
KeyboardInterrupt

What is strange is if I change the IP in my configuration to something that is not reachable, HA starts normally and then I see this in the error log (which is expected):

16-07-31 17:08:10 homeassistant.components.media_player.kodi: Unable to fetch kodi data

I’ve looked at a few examples and don’t think I’m doing anything wrong. I’ve tried removing the http:// prefix from the address which results in the above message in error log (and HA starts as normal) so at this time I am stumped.

Any pointers would be appreciated.

Stephen

your format does not look right.

remove the “-” from platform and remove the extra spaces from the other lines, use only 2 spaces for each line after “media_player”

As I understand it JSON-RPC on Kodi uses 2 different ports for 2 different purposes 8080 and 9090.

  1. 8080 uses the HTTP protocol and uses HTTP headers with a JSON payload and you get back a single JSON response.
  2. 9090 is a raw TCP socket where you send just the JSON text and you can receive responses asynchronously not just for the message you sent but also other notifications Kodi sends out…

I think Home Assistant uses the HTTP transport and so you should probably be using port 8080.

This has been solved. I was using the tcp transport port and not the HTTP transport - nooby error :frowning:

I thought because the Kodi Remote was working HA should’ve worked, but turns out they use different transports as sffjunkie pointed out.