Homekit stops working after some hours. openhab 3.4.0

in my case it is run from root’s crontab. Insert it using “sudo crontab -e”, chmod +x script and it should work.
if you want to do it from normal user - check if you are able to run this command step by step - openhab-cli, avahi-browse.

Thanks for your quick reply!

Weird, I added it to sudo crontab -e as well.
I can run the shell directly using sudo /opt/homeKitWatchdog/homeKitWatchdog.sh

But from crontab its not working.
Heres my crontab entry:
*/1 * * * * /opt/homeKitWatchdog/homeKitWatchdog.sh >> /var/log/homeKitWatchdog.log
but all my log does is

................................................
2023.01.16 20:51:01
 
hap service not found restarting

................................................

When running it directly using sudo /opt/homeKitWatchdog/homeKitWatchdog.sh I get

................................................
2023.01.16 20:54:10
 
hap service not found restarting

Logging in as openhab
................................................

I checked permissions for the shell and the log. But the command is never executed it seems…
Any idea?

you need to check the homekit bridge name in openhab config. In my setup it’is “openHAB” try to execute
avahi-browse -t _hap._tcp |grep openHAB and tell me if there is a line if not try avahi-browse -a and find it, then change the grep openHab

i think the command is executed properly, but the hap service is not up - maybe there is an error in configuration ? check the logs of homekit binding

As I said, everything works perfectly fine if I execute the shell directly. Just from crontab its behaving different.
I will check the logs and get back to you, thanks again!

I did setup ssh with an rsa key (Tutorial: Restart Binding from rule - #14 by shutterfreak) to execute the karaf command.

I adapted the shell to execute

ssh -p 8101 -i ~/.ssh/karaf.id_rsa openhab@localhost 'bundle:restart org.openhab.io.homekit'

now its working fine… who knows what was the reason

Thanks again for your help!

1 Like

So after some weeks my homekit is unavailable again.
Trace writes this message:
18:14:11.662 [TRACE] [enhab.io.homekit.internal.HomekitImpl] - HomeKit bridge reacting on network interface changes.
18:15:13.721 [TRACE] [enhab.io.homekit.internal.HomekitImpl] - HomeKit bridge reacting on network interface changes.

IP hasnt changed.

Does your router/access point automatically change channels?
Do you have a mesh WiFI network?
Try disabling and automatic channel changes and/or bind your OpenHAB device to one access point.
I have seen quite a few other pieces of software have issues with the above so it is worth ruling them out as potential issues.

Hi together. I have the same issue, but on 3.4.1.

Pairing works fine, but after ~1 oder ~2 hours there is no connection anymore…

Befor the update everything works fine, so it looks like an issue in the 3.4.1 version? I made all the things above…

More ideas?!

i am “stable” on 3.4.1 with 9 hosts now, it’s not related to 3.4.1 but the homekit bridge sometimes is down after network changes

@moto you are right, cron is not handling correctly the openhab-cli command which seems to be a wrapper to ssh with password at prompt, switching to rsa-keys is helping. Now we have working solution to refresh it.

@yfre any news from your site ? or / somebody on it ?

@Jacek_Kaczmarczyk @xtoasty

it looks like in some case the network change / short reconnect is not handled correctly by homekit addon.
the fix was already implemented by @ccutrer but it is for oh4.0. not sure whether it can be installed on 3.4.1

if 3.4.2 will be release then this fix can be included in 3.4.2

alternative, try to find a way to avoid network changes, e.g. static ip address.
you can try to install the

2 Likes

@yfre @ccutrer 3.4.2 installed MY issue still exist. after powering off and on router again openhab _hap._tcp is not visible in the network and i need to refreash the bundle.
Version: 3.4.2 (Build)

ah now i understand it will be included in 3.4.3 build

Note also if you continue to have problems, try setting Use openHAB mDNS service to off in the HomeKit settings. I’ve found an issue where if your network interfaces change (in my case bringing up a new docker container), openHAB resets mDNS, but the HomeKit addon doesn’t know about it.

thank you i will try. I noticed that with toggled ON the ‘bundle:restart org.openhab.io.homekit’ command used in my cron script is not helping to bring back the mds entry of homekit bridge. So the whole script is not working :frowning:

btw is openhab 3.4.3 planned to be released? is this fix included in 4.0?

@Kai is there any chance to get 3.4.3 soon ?

I upgraded on Monday.

This topic is not solved, right?
At least for me I still have the problems described in this thread. My Homekit loses conection even with mDNS ON or and with mDNS OFF.
I tried OH3.4.4 and now I am on OH4.0 - no change. After some hours Homekit stops working.

Execeuting a ‘bundle:restart org.openhab.io.homekit’ solves the problem immediately.
Isn’t there another solution available? :slight_smile:

My OH is running in a Docker Container on Synology / I am using fixed IPs only / OH4 / mDNS on or off - does not have an effect / ipv6 is disabled

I haven’t had an unexpected disconnect for HomeKit in several months. I am running a custom build of the addon with several commits adding new features that I haven’t had time to polish up PRs for, but I don’t believe any of them should include stability improvements (GitHub - ccutrer/openhab-addons at homekit; beware I rebase this branch each time I update openHAB). The big thing for me was disabling the shared mDNS. I know the root cause for that (openHAB’s network manager rebuilds it on any network interface change, but HomeKit has cache the underlying JmDNSClient, and only restarts itself if the network change is for the interface we’re using), but a fix will be tricky (even if we always restart, or we improve openHAB core to only restart the JmDNSClient when the appropriate interface changes, there’s still a race condition because both objects are notified of the same event at the same time in different threads).

Hi,
I didn’t have any homekit disconnection for months, until I upgraded to from 3 to 4.0.1.

I now get this once every two weeks approximately.

2023-08-11 10:51:09.329 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - HomeKit bridge reacting on network interface changes.
2023-08-11 10:51:09.330 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - removed interface /fe80:0:0:0:18a9:624a:d4e8:2591%wlan0
2023-08-11 10:51:09.332 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - removed interface /192.168.100.200
2023-08-11 10:51:09.332 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - stopping HomeKit bridge
2023-08-11 10:51:09.333 [TRACE] [penhab.io.homekit.internal.Debouncer] - stop debouncer
2023-08-11 10:52:11.440 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - HomeKit bridge reacting on network interface changes.
2023-08-11 10:52:11.442 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - starting HomeKit bridge instance 1
2023-08-11 10:52:11.447 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - no suitable mDNS server for IP /192.168.100.200 found
2023-08-11 10:52:11.448 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - create HomeKit server with dedicated mDNS server
2023-08-11 10:52:11.800 [WARN ] [nhab.io.homekit.internal.HomekitImpl] - could not initialize HomeKit bridge: No such device
2023-08-11 10:57:26.823 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - HomeKit bridge reacting on network interface changes.
2023-08-11 10:57:26.825 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - removed interface /fe80:0:0:0:dea6:32ff:feeb:d740%wlan0
2023-08-11 10:57:26.826 [TRACE] [nhab.io.homekit.internal.HomekitImpl] - removed interface /10.41.0.1
2023-08-11 10:57:26.827 [WARN ] [nhab.io.homekit.internal.HomekitImpl] - trying to start HomeKit server but it is already initialized

So it seems that it is trying to restart the bundle but it can’t because it hasn’t been correctly stopped.

In fact:

openhab> bundle:status org.openhab.io.homekit 
Active

Besides, do you happen to know what that 10.41.0.1 interface is? I have nothing like that in my network.

Hi Matteo
10.41.0.1 must be something on your openHAB machines. it says sometning about wlan0.
to me, it looks like, wlan0 changes the ip from 192.168.100.200 to 10.41.0.1 and back for a very short time.
openHAB homekit see that 192.168.100.200 is down and stops the bridge/addon for that address, while homekit is busy with stopping the bridge, the interface is up again, and homekit starting the bridge, but then the wlan0 is down again (see “could not initialize HomeKit bridge: No such device”)… and so on.

so. interface and up and down faster than homekit with up/down of the bridge (addon). as result you can get partially started/stopped homekit addon with all possible strange effects.