Home Assistant release with the issue: 0.79.3
Last working Home Assistant release (if known): Unknown
Operating environment (Hass.io/Docker/Windows/etc.): Docker
Component/platform: https://www.home-assistant.io/components/media_player.kodi/
Description of problem:
When Kodi is restarted, the connection from HA to Kodi doesn't re-establish. The only way to get HA to receive status changes is by restarting HA.
Problem-relevant configuration.yaml
entries and (fill out even if it seems unimportant):
media_player:
- platform: kodi
name: Main Kodi
host: 192.168.7.61
port: 80
username: kodi
password: ********
Traceback (if applicable):
Additional information:
Do other network based Kodi remotes and Kodi's web interface still work as usual? I have seen occurrences where Kodi did not properly release the network port when exiting, so it could not rebind the port on startup.
Yes. I can still connect to the normal web-page of Kodi, use Maraschino and using Yatse (Android). It is only HA that doesn't get updated any more, until I restart HA.
Thank you for rising this issue @Xaldimo. I also have the same problem, and can confirm that all other applications that connect to Kodi resume function when the system is restored/unsuspended. Yaste on my Android device is an example.
So what's likely happening to Home Assistant (HA) is the following:
Possible solution: have HA check to see if the Kodi system is up and re-connect every X seconds (conf option)?
Doesn't hass detect that the websocket gets disconnected? Normally it should not poll.
Isn't this the same as reconnecting to a hue bridge or a Chromecast that rebooted?
Haha there it is again. This gosh darn issue that has existed since... forever.
I actually tried fixing it a few times but I just cant figure out where the issue is.
The component itself looks like (to me at least) would properly handle the connection.
Also, it's not like HA can't connect with kodi again.
If your kodi system is back online while HA shows it as being offline, hit the power on button and you'll most likely see the component updating.
The most recent idea I had revolves around the should_poll property.
Does the property itself get polled or is it check once (on startup)?
If only once, this would explain a lot.
If your kodi instances was already online while HA starts, HA would never ever again trigger a update -> not reconnecting the socket.
If kodi was offline however, HA would eventually update the component, forcing the socket to reestablish.
I'm just super not familiar with HAs internals and don't really have the time to do lots of debugging etc.
Sorry for the wall of text :)
The problem is that there is no power button. I have just rebooted Kodi, while HA is still up and running. HA now shows:
It doesn't show any power button. The only way I can find to get HA to sync again is to restart HA.
@Xaldimo because you did not configure a kodi turn on/off action
@tadly you are right :) I have now enable the turn on mechanism, and it does create a new socket to Kodi. But I feel this is more of a work around then a proper fix. My Kodi is running 24/7 and only if I upgrade routers/switches or if Kodi gets upgraded it will go down. But that means if that happens (my routers/switches get upgraded automatic) I will need to go into HA to trigger a turn-on for Kodi. Then my automation in regards to lights triggered by Kodi will work again.
I would have expected that HA would keep trying to establish a connection to Kodi until it is successful.
I never said it's not a workaround.
I even said I tried fixing it a few times already but failed.
Anyways, for you rebooting kodi while HA is running reliably recreates the issue?
If so, would you be comfortable enough to change a small piece of code with your HA installation and test again?
@tadly sorry if it came across in the wrong way. Didn't mean it that way :)
I would be gladly to test a piece of code. I tried going through it but haven't done any coding myself for few decades so am very rusty with it.
I have done the following:
This seems to work :)
I don't really like the fix but it certainly is better than what we have now (a 50/50 chance).
I'll make a PR for it.
@Xaldimo would you be so kind and do another test? I did a few tweaks...
This time you're better of just downloading the file:
https://raw.githubusercontent.com/tadly/home-assistant/dev/homeassistant/components/media_player/kodi.py
There aren't to many changes as you can see here but downloading it should be way easier.
I have used the new version of kodi.py, and it seems to still behave as expected:
I have repeated steps 4-6 again to make sure it does as expected, and both times HA seems to re-establish the link to Kodi :smiley:
Perfect. Thanks again for testing.
Doesn't look like it's getting merged as of now but I'll see if we can come up with a proper solution.
Thanks for the work you put into this tadly! I'm excited to test this when I get home from work.
So it does indeed seem like HA only attempts to connect to Kodi once (upon boot) and if it does, great, but if it doesn't it never tries again? So my order/flow makes sense then on my first post above?
With the current version of HA you should make sure to always start/restart HA when kodi is offline.
Then (from what I can tell) it should work properly even without tinkering with the source.
Follow the PR #17474 if you're curious about more detailed stuff.
You are correct in that if you start HA with Kodi offline, the socket will reconnect as required. That's good to know until I see an update from your PR. Thanks!
The setup I have is that my Kodi is on 24/7 since I also use it to automatically import new files when they are available. So the scenario of having Kodi offline wouldn't really work then.
Second PR was just closed and I don't feel like jumping through any more hoops.
If anyone else wants to try and get this fixed, be my guest.
Edit: I outlined the actual issue in both PRs that originated from this issue.
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 :+1:
still a bug...
@casperklein nope, not related.
The actual problem is well known at this point but neither of my two fixes was accepted.
Creating a fix which would fit their requirements would take a day or two with proper testing.
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 now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
still a bug...