Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomeKit integration occasionally has stale accessory state since 2022.11.x #81990

Closed
jfroy opened this issue Nov 12, 2022 · 27 comments
Closed

HomeKit integration occasionally has stale accessory state since 2022.11.x #81990

jfroy opened this issue Nov 12, 2022 · 27 comments

Comments

@jfroy
Copy link
Contributor

jfroy commented Nov 12, 2022

The problem

With 2022.11.x, the HomeKit integration feels somewhat less reliable. Specifically, accessory state is sometimes stale. Switching to a different view in the Home app or re-opening the Home app usually updates the state. I do not remember this behavior with 2022.10.x. Nothing has changed on my network (no hardware, software, or configuration change).

I bridge a mix of accessories via the HomeKit integration, including Z-Wave devices (deadbolts, scene controllers, light switches, LED strip controllers, sensors), HomeKit Bridge devices (light switches). I use a YAML configuration for my main bridge integration in order to associate battery sensors with some of the bridged accessories.

Home Assistant 2022.11.2
Supervisor 2022.10.2
Operating System 9.3
Frontend 20221108.0 - latest

What version of Home Assistant Core has the issue?

2022.11.2

What was the last working version of Home Assistant Core?

2022.10

What type of installation are you running?

Home Assistant OS

Integration causing the issue

HomeKit

Link to integration documentation on our website

https://www.home-assistant.io/integrations/homekit

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (homekit) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homekit can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign homekit Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


homekit documentation
homekit source
(message by IssueLinks)

@jfroy

This comment was marked as off-topic.

@jfroy

This comment was marked as off-topic.

@jfroy

This comment was marked as off-topic.

@jfroy
Copy link
Contributor Author

jfroy commented Nov 12, 2022

I've made a mess of this issue. The desync / late sync issue happens for all sorts of devices (for example zwave lights in another room). The issues with the Eve light switch is compounded by Thread/coap problems.

@jfroy
Copy link
Contributor Author

jfroy commented Nov 12, 2022

I suppose I should mention all my Apple devices are running the latest public stable release (so iOS 16.1.1, equivalent ATV version, and latest Ventura on macOS). It's quite possible these is an issue on Apple's side, and maybe I can devise a test methodology to discern that.

@iEddy1985

This comment was marked as off-topic.

@bdraco

This comment was marked as off-topic.

@bdraco
Copy link
Member

bdraco commented Nov 12, 2022

I've made a mess of this issue. The desync / late sync issue happens for all sorts of devices (for example zwave lights in another room). The issues with the Eve light switch is compounded by Thread/coap problems.

There is a lot to unpack here so I'm going to try to give you information about what has changed in the hopes that it can get you to a resolution.

  • There were some changes to how HomeKit works in 16.1/16.1.1 n the Apple side in preparation for the new architecture that Apple is releasing in 16.2. You may find your iOS device is talking to the home hub instead of accessories directly now.
  • There have been no protocol level changes on the HAP-python (underling library used by HomeKit` side except for a bugfix to send paired UUIDs in uppercase (this is likely not related) and the stable iid restore listed below.
  • Any HomeKit pairing made with HA before 2022.11 (day one problem with the HomeKit integraiton) never saved the iids between restarts and they were completely unstable. Unpairing and repairing will be sure that the Home Hub and iCloud has the correct iids. This sounds like it could be the issue
  • Any BLE HomeKit Controller pairing made before 2022.11 had incorrect service iids. I don't think this is the issue but they should be unpaired and re-paired as well.

@jfroy
Copy link
Contributor Author

jfroy commented Nov 12, 2022

What's the procedure for re-pairing or resetting a HA HomeKit bridge? Something like

  • Remove bridge from HomeKit
  • Remove bridge integration
  • Restart HA core
  • Re-add bridge integration
  • Re-pair new bridge in HomeKit

@bdraco
Copy link
Member

bdraco commented Nov 12, 2022

  • Remove bridge from HomeKit (verify QR code re-appears in HA)
  • Reload HA HomeKit integration to get a new ID
  • Re-pair new bridge in HomeKit

@bdraco
Copy link
Member

bdraco commented Nov 12, 2022

Actually the ID will probably not change unless you delete it and recreate it. But you could also modify the .state file in /config/.storage/homekit.ENTRY_ID.state and pick a new random id and reload

@jfroy
Copy link
Contributor Author

jfroy commented Nov 12, 2022

I followed my procedure and made a brand new bridge. Going to see how the system behaves over the weekend.

I'll open a new issue specifically for the Thread devices. They all do seem to go unavailable in HA after some time.

@jfroy
Copy link
Contributor Author

jfroy commented Nov 13, 2022

The problem has just occurred again. Went into the Apple Home app and I had a very stale turned on lights count and light states across the home which did not update after waiting idle in the app for 10 seconds or so. I went out of the app back to the home screen, waiting a few seconds, went back into Apple Home and that triggered a refresh. I never observed this behavior in the recent past (a month ago).

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

If you enable debug logs for pyhap do you see the events still being sent?

@jfroy
Copy link
Contributor Author

jfroy commented Nov 13, 2022

If you enable debug logs for pyhap do you see the ends still being sent?

The ends?

In any case, debug logging is enabled and I'll keep an eye out for the problem again so I have a time region to look at in the logs. I don't have a good sense of when the problem occurs. It may be when I leave home and the phone goes on cellular, it could be a lapse of time w/o going into the Apple Home app, or something else entirely.

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

Autocorrect fail: should have been "events"

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

Also check in the Home app which Apple device is the home hub. You'll likely find in the pyhap debug log thats where the events are being sent. Sometimes events can be missed if

  • its a Home Pod (Mini) and the wifi connection is flakey (I wish Apple provided a way to disable HomeKit on these like they do for the apple tvs)
  • it needs to be rebooted because of stability issues with the device itself. I saw on the homekit subreddit recently that someone had a similar issue and solved it by rebooting all their home pod minis

@jfroy
Copy link
Contributor Author

jfroy commented Nov 13, 2022

I use a wired AppleTV as my only HomeKit hub (do not own any HomePods). Apple Home on my phone and Mac shows it as connected.

However, I just remembered that some of my accessories (WeMo lights) are directly paired to my HomeKit home. I'll pay extra attention the next time the issue occurs, but I believe some of those lights also had stale state. If that's the case, the issue is on the ATV HomeKit hub, not in HA. I don't know if there would be indication that the hub stopped responding in the pyhap logs.

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

I don't know if there would be indication that the hub stopped responding in the pyhap logs.

If its network is down you'll see it stop getting events. If its network is up it could still be receiving the events but not processing them

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

I use a wired AppleTV as my only HomeKit hub (do not own any HomePods).

Glad we can rule that out as that one is always nearly impossible to resolve if its wifi

Which version of TvOS and AppleTV hardware do you have?

@jfroy
Copy link
Contributor Author

jfroy commented Nov 13, 2022

I use a wired AppleTV as my only HomeKit hub (do not own any HomePods).

Glad we can rule that out as that one is always nearly impossible to resolve if its wifi

Which version of TvOS and AppleTV hardware do you have?

Apple TV 4K 2nd gen (AppleTV11,1). It's currently on tvOS 16.1.

@bdraco
Copy link
Member

bdraco commented Nov 13, 2022

I've got almost the same setup for my production except I'm using a 4k gen3 AppleTV14,1 w/tvOS 16.1

I haven't had any luck replicating this yet, but I'll keep watching.

@jfroy
Copy link
Contributor Author

jfroy commented Nov 15, 2022

I have radically simplified my prod network over the weekend. No more VLANs, everything on the default LAN. I have not observed the issue again yet, but will keep open a few more days.

A Unifi OS 1.x network with VLANs + Unifi OS 1.x's mdns reflector may have reliability problems. I did reboot my ATV and a lot of other devices however (as part of the network arch change), so it is also possible I "flushed out the badness" just by rebooting devices.

@jfroy
Copy link
Contributor Author

jfroy commented Dec 10, 2022

This is still ongoing. I have a feeling it's an issue with Apple Home app and not strictly related to the HomeKit integration, though of course there could be an interaction (would be very difficult to prove w/o ripping apart most of my HomeKit home).

@bdraco
Copy link
Member

bdraco commented Dec 11, 2022

Might be best to wait for iOS 16.2 and see if the new architecture fixes it since whatever time we invest in digging through this is likely going to be wasted effort when everything changes again shortly.

@issue-triage-workflows
Copy link

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 has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants