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

Xiaomi Mi Bedside Lamp 2 pairing problem #116

Closed
rgruyters opened this issue Mar 4, 2019 · 15 comments
Closed

Xiaomi Mi Bedside Lamp 2 pairing problem #116

rgruyters opened this issue Mar 4, 2019 · 15 comments

Comments

@rgruyters
Copy link

I'm trying to add my Xiaomi Mi Bedside Lamp 2 to my Hass, but uncounted an issue.

53557023-61235b00-3b45-11e9-86a7-4ef62e3f4d03

After some debugging I noticed the following message:

2019-03-03 12:26:22 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1794488400] Error handling message: {'type': 'call_service', 'domain': 'configurator', 'service': 'configure', 'service_data': {'configure_id': '1818329712-1', 'fields': {'code': 'XXXXXXXX'}}, 'id': 24}
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/decorators.py", line 17, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 147, in handle_call_service
    connection.context(msg))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1133, in async_call
    self._execute_service(handler, service_call))
  File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1155, in _execute_service
    await handler.func(service_call)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/configurator/__init__.py", line 221, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/homekit_controller/__init__.py", line 139, in device_config_callback
    self.controller.perform_pairing(self.hkid, self.hkid, code)
  File "/usr/local/lib/python3.7/site-packages/homekit/controller.py", line 192, in perform_pairing
    pairing = perform_pair_setup(conn, pin, str(uuid.uuid4()))
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 98, in perform_pair_setup
    error_handler(response_tlv[1][1], 'step 3')
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 50, in error_handler
    raise BusyError(stage)
homekit.exceptions.BusyError: step 3

I logged into the hassio container and tried to use the Python module directly to see what is happening.

bash-4.4# python3 -m homekit.discover
Name: Home Assistant Bridge._hap._tcp.local.
Url: http_impl:https://192.168.10.34:51827
Configuration number (c#): 2
Feature Flags (ff): Paired (Flag: 0)
Device ID (id): 57:6C:02:39:B1:3B
Model Name (md): Home Assistant Bridge
Protocol Version (pv): 1.0
State Number (s#): 1
Status Flags (sf): 0
Category Identifier (ci): Bridge (Id: 2)

Name: Philips hue - 2B5424._hap._tcp.local.
Url: http_impl:https://192.168.10.14:8080
Configuration number (c#): 16
Feature Flags (ff): Supports Pairing (Flag: 1)
Device ID (id): 90:E7:6C:D7:43:09
Model Name (md): BSB002
Protocol Version (pv): 1.1
State Number (s#): 1
Status Flags (sf): 0
Category Identifier (ci): Bridge (Id: 2)

Name: MiBedsideLamp2-2BC2._hap._tcp.local.
Url: http_impl:https://192.168.10.36:80
Configuration number (c#): 1
Feature Flags (ff): Supports Pairing (Flag: 1)
Device ID (id): 74:D1:16:5A:5F:69
Model Name (md): MJCTD02YL
Protocol Version (pv): 1.1
State Number (s#): 1
Status Flags (sf): 0
Category Identifier (ci): Lightbulb (Id: 5)

And:

bash-4.4# echo '{}' > pairing.json

bash-4.4# python -m homekit.pair -d 74:D1:16:5A:5F:69 -f pairing.json -a MiBedsideLamp2 -p XXXXXXXX
step 3
bash-4.4#

Is this a known issue? Can I fix this?

@rgruyters
Copy link
Author

FYI, I have no issues when pairing via Home.app on iOS devices.

@jlusiardi
Copy link
Owner

Hi,

BusyError should mean that there is already pairing attempt blocking the next one. Could you unpair the iOS device and try again.

Also the homekit version is up to date? Could you try the code from the repository and use branch add_bluetooth? The pair.py can print debug information with -–log DEBUG Then.

@rgruyters
Copy link
Author

Hass.IO uses version 0.12.2.

bash-4.4# pip freeze|grep homekit
homekit==0.12.2

Need to find a way to install the add_bluetooth branch on hassio.

@rgruyters
Copy link
Author

rgruyters commented Mar 4, 2019

I have removed pairing to Home.app and now I get the following message:

bash-4.4# echo '{}' > pairing.json
bash-4.4# python -m homekit.pair -d 74:D1:16:5A:5F:69 -f pairing.json -a MiBedsideLamp2 -p XXXXXXXX
step 5
bash-4.4#

@rgruyters
Copy link
Author

I have tried to install the add_bluetooth branch but no luck.

bash-4.4# pip3 install -U https://github.com/jlusiardi/homekit_python/archive/add_bluetooth.zip
Collecting https://github.com/jlusiardi/homekit_python/archive/add_bluetooth.zip
  Downloading https://github.com/jlusiardi/homekit_python/archive/add_bluetooth.zip
     \ 1.7MB 10.8MB/s
Requirement already satisfied, skipping upgrade: zeroconf in /usr/local/lib/python3.7/site-packages (from homekit==0.12.2) (0.21.3)
Requirement already satisfied, skipping upgrade: hkdf in /usr/local/lib/python3.7/site-packages (from homekit==0.12.2) (0.0.3)
Requirement already satisfied, skipping upgrade: ed25519 in /usr/local/lib/python3.7/site-packages (from homekit==0.12.2) (1.4)
Requirement already satisfied, skipping upgrade: cryptography in /usr/local/lib/python3.7/site-packages (from homekit==0.12.2) (2.5)
Requirement already satisfied, skipping upgrade: ifaddr in /usr/local/lib/python3.7/site-packages (from zeroconf->homekit==0.12.2) (0.1.6)
Requirement already satisfied, skipping upgrade: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.7/site-packages (from cryptography->homekit==0.12.2) (1.11.5)
Requirement already satisfied, skipping upgrade: asn1crypto>=0.21.0 in /usr/local/lib/python3.7/site-packages (from cryptography->homekit==0.12.2) (0.24.0)
Requirement already satisfied, skipping upgrade: six>=1.4.1 in /usr/local/lib/python3.7/site-packages (from cryptography->homekit==0.12.2) (1.12.0)
Requirement already satisfied, skipping upgrade: pycparser in /usr/local/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->homekit==0.12.2) (2.19)
Building wheels for collected packages: homekit
  Building wheel for homekit (setup.py) ... done
  Stored in directory: /tmp/pip-ephem-wheel-cache-yrda5929/wheels/7b/b7/ad/220f2d78d18880e70e283f5741bbcf44227afa6d1b75bfec51
Successfully built homekit
Installing collected packages: homekit
  Found existing installation: homekit 0.12.2
    Uninstalling homekit-0.12.2:
      Successfully uninstalled homekit-0.12.2
Successfully installed homekit-0.12.2
bash-4.4# python -m homekit.discover
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.7/site-packages/homekit/__init__.py", line 26, in <module>
    from homekit.controller import Controller
ModuleNotFoundError: No module named 'homekit.controller'
bash-4.4#
bash-4.4# python -m homekit.pair -d 74:D1:16:5A:5F:69 -f pairing.json -a MiBedsideLamp2 -p XXXXXXXX
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/local/lib/python3.7/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/usr/local/lib/python3.7/site-packages/homekit/__init__.py", line 26, in <module>
    from homekit.controller import Controller
ModuleNotFoundError: No module named 'homekit.controller'

@Jc2k
Copy link
Collaborator

Jc2k commented Mar 5, 2019

@rgruyters the add_bluetooth branch will not work with HA or HASS.io yet. When it's released I will make the neccessary changes to HA. I think @jlusiardi means you should try and pair with the CLI using the add_bluetooth branch, not try and run HA/HASS.io with the add_bluetooth branch.

@jlusiardi
Copy link
Owner

Yes exactly what @Jc2k said. Sorry for my imprecise wording. I just want to exclude that hass.io has effects and in the branch we have more debug logs as described in my last comment.

@rgruyters
Copy link
Author

Ah, ok. Will try in my local dev environment.

@rgruyters
Copy link
Author

Finally find the time to do it. Here is the debug output. Hopefully it gives enough info to get it working.

robin@ubuntu:~/dev/homekit_python$ echo '{}' > pairing.json
robin@ubuntu:~/dev/homekit_python$ python3 -m homekit.pair -d 74:D1:16:5A:5F:69 -f pairing.json -a MiBedsideLamp2 -p XXXXXXXX --log DEBUG
2019-03-06 08:14:09,827 __init__.py:0109 DEBUG #1 ios -> accessory: send SRP start request
2019-03-06 08:14:09,828 tlv.py:0134 DEBUG sending [
  6: (1 bytes) 0x01
  0: (1 bytes) 0x01
]

2019-03-06 08:14:09,830 tlv.py:0117 DEBUG receiving [
  6: (1 bytes) 0x01
  0: (1 bytes) 0x01
]

2019-03-06 08:14:09,830 __init__.py:0058 DEBUG write message: [
  6: (1 bytes) 0x01
  0: (1 bytes) 0x01
]

2019-03-06 08:14:10,473 tlv.py:0117 DEBUG receiving [
  6: (1 bytes) 0x02
  3: (384 bytes) 0xe4e7f354fcaec598cf2504ba07fd25c33d9fa25fe7eedf7b32d3f57ae4ecec2c76662a8eb0a8f7e9790cd394a82c03ef65de2f3d0d3e9a3d5f18e6172bd7bd653d1837ce021a120d2fa3c230fad88975267ae6622dfe4b2a4c702c6a97a552ba4cc58d6d1171bda4a301f2a8ba00f82a16cbaffff0aad93d39bafd836ed1cbaf5e810bccb4b3276e6692a8a5e1d0503b10969de1bed3841c968c749f2f301061008cf105e22601ea4d90926846a9c67efda8c904af0b194d1d0f1c669f443c91a8fc867154efbe479918ef9ac3b50582fb463a60c2855fa99839b694ec0b18d9d2781e342f93007081191b2372d19aa7f65f30130681e1c49cbb1a1fccabb309c64af4cdbf714366ab8f5eeb75110bba781428d82e0b54b9722301bde3c49ae61e6377586696e3c30a21f479a3e49fef7e6d151efaa9a772c7c53e14bb39903039b2d47e2e075638f8b9c691f421940ff720234e28af42d4ab40fbf4fdd68919d2cb4abb1303a9e5eae546851de4bbe471ebca1e090af2250223dd8e498975b1
  2: (16 bytes) 0xbc3ce3599fdb0419f6e46e1074a7aabf
]

2019-03-06 08:14:10,475 __init__.py:0066 DEBUG response: [
  6: (1 bytes) 0x02
  3: (384 bytes) 0xe4e7f354fcaec598cf2504ba07fd25c33d9fa25fe7eedf7b32d3f57ae4ecec2c76662a8eb0a8f7e9790cd394a82c03ef65de2f3d0d3e9a3d5f18e6172bd7bd653d1837ce021a120d2fa3c230fad88975267ae6622dfe4b2a4c702c6a97a552ba4cc58d6d1171bda4a301f2a8ba00f82a16cbaffff0aad93d39bafd836ed1cbaf5e810bccb4b3276e6692a8a5e1d0503b10969de1bed3841c968c749f2f301061008cf105e22601ea4d90926846a9c67efda8c904af0b194d1d0f1c669f443c91a8fc867154efbe479918ef9ac3b50582fb463a60c2855fa99839b694ec0b18d9d2781e342f93007081191b2372d19aa7f65f30130681e1c49cbb1a1fccabb309c64af4cdbf714366ab8f5eeb75110bba781428d82e0b54b9722301bde3c49ae61e6377586696e3c30a21f479a3e49fef7e6d151efaa9a772c7c53e14bb39903039b2d47e2e075638f8b9c691f421940ff720234e28af42d4ab40fbf4fdd68919d2cb4abb1303a9e5eae546851de4bbe471ebca1e090af2250223dd8e498975b1
  2: (16 bytes) 0xbc3ce3599fdb0419f6e46e1074a7aabf
]

2019-03-06 08:14:10,476 __init__.py:0121 DEBUG #3 ios -> accessory: send SRP verify request
2019-03-06 08:14:10,521 tlv.py:0134 DEBUG sending [
  6: (1 bytes) 0x03
  3: (384 bytes) 0x6915039d4503f3c1cd8998e7c9fca768ba22b0257c3517f3176d8508b644239791d401f4abe9ded938b6abb2ba1c3670b60a0d5290f938f6404cd00f00992b59485e394d1f178915589b52806b9844a0388f568f888a35287f44e836e7ae7f01a27be7616ef083893aa38d3299f07506066fc6278152be4b48a82de4e269bfd8a9b77f80fbb4c047c60002b92e23cf29f110b59bf9e9969a56080b65530246f7382f4b0c2840b8d776789789e6140a779894de29c01177e5565ff5fc4efb1c46452e562125b783026bd9ca4eb623dd1318e108aeba20df97d58b1a00bf594bd8b1ec1aae7e2b3bb6325ca8580ca9037be6c03398b59371be6b9e99b16e816fc3dd524a8ad436cb58023c595869a08916a7467ea053c328bcca4cfd16487f3fc8741982ab78ddb72eb40e761776d49b35c0a822cd72dc87561a1d72ea0be1f8fc058b19a854f8bafe21ed7a2c9f1439dfd5f934099710621eb7135e2f06fbf9b3a75b0e238a08b65969931f0e278e61ade99f2f2539dec2c53e0fbc066663ecce
  4: (64 bytes) 0x9d26083a7abe410daeb5d99cc8ad28e578f89210ee4c9eabbf6960e8e297fbbc766426e76296debc0233cdfeae25360b921f16583c0fe4ee76e5bd73fb3963a9
]

2019-03-06 08:14:10,522 tlv.py:0117 DEBUG receiving [
  6: (1 bytes) 0x03
  3: (384 bytes) 0x6915039d4503f3c1cd8998e7c9fca768ba22b0257c3517f3176d8508b644239791d401f4abe9ded938b6abb2ba1c3670b60a0d5290f938f6404cd00f00992b59485e394d1f178915589b52806b9844a0388f568f888a35287f44e836e7ae7f01a27be7616ef083893aa38d3299f07506066fc6278152be4b48a82de4e269bfd8a9b77f80fbb4c047c60002b92e23cf29f110b59bf9e9969a56080b65530246f7382f4b0c2840b8d776789789e6140a779894de29c01177e5565ff5fc4efb1c46452e562125b783026bd9ca4eb623dd1318e108aeba20df97d58b1a00bf594bd8b1ec1aae7e2b3bb6325ca8580ca9037be6c03398b59371be6b9e99b16e816fc3dd524a8ad436cb58023c595869a08916a7467ea053c328bcca4cfd16487f3fc8741982ab78ddb72eb40e761776d49b35c0a822cd72dc87561a1d72ea0be1f8fc058b19a854f8bafe21ed7a2c9f1439dfd5f934099710621eb7135e2f06fbf9b3a75b0e238a08b65969931f0e278e61ade99f2f2539dec2c53e0fbc066663ecce
  4: (64 bytes) 0x9d26083a7abe410daeb5d99cc8ad28e578f89210ee4c9eabbf6960e8e297fbbc766426e76296debc0233cdfeae25360b921f16583c0fe4ee76e5bd73fb3963a9
]

2019-03-06 08:14:10,524 __init__.py:0058 DEBUG write message: [
  6: (1 bytes) 0x03
  3: (384 bytes) 0x6915039d4503f3c1cd8998e7c9fca768ba22b0257c3517f3176d8508b644239791d401f4abe9ded938b6abb2ba1c3670b60a0d5290f938f6404cd00f00992b59485e394d1f178915589b52806b9844a0388f568f888a35287f44e836e7ae7f01a27be7616ef083893aa38d3299f07506066fc6278152be4b48a82de4e269bfd8a9b77f80fbb4c047c60002b92e23cf29f110b59bf9e9969a56080b65530246f7382f4b0c2840b8d776789789e6140a779894de29c01177e5565ff5fc4efb1c46452e562125b783026bd9ca4eb623dd1318e108aeba20df97d58b1a00bf594bd8b1ec1aae7e2b3bb6325ca8580ca9037be6c03398b59371be6b9e99b16e816fc3dd524a8ad436cb58023c595869a08916a7467ea053c328bcca4cfd16487f3fc8741982ab78ddb72eb40e761776d49b35c0a822cd72dc87561a1d72ea0be1f8fc058b19a854f8bafe21ed7a2c9f1439dfd5f934099710621eb7135e2f06fbf9b3a75b0e238a08b65969931f0e278e61ade99f2f2539dec2c53e0fbc066663ecce
  4: (64 bytes) 0x9d26083a7abe410daeb5d99cc8ad28e578f89210ee4c9eabbf6960e8e297fbbc766426e76296debc0233cdfeae25360b921f16583c0fe4ee76e5bd73fb3963a9
]

2019-03-06 08:14:11,386 tlv.py:0117 DEBUG receiving [
  6: (1 bytes) 0x04
  7: (1 bytes) 0x02
]

2019-03-06 08:14:11,388 __init__.py:0066 DEBUG response: [
  6: (1 bytes) 0x04
  7: (1 bytes) 0x02
]

2019-03-06 08:14:11,389 __init__.py:0153 DEBUG #5 ios -> accessory: send SRP exchange request
step 5
2019-03-06 08:14:11,389 pair.py:0063 DEBUG step 5
Traceback (most recent call last):
  File "/home/robin/dev/homekit_python/homekit/pair.py", line 56, in <module>
    controller.perform_pairing(args.alias, args.device, args.pin)
  File "/home/robin/dev/homekit_python/homekit/controller/controller.py", line 318, in perform_pairing
    pairing = perform_pair_setup(pin, str(uuid.uuid4()), write_fun)
  File "/home/robin/dev/homekit_python/homekit/protocol/__init__.py", line 160, in perform_pair_setup
    error_handler(response_tlv[1][1], 'step 5')
  File "/home/robin/dev/homekit_python/homekit/protocol/__init__.py", line 43, in error_handler
    raise AuthenticationError(stage)
homekit.exceptions.AuthenticationError: step 5

@jlusiardi
Copy link
Owner

mmh just to be sure an not miss out anything, the pin code was entered with the dashes like XXX-XX-XXX?

@rgruyters
Copy link
Author

Uh, no? Should I? It doesn’t say on the back of the device.

@jlusiardi
Copy link
Owner

Oh ok, I did not put it into documentation explicitly because Apple's spec is pretty precise: It should look like 123-45-678 (which is forbidden by the spec by the way ;) ) Can you give it a try?

@jlusiardi
Copy link
Owner

https://images.ifun.de/wp-content/uploads/2019/01/mi-bedside-lamp-2-fuss.jpg shows a model with pin 38174620 which should be something like 381-74-620.

@rgruyters
Copy link
Author

Ok. Just test it on the current release 0.12.2 and works fine when I dashes.
Thanks for the help and info.

@jlusiardi
Copy link
Owner

Ok this is good news. Perhaps code should be added to prevent such an issue (at least print a warning when using the tools from this project).

65752d3 should at least improve the README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants