openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.58k forks source link

[HomeKit] - Losing Rooms/Zones in Homekit #929

Closed edsonaj closed 7 years ago

edsonaj commented 8 years ago

Hi,

I'm using the homekit extension to map KNX and Insteon devices to homekit. It works perfectly until the server is restarted. When that happens, I lose all links between the accessories/devices and rooms/zones. Everything shows up in the Default Room (homekit).

I tried to link them using Insteon+ app and Elegato Eve app.

I searched in the log but didn't find anything related to this.

Could this be related to the homekit id? I know the id is hashed from the device name, but can I manually set an id if so?

andylintner commented 8 years ago

Hi @edsonaj

I think this might result from a race between the HomeKit advertisement being sent and the accessories being fully initialized. I saw this a few times during early testing, but haven't been able to reproduce it. If you have logs from the openHAB instance when you restarted and the rooms cleared, that would be useful.

edsonaj commented 8 years ago

Hi @beowulfe,

I searched the logs but I think I deleted them. I changed the openhab startup from service to a script + task scheduler and didn't saw this anymore.

I will test again this weekend using the service startup and send you logs if the rooms cleared.

edsonaj commented 8 years ago

Hi @beowulfe

Here are the logs.

openhab.log.txt openhab.log.1.txt

andylintner commented 8 years ago

Thanks @edsonaj - looks like my assumption was right. Your HomeKit client is connecting before your Insteon devices finish initializing. So it first gets an empty list of accessories, which must clear out iOS's local settings for the accessory. I should be able to replicate this race locally - I'll see what I can do.

edsonaj commented 8 years ago

Hi @beowulfe ,

Any news on this? If you need any test, feel free to contact me.

Also I don't know what you plan to do, but if possible a simple startup delay with the time set in the .cfg will work for me.

Thanks,

andylintner commented 8 years ago

Not really. Someone with access to the actual spec reached out and pointed out an issue - the advertisement the bridge makes has an integer that needs to be incremental with each revision to the list of included accessories. In this case, when iOS sees the accessory list changed without a change to this sequence, it assumes the bridge was reset and treats it as new.

This is a bit at odds with openHAB, as there's no concept of revisions to the item catalog. I'm working on a way to hash the item list and store that in the persisted state, but it's a non-trivial change. I'll try to get something together in the next couple weeks. Are you willing to beta test if I drop you a JAR?

edsonaj commented 8 years ago

@beowulfe Sure, when you have something send it to me.

andylintner commented 8 years ago

@kaikreuzer - started working on this - it's a race between the iOS client connecting and the items model being loaded. iOS drops metadata if it can't find the accessory in the bridge.

I'm having a hard time identifying when the model is fully loaded. I thought I'd get this from ItemRegistryChangeListener.allItemsChanged, but it doesn't seem to be getting called - instead, the added() method is called for each item that's added.

Any suggestions on how I can know everything is initialized?

kaikreuzer commented 8 years ago

Sounds as if you might be interested in https://github.com/eclipse/smarthome/issues/1896.

andylintner commented 8 years ago

Yep, that's exactly what I need! I'll follow that issue.

edsonaj commented 7 years ago

Hi @beowulfe

Any news on this?

Thanks

andylintner commented 7 years ago

Still waiting on the ESH issue to be resolved - there's no way to solve this within the add-on without that.

anthonygillet commented 7 years ago

I am experiencing this same exact issue as well, with Insteon devices and OH2. I have over 30 homekit devices so it is very annoying to have to reassign rooms every time this happens, and it happens fairly frequently since I am actively developing my openhab setup.

While we await a fix, is there any workaround in the meantime? Such as:

hypery2k commented 7 years ago

are there any news on this issue? Experiencing the same issue

theo-69 commented 7 years ago

Having the same Problem any solution yet? Hey @hypery2k did you find a solution yet?

theo-69 commented 7 years ago

still no solution?

edsonaj commented 7 years ago

Hey @beowulfe, any news on this?

andylintner commented 7 years ago

@edsonaj - I had a thought that this behavior might be related not to items that aren't available, but simply items whose values have not been initialized. There was a fix to the homekit library to better handle null values. I have an updated addon here: https://github.com/beowulfe/openhab2/releases/tag/homekit-1.1.4

Can you or someone else give that a shot and see if it has an impact?

andylintner commented 7 years ago

Actually, scratch that. I was finally able to reproduce this reliably!

There are a few fixes here - the most important one is I'm making use of Apple's configuration index for the bridge. That entails advertising what's essentially a revision number with the bridge. So, the very first time we advertise anything, we advertise it with revision "1". If something changes, we increment that to "2".

On startup, I now wait until the list of accessories exactly matches the previously published list before advertising, or until a timeout expires. If the timeout expires, we use the current set as the new expected set, and increment the version. The default timeout is 30 seconds - you can change it via the startupTimeout configuration key.

This will mean a delay before homekit starts up when you make changes to the accessories you're exposing, but I feel like that's a fair trade-off.

Here's the updated jar: https://github.com/beowulfe/openhab2/releases/tag/accessory-state

martinvw commented 7 years ago

This will mean a delay before homekit starts up when you make changes to the accessories you're exposing, but I feel like that's a fair trade-off.

That sounds indeed like a fair trade-off. Thanks for looking into it!

edsonaj commented 7 years ago

Great, that solved it.

Thank you.

martinvw commented 7 years ago

@beowulfe can you also create a PR for it? Thanks!

maltetgh commented 6 years ago

@beowulfe Im still running into problems because HomeKit compares the accessory list apparently against a version before the RWE binding was initialized.

On subsequent starts of openHAB just before the RWE binding begins to initialize the log says:

Reached homekit target state for version 1, starting

I dont know when you save the accessory list and it seems that after an crash of openhab there is a empty or very short list saved.

I think it would help to have a forced timeout... it would be more stable than an incorrect version of the accessory list for comparison. If I could set a forced timeout of 60 seconds before HomeKit ever initializes, I could be sure that the RWE binding is done initializing and updating device states.

Thanks :)

edsonaj commented 6 years ago

You can change that in homekit config. The default is 30 seconds. Increase that so the biding is initialized before the timeout.


Edson Alves Junior

On 10 Oct 2017, at 09:17, maltetgh notifications@github.com wrote:

@beowulfe https://github.com/beowulfe Im still running into problems because HomeKit compares the accessory list apparently against a version before the RWE binding was initialized.

On subsequent starts of openHAB just before the RWE binding begins to initialize the log says:

Reached homekit target state for version 1, starting

I dont know when you save the accessory list and it seems that after an crash of openhab there is a empty or very short list saved.

I think it would help to have a forced timeout... it would be more stable than an incorrect version of the accessory list for comparison. If I could set a forced timeout of 60 seconds before HomeKit ever initializes, I could be sure that the RWE binding is done initializing and updating device states.

Thanks :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/openhab/openhab2-addons/issues/929#issuecomment-335453523, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBG33ppi4OJm-9pe5KJ3tkYKFV9fuKLks5sq2A8gaJpZM4IeskE.

juelicher commented 6 years ago

@beowulfe First of all thanks a lot for your effort with the homekit addon!

As I also had the issue, that the configuration was lost I wanted to try the snapshot within my openHAB 2.1 installation binding you posted in this thread. But this binding throws an exception: 2017-11-04 13:21:39.363 [ERROR] [org.openhab.io.homekit ] - [org.openhab.homekit(239)] The setItemRegistry method has thrown an exception java.lang.NoSuchMethodError: org.eclipse.smarthome.core.items.ItemRegistry.get(Ljava/lang/Object;)Lorg/eclipse/smarthome/core/common/registry/Identifiable; at org.openhab.io.homekit.internal.HomekitTaggedItem.isMemberOfRootGroup(HomekitTaggedItem.java:125)

Am I assuming correctly, that the 2.2 snapshot version of the binding can only be used with openHAB 2.2 and not 2.1?

Thanks for your help!

andylintner commented 6 years ago

Correct - you need the 2.2 version.

Depechie commented 6 years ago

Just for reference ( I'm new to OpenHab ), I configured the home bridge addon but everything is mapped to the default room in HomeKit. So how should one config OpenHab to get room mapping in HomeKit ( taking into account this should working )?

edsonaj commented 6 years ago

You have to map it manually in any homekit app.


Edson Alves Junior

Enviado por dispositivo móvel.

On Nov 4, 2017, at 10:57 AM, Depechie notifications@github.com wrote:

Just for reference ( I'm new to OpenHab ), I configured the home bridge addon but everything is mapped to the default room in HomeKit. So how should one config OpenHab to get room mapping in HomeKit ( taking into account this should working )?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

Depechie commented 6 years ago

Ok feeling like a total noob, but if I add a room in Homekit there are no accessories listed. So how do I divide the accessories from the OpenHab? For example my Openhab has several lighting points but they are now all mapped to default room in homekit because in that room I connected the openhab through the pincode.

edsonaj commented 6 years ago

You have to edit the device (one light per time) and change its room.

In Home app, click Edit in the upper tight corner and select a device. In the next screen there is a field named Room.


Edson Alves Junior

Enviado por dispositivo móvel.

On Nov 4, 2017, at 12:18 PM, Depechie notifications@github.com wrote:

Ok feeling like a total noob, but if I add a room in Homekit there are no accessories listed. So how do I divide the accessories from the OpenHab? For example my Openhab has several lighting points but they are now all mapped to default room in homekit because in that room I connected the openhab through the pincode.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

Depechie commented 6 years ago

thx

roswennen commented 6 years ago

I’m still on 2.1. When 2.2 becomes the stable version will the HomeKit binding automatically update or would it require a manual install of the jar ?

kingkoopa13 commented 6 years ago

@beowulfe, thanks for the hard work that's gone into this excellent addon.

I'm using 2.3.0-SNAPSHOT Build #1191 (W7 PC) and have this issue. Every now and again, all accessories reset to their original name and default room in the iOS Home app because the HomeKit client is connecting before my z-wave devices have initialized.

On Oct 2017, you posted this as a fix:

the updated jar: https://github.com/beowulfe/openhab2/releases/tag/accessory-state

Are the fixes posted in the 2.2.0 release you refer to here also included in 2.3.0? I assumed they were – otherwise I'm stumped as to why this is happening. 2.3.0 is reliable on my setup, so I'd like to find a way to implement this without losing Build #1191. Any help would be appreciated!

andylintner commented 6 years ago

Nope, they're not yet in the main branch, so the changes are not part of 2.3.0

kingkoopa13 commented 6 years ago

I see. thanks. So is there a way to install just the right bits of the .jar or do I have to roll back into 2.2.0?

kingkoopa13 commented 6 years ago

Okay. I've worked it out and placed the latest HomeKit build in my addons folder. Karaf confirms that the latest version is installed but it never runs, even after the 30 second delay. Any pointers?

martinvw commented 6 years ago

Please note that I would be more then happy to receive a pull request for this if everything is running (more) stable with this new version. If you mention me I will make sure we can get this merged ASAP.

Thanks for all your work and support!