Support for control of HomeKit bulbs and switches (testing required!)

Support for direct control of HomeKit devices just got merged, and ought to be in 0.68. It’s not enabled by default and could do with broader testing (it works fine for me, but the amount of hardware I have is limited). To enable it, make sure configuration.yaml has the following:

discovery:
  enable:
   - homekit

and any IP-based HomeKit devices on your network should appear. You’ll need to enter the homekit code from the web UI, but this pairing information will be saved. Once paired, if a device provides any lights or switches these should automatically be added to the UI. Things I’m interested in:

  1. Bulbs and switches that don’t work
  2. Devices that appear under HomeKit but which are already supported by HASS

(1) is stuff that I’ll want to fix up as quickly as possible. (2) is stuff that we’ll want to blacklist from the HomeKit code in order to leave it up to the native code (for instance, Tradfri has HomeKit support, but only for Ikea bulbs - if you use any Hue bulbs, they won’t appear, so we want to continue using the Tradfri component and block the HomeKit component from finding it)

2 Likes

Trying to test on a fresh install of Debian 9.4 but setting up homekit-controller failed due to missing dependencies - have you added a section to the docs somewhere that notes the required system libs to install gmpy2 (a dep of homekit)? Looks like gmp, mpfr, and mpc.

Edit - to my base Debian install, I needed to do:

apt install libgmp-dev libmpfr-dev libmpc-dev 

Before pip install gmpy2 would work inside my HA venv.

1 Like

Trying to connect to a Hue Bridge as a first test, but hitting configure in the frontend and entering the code from the bottom of the bridge (both with dashes and without) results in:

Error executing service <ServiceCall configurator.configure: configure_id=140564616230840-3, fields=code=72785369>
Traceback (most recent call last):
  File "/root/home-assistant/homeassistant/core.py", line 1002, in _event_to_service_call
    await service_handler.func(service_call)
  File "/root/home-assistant/homeassistant/components/configurator.py", line 224, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/home-assistant/homeassistant/components/homekit_controller/__init__.py", line 137, in device_config_callback
    self.conn, code, pairing_id)
  File "/root/home-assistant/lib/python3.5/site-packages/homekit/protocol.py", line 89, in perform_pair_setup
    assert response_tlv[TLV.kTLVType_State] == TLV.M4
AssertionError

I’ve also just tried to pair with a Lutron Smart Bridge Pro 2 and have no success; the SUBMIT button on the frontend greys out and the circle spins endlessly, and HA appears to hang.

In the terminal (scrolling the HA log), the following is discovered:

2018-04-13 14:56:25 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=configurator.smart_bridge_pro_2, old_state=None, new_state=<state configurator.smart_bridge_pro_2=configure; description=Please enter the HomeKit code for your Smart Bridge Pro 2, entity_picture=None, fields=[{'type': 'string', 'name': 'HomeKit code', 'id': 'code'}], submit_caption=submit, configure_id=139655092167064-1, friendly_name=Smart Bridge Pro 2 @ 2018-04-13T14:56:25.057776-04:00>>

After I click submit, the terminal immediately displays the following and HA hangs:

2018-04-13 14:56:43 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=fields=code=872-20-780, configure_id=139655092167064-1, domain=configurator, service_call_id=139656802197120-2, service=configure>
Step #3: unkown error!

That’s great feedback - could you open a couple of issues on github (one for each platform) and assign them to me? (I’m mjg59 on github)

I’ve opened issues on the repo but I can’t assign them to you - I did tag you on them however:

https://github.com/home-assistant/home-assistant/issues/13860

https://github.com/home-assistant/home-assistant/issues/13861

I’ve added support for providing more useful feedback when pairing fails, but it needs an updated version of the homekit package first. I’ll update once that’s merged.

this is my error:

Error executing service <ServiceCall configurator.configure: configure_id=140274439927624-2, fields=code=836-36-833>
Traceback (most recent call last):
File “/usr/src/app/homeassistant/core.py”, line 1002, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/src/app/homeassistant/components/configurator.py”, line 224, in async_handle_service_call
call.data.get(ATTR_FIELDS, {}))
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/app/homeassistant/components/homekit_controller/init.py”, line 138, in device_config_callback
pairing_id)
File “/config/deps/lib/python3.6/site-packages/homekit/protocol.py”, line 67, in perform_pair_setup
connection.request(‘POST’, ‘/pair-setup’, request_tlv, headers)
File “/usr/local/lib/python3.6/http/client.py”, line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/usr/local/lib/python3.6/http/client.py”, line 1250, in _send_request
self.putrequest(method, url, **skips)
File “/usr/local/lib/python3.6/http/client.py”, line 1108, in putrequest
raise CannotSendRequest(self.__state)
http.client.CannotSendRequest: Request-sent

Oh bother - yes, it looks like my monkey patching is incompatible with Python 3.6. I’ll try to fix that.

Actually, that’s not the problem. I’ll do some more digging. Does it always fail this way?

Thank you @marthocoo! I just confirmed your fix works on my new Ubuntu Server Docker install.

Hello, I’ve been considering switching over from zwave to homekit for my lighting devices to have more reliable control so went out and purchased a few Leviton dimmers and switches for testing knowing this component ensures we aren’t completely trapped into Apple’s ecosystem.

I have the controller working after updating the dependencies as @marthocoo has pointed out to make gmpy2 happy but it says the device has already been paired when I try to pair it. I did first pair with Home app on my phone (which has an ATV associated).

Do I have to associate all of my devices with HA and then expose them via the HomeKit component and only one device can pair or is something else wonky (it’s possible I used the wrong code, it’s late and I’m also trying to figure out what 4 different light switches codes are blindly).

Side note, am I crazy to switch from zwave?

Yes, you can only pair one device at once - if you reset the devices and then pair them with Home Assistant, you can export them back with the HomeKit component in order to pair them with Home.

1 Like

I wanted to try it with my Koogeek P1 Plug but these appeared:

%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20180430184725

Any solutions?

@TTDARK Check earlier in the thread, you need to install dependencies.

I’m using hassio and the ssh addon wont allow me to run those commands.
It may be a silly question, but is there anyway i can install the depencencies?

%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20180430214719

No there isn’t. You’ll have to wait until the underlying Docker image is fixed. I’ve opened a PR to add the dependencies to the main docker image, and I’m sure it will make its way to the RaspBerry Pi images after that.

1 Like

So my guess is these devices (Leviton Dimmer) use bluetooth initially to get the WiFi password so how is this supposed to work without Bluetooth available, does this controller component support bluetooth (I have it disabled on my PI as it’s suggested to for whatever reason when using a GPIO z-wave shield). Halp!

wifi setup isn’t part of the homekit spec, so you’ll need to use the vendor app to do that.

Anyone that have any thoughts regarding support for Elgato EVE devices since these are BTLE. Have some of their devices I would love to reuse in HA :slight_smile:

1 Like