Kodi state not detected

Home Assistant is no longer detecting Kodi’s state. Kodi always shows as ‘off’. I think it has happened after upgrading to 0.76.2.

I have tried a couple of things:

  • Kodi’s web service is enabled on port 8080 and is reachable from a browser.
  • I removed my media_player configuration for Kodi and let autodiscovery do it’s job. Kodi was autodiscovered succesfully but is still showing as ‘off’.
  • Edit: as mentioned in post Kodi not connecting I changed the port for the web service from 8080 to 80. No change :frowning:

What more can I try to fix this? Any help is appreciated!

Can confirm I am seeing the same problem. I know it doesn’t help much, but at least now you know it’s not just you :slight_smile:
Might be worthwhile posting an issue on github.

Thanks for the support. The more the merrier I suppose :slight_smile: I might try raising my first issue on Github then.

I am on 0.77.3 and Kodi states are correctly detected.
Can you access Kodi over your local ip?

What do you mean by ‘over your local ip’? I can see the web interface in a browser on my laptop. Is that what you mean?

should have mentioned I’m on 0.77.3.

And I can ping or access the Kodi player via the web interface but HA still sees it as off. This was working as I have light automations based on the player state that were working.

Do you see any errors in the log? You may want to enable debug logging for the platform (homeassistant.components.media_player.kodi) for the homeasisstant’s logger. That would be the first point to start investigating this.

The platform uses the JSON interface to communicate which is different from the web interface (afaik), so you could try to check what settings you have: https://kodi.wiki/view/JSON-RPC_API#Enabling_JSON-RPC - The state will always be off if it cannot communicate with the device, I think this should be changed to respond “unavailable” though…

Thanks for your information! Will try soon.

The log shows HA is unable to connect to Kodi: connection refused. But what’s next in troubleshooting? In Kodi settings, webservices are enabled, also ‘allow remote control from other devices’. Password is set to kodi/kodi.

This is the log:

2018-09-18 19:23:04 INFO (MainThread) [homeassistant.components.media_player.kodi] Unable to fetch kodi data
2018-09-18 19:23:04 DEBUG (MainThread) [homeassistant.components.media_player.kodi] Unable to fetch kodi data
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 822, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)
File “uvloop/loop.pyx”, line 1881, in create_connection
File “uvloop/loop.pyx”, line 1860, in uvloop.loop.Loop.create_connection
ConnectionRefusedError: [Errno 111] Connection refused

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

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/jsonrpc_async/jsonrpc.py”, line 29, in send_message
response = yield from self._request(data=message.serialize())
File “/usr/local/lib/python3.6/site-packages/aiohttp/client.py”, line 366, in _request
timeout=timeout
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 445, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 757, in _create_connection
req, traces, timeout)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 879, in _create_direct_connection
raise last_exc
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 862, in _create_direct_connection
req=req, client_error=client_error)
File “/usr/local/lib/python3.6/site-packages/aiohttp/connector.py”, line 829, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host xxx.xxx.1.12:8080 ssl:None [Connection refused]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/kodi.py”, line 395, in _get_players
return (yield from self.server.Player.GetActivePlayers())
File “/usr/local/lib/python3.6/site-packages/jsonrpc_async/jsonrpc.py”, line 31, in send_message
raise TransportError(‘Transport Error’, message, exc)
jsonrpc_base.jsonrpc.TransportError: (“Error calling method ‘Player.GetActivePlayers’: Transport Error”, ClientConnectorError(111, ‘Connection refused’))

This is configuration.yaml:

media_player:
  - platform: kodi
    host: Xxx. Xxx.1.12
    enable_websocket: true
    username: kodi
    password: kodi
    turn_on_action:
     - service: wake_on_lan.send_magic_packet
       data:
         mac: xxx
         broadcast_address: Xxx. Xxx.1.255
    turn_off_action:
      - service: media_player.kodi_call_method
        data:
          entity_id: media_player.kodi
          method: System.Shutdown

This indicates that there is no kodi listening on that address (for a reason or another, your settings sound right), or that it’s blocked by a firewall. You could try sudo ss -nlp | grep kodi on the device to see if it is really listening there. 9090 is used for websockets, 8080 for http poll.

Thanks! The command you’re suggesting unfortunately isn’t working for me. I am on Hassio, I believe it doesn’t support sudo. Also ‘ss’ shows ‘command not found’.

On Windows I found a little tool called PortCheck, it shows both port 8080 and 9090 are open on the Kodi machine. I ran this from my laptop, don’t know how I can do this from the Hassio machine.

I just did another reboot of Hassio, different error is popping up in the log:

2018-09-19 19:31:38 INFO (MainThread) [homeassistant.components.media_player.kodi] Unable to fetch kodi data
2018-09-19 19:31:38 DEBUG (MainThread) [homeassistant.components.media_player.kodi] Unable to fetch kodi data
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/kodi.py”, line 395, in _get_players
return (yield from self.server.Player.GetActivePlayers())
File “/usr/local/lib/python3.6/site-packages/jsonrpc_async/jsonrpc.py”, line 34, in send_message
raise TransportError(‘HTTP %d %s’ % (response.status, response.reason), message)
jsonrpc_base.jsonrpc.TransportError: Error calling method ‘Player.GetActivePlayers’: HTTP 401 Unauthorized

Ok, so for some reason it was not running at that point. netstat can be used instead of ss, too, maybe hassio has it.

Anyway, your new log entry shows that it has been able to connect to the endpoint, but is getting Unauthorized (meaning that the username/password is probably false).

Found it. I fixed it by removing the username and password in Kodi, also removed them from HA, then rebooting, after that readded them. I can’t explain why this helped because other apps are using the exact same password to connect to Kodi, and they have been working just fine. But whatever :wink:

Thanks for talking me through it!

2 Likes

Glad that you got it working! If those were indeed working, this sounds like a bug and it would be nice if you could check if there’s already an issue on github, and if no, create one to make the issue known!

Thanks, I’ll give that a try tonight.

Kodi states stop working for me very occasionally, first sign is lights don’t go off when starting a movie, just needs HA restarting and all back to normal.

Thanks @Emphyrio. Your solution worked for me too.

Please create an issue on github (and link it here) for this, so the developers will also know about the issue. This should definitely be fixed.

@teprrr I feel wobbly about raising an issue that I am unable to reproduce. It could be just a one time thing, and I doubt I will see this issue again. Are you sure it is worth the effort trying to spell this out in a Github issue?

Ok, that’s fine. Maybe I misunderstood your description, so did you add the username and the password back into homeassistant’s config after temporary removing them? Or did you get rid of them completely? If the former, then it may have been an extra whitespace which caused the problem. If it works only without a password then it’s obviously a bug to report :slight_smile: