custom-components / ble_monitor

BLE monitor for passive BLE sensors
https://community.home-assistant.io/t/passive-ble-monitor-integration/
MIT License
1.9k stars 246 forks source link

[New Sensor]: yeelight dimmer YLKG07YL / YLKG08YL new model YLYKQ-0004 #999

Open Blacksli opened 2 years ago

Blacksli commented 2 years ago

Sensor Description

yeelight dimmer YLKG07YL / YLKG08YL model YLYKQ-0004

Additional information

I ordered a yeelight dimmer on aliexpress on batteries YLKG07YL / YLKG08YL

The seller sent some new version

On the body of the inscription YLYKQ-0004

2022-08-29 20-55-16

image

2022-08-29 20-55-07

2022-08-29 20-55-23

I don't have a yeelight lamp, I just needed a dimmer.

When paired with BLE Monitor, it is defined as YLKG07YL / YLKG08YL but there is no data:


2022-08-29 22:07:08.868 INFO (MainThread) [custom_components.ble_monitor] Attention! Option report_unknown is enabled for Xiaomi sensors, be ready for a huge output

2022-08-29 22:07:36.418 INFO (Thread-2) [custom_components.ble_monitor.ble_parser.xiaomi] MiVer: 3, DevID: 0x3b6 : YLKG07YL/YLKG08YL,  

FnCnt: 44, Not bound, Old version certification, Capability: 0xd, No encryption, Object data: 0200020110,  

UNKNOWN dataobject in payload! Adv: 141695fe7030b6032c60f06a412d100d0200020110

Method for obtaining a key by a script:


root@debian11:/home/mark# python3 get_beacon_key.py 10:2d:41:6a:f0:60 950

Activate pairing on your '10:2D:41:6A:F0:60' device, then press Enter:

Connection in progress...

Successful connection!

Authentication in progress...

Traceback (most recent call last):

 File "/home/mark/get_beacon_key.py", line 159, in <module>

   main(sys.argv)

 File "/home/mark/get_beacon_key.py", line 155, in main

   get_beacon_key(mac, product_id)

 File "/home/mark/get_beacon_key.py", line 113, in get_beacon_key

   peripheral.writeCharacteristic(HANDLE_AUTH_INIT, MI_KEY1, "true")

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 543, in writeCharacteristic

   return self._getResp('wr')

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 407, in _getResp

   resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 368, in _waitResp

   raise BTLEGattError("Bluetooth command failed", resp)

bluepy.btle.BTLEGattError: Bluetooth command failed (code: 3, error: Attribute can't be written)

root@debian11:/home/mark# python3 get_beacon_key.py 10:2d:41:6a:f0:60 339

Activate pairing on your '10:2D:41:6A:F0:60' device, then press Enter:

Connection in progress...

Successful connection!

Authentication in progress...

Traceback (most recent call last):

 File "/home/mark/get_beacon_key.py", line 159, in <module>

   main(sys.argv)

 File "/home/mark/get_beacon_key.py", line 155, in main

   get_beacon_key(mac, product_id)

 File "/home/mark/get_beacon_key.py", line 113, in get_beacon_key

   peripheral.writeCharacteristic(HANDLE_AUTH_INIT, MI_KEY1, "true")

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 543, in writeCharacteristic

   return self._getResp('wr')

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 407, in _getResp

   resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)

 File "/usr/local/lib/python3.9/dist-packages/bluepy/btle.py", line 368, in _waitResp

   raise BTLEGattError("Bluetooth command failed", resp)

bluepy.btle.BTLEGattError: Bluetooth command failed (code: 3, error: Attribute can't be written)

Method for obtaining a key through a modified mihome (dimmer):

The device finds, loads the plugin, but then an error will appear.

There is nothing in the log folder.

Windows 10 sees the device as: yeelink.remote.seesaw

Is there any way to search for a key without a lamp and add support?

I will collect any information / dumps dump.txt

BLE advertisements

No response

MichalLytek commented 10 months ago

I have similar experience. I bought yeelight wireless dimmer to control my Zigbee bulb via HA and I don't have any Yeelight lamp to pair 😞

My tries so far:

I think there's no other possibilities to try. On the box and device it says it's YLKG07YL with Firmware: Xiaomi (MiBeacon V3) but I have same issue like with the new version 😕

ok,

i tested 👍

Method 1:

No BindKey on my ceiling lights, the remotes do not appear and yet I have many different ceiling lights and different remotes, they are all up to date)

Method 2:

Once connected and after clicking (Do Activation), no Mi Bind Key and it disconnects

Log:
17:13:57: Searching for devices
17:13:59: Connecting to: yeelink.remote.seesaw
17:14:01: Detected Mi Thermometer
17:14:01: Connected
17:14:07: Activating now, please wait...
5:14:30 PM: Disconnected.

Method 3 (vevs):

I get a 24-character key also even after a total reset of the switch (reset 20s) and a new association, the MAC address changes but the key is still 24 characters.

Method 3 (vevs dimmer):

After adding, message "unable to complete the action" and the logs are empty

Method 4:

Too long and complicated for the moment...

Are we sure it wouldn't work with a 24 character key by forcing home assistant to accept it?

I don't see what I can do now...

frickeo commented 8 months ago

Solved it!

I have had the same problems with two new YLKG07YL devices. The device type is reported to be 950, the get_beacon_key.py got me a 24 character beacon key but version byte in the data said version 5. There were eight hex characters missing.

Brute forcing the missing eight characters on a GPU finally got me the answer: I had two append eight f characters to the end of the beacon key to enable the decryption. That worked for both of my devices.

With that extended beacon key the integration was successful: grafik

Ernst79 commented 8 months ago

wow, great finding. I'll add that as a tip in the FAQ.

Blacksli commented 8 months ago

Solved it!

I have had the same problems with two new YLKG07YL devices. The device type is reported to be 950, the get_beacon_key.py got me a 24 character beacon key but version byte in the data said version 5. There were eight hex characters missing.

Brute forcing the missing eight characters on a GPU finally got me the answer: I had two append eight f characters to the end of the beacon key to enable the decryption. That worked for both of my devices.

It works! Thank you! I got the key from the script and added 8 f characters to the end image

image

genex89 commented 8 months ago

I receive this error, can you help me?

python3 get_beacon_key.py XX:XX:XX:XX:XX:XX 950 Activate pairing on your XX:XX:XX:XX:XX:XX device, then press Enter: Connection in progress... Successful connection! Authentication in progress... Traceback (most recent call last): File "/home/pi/get_beacon_key.py", line 159, in main(sys.argv) File "/home/pi/get_beacon_key.py", line 155, in main get_beacon_key(mac, product_id) File "/home/pi/get_beacon_key.py", line 113, in get_beacon_key peripheral.writeCharacteristic(HANDLE_AUTH_INIT, MI_KEY1, "true") File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 543, in writeCharacteristic return self._getResp('wr') File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 368, in _waitResp raise BTLEGattError("Bluetooth command failed", resp) bluepy.btle.BTLEGattError: Bluetooth command failed (code: 3, error: Attribute can't be written)

Il giorno lun 22 gen 2024 alle ore 23:37 Blacksli @.***> ha scritto:

Solved it!

I have had the same problems with two new YLKG07YL devices. The device type is reported to be 950, the get_beacon_key.py got me a 24 character beacon key but version byte in the data said version 5. There were eight hex characters missing.

Brute forcing the missing eight characters on a GPU finally got me the answer: I had two append eight f characters to the end of the beacon key to enable the decryption. That worked for both of my devices.

It works! Thank you! I got the key from the script and added 8 f characters to the end image.png (view on web) https://github.com/custom-components/ble_monitor/assets/74769766/684859f4-271d-4042-b8c5-d72400f0f313

image.png (view on web) https://github.com/custom-components/ble_monitor/assets/74769766/7ed51fc2-4de6-4dba-b0d8-45e07a4cca3c

— Reply to this email directly, view it on GitHub https://github.com/custom-components/ble_monitor/issues/999#issuecomment-1904951794, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBGHU5K34YSAYHL7AWCJCTYP3S3FAVCNFSM5766CCZKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJQGQ4TKMJXHE2A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Ing Gennaro Mellone

xekil commented 8 months ago

Solved it! I had two append eight f characters to the end of the beacon key to enable the decryption. That worked for both of my devices.

@frickeo Great thank you very much, I confirm that it works, I will be able to take my switches out of the cupboard!!!!

itsmartinho commented 8 months ago

Solved it!

I have had the same problems with two new YLKG07YL devices. The device type is reported to be 950, the get_beacon_key.py got me a 24 character beacon key but version byte in the data said version 5. There were eight hex characters missing.

Brute forcing the missing eight characters on a GPU finally got me the answer: I had two append eight f characters to the end of the beacon key to enable the decryption. That worked for both of my devices.

With that extended beacon key the integration was successful: grafik

OMG, this is so unexpected. I asked for help on this a LONG TIME ago and out of nowhere reading a "SOLVED IT!" it's such a cool and geeky feeling. Very excited to try to out when I get home. So basically the trick is to add 8 f characters to the end of the beaconKey?

Ernst79 commented 8 months ago

Yes, it seems so. I added the solution in the FAQ, but please let us know if it worked for you. Big thanks for @frickeo for solving this!!!

frickeo commented 8 months ago

@genex89 : You are using an old version of the get_beacon_key.py script that was based on the bluepy package. Please update your script, the new version is using the bleak package (see https://github.com/custom-components/ble_monitor/issues/913)

genex89 commented 8 months ago

@genex89 : You are using an old version of the get_beacon_key.py script that was based on the bluepy package. Please update your script, the new version is using the bleak package (see #913)

Hi, I used the script linked in the FAQ. However, following your instructions I was able to use the version of the script contained in the latest release of the custom component and everything worked. I managed to correctly integrate the dimmer into the home assistant. I don't know how to thank you, now I can finally take it out of the box. Thank you very much

itsmartinho commented 8 months ago

Getting this error:

PS C:\Users\timar\Downloads> python3 get_beacon_key.py F8:24:41:C4:96:96 950
Traceback (most recent call last):
  File "C:\Users\timar\Downloads\get_beacon_key.py", line 22, in <module>
    from bleak import BleakClient
ModuleNotFoundError: No module named 'bleak'
Ernst79 commented 8 months ago

The error says it all, install bleak

https://bleak.readthedocs.io/en/latest/

itsmartinho commented 8 months ago

Thank you buddy.

What am I doing wrong now? macadress python_notfound

Ernst79 commented 8 months ago

Is your Bluetooth adapter enabled on your windows PC? Can it be accessed by python? Hard to say what is wrong. Do you have access to a Linux system?

MichalLytek commented 8 months ago

@itsmartinho I had same issue on my Mac. Couldn't resolve it, so I've returned the yeelight dimmer.

itsmartinho commented 8 months ago

Is your Bluetooth adapter enabled on your windows PC? Can it be accessed by python? Hard to say what is wrong. Do you have access to a Linux system?

Now I'm getting this: image

I'm using Home Assistant Terminal AND also trying on my laptop, using the file directly.

frickeo commented 8 months ago

@itsmartinho You can try the following simple python script to check the connection:

import asyncio
from bleak import BleakClient

address = "F8:24:41:C4:96:96"

async def main():
    client = BleakClient(address)
    try:
        await client.connect()
        for service in client.services:
            print(service)
    except Exception as e:
        print(e)
    finally:
        await client.disconnect()

asyncio.run(main())

After starting the script you have to push the little pairing button at the top side of the dimmer, until the the little LED at the bottom starts blinking.

Here is the output of the script on my machine (Windows 10 with git bash, Python 3.12.0):

$ python connecting.py
00001800-0000-1000-8000-00805f9b34fb (Handle: 1): Generic Access Profile
00001801-0000-1000-8000-00805f9b34fb (Handle: 8): Generic Attribute Profile
0000180a-0000-1000-8000-00805f9b34fb (Handle: 12): Device Information
0000180f-0000-1000-8000-00805f9b34fb (Handle: 15): Battery Service
00010203-0405-0607-0809-0a0b0c0d1912 (Handle: 19): Unknown
0000fe95-0000-1000-8000-00805f9b34fb (Handle: 23): Xiaomi Inc.
00000100-0065-6c62-2e74-6f696d2e696d (Handle: 45): L2CAP
frickeo commented 8 months ago

@itsmartinho Your error message seem to be same as in https://github.com/custom-components/ble_monitor/issues/1281.

It might be that your dimmer is still paired to some other computer/service/program. Try to disconnect that. If disconnecting is not possible, you may try a hard reset of the dimmer (press the pairing button longer then 20 seconds). But beware, that a hard reset will give you a new mac address.

itsmartinho commented 8 months ago

How do I get the new address? It still shows the same Bluetooth Address on Home Assistant and I've tried that. And your script isn't returning anything, I've sent it to HA and I'm executing it there @frickeo

@ edit Also, thank you for the help so far! That sounded really harsh/ungrateful but not on purpose lol

frickeo commented 8 months ago

On the top of the dimmer is a small pairing button. You have to press for 3 seconds on it and the LED on the bottom of the front panel begins to blink. Now the dimmer is in pairing mode and the script should give you some data.

If you continue to press the small button for another 20 seconds or so, the LED will do a double blink and is then going dark. Now your dimmer device has got another MAC. To get that MAC, I am using the web site https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html in the chrome browser (firefox will not work). Make sure to disconnect. If you got the new MAC, try it out with the script.

Please be sure to press down the small button again until the small LED blinks if running anyone of both scripts.

itsmartinho commented 8 months ago

20:33:45: MiVer3, DevID: 0x03B6-YLKG07YL/YLKG08YL, FnCnt: 1, CtrID: 0x3251 Not bound, Request APP to register and bind, Old version certification, Request APP to register and bind, MAC: F82441C49696, DataID: 0x0002 Value: 0x1001

Also, screenshot of the error I'm getting on the terminal by using: python3 get_beacon_key.py.5 F8:24:41:C4:96:96 950 now. It's the device in pair mode as advised. ( https://github.com/custom-components/ble_monitor/blob/master/custom_components/ble_monitor/ble_parser/get_beacon_key.py )

I don't know how to use the script you gave me, can you please elaborate if isn't asking for too much?

errro3

frickeo commented 8 months ago

That is not the script. You have to save and execute the raw file and not its presentation in the browser.

Amnezik commented 5 months ago

Hello everyone,

I post here because lot of people having trouble with their YLKG07YL dimmer, and I was like you, been nuts to have beacon_key or adding it in home assistant... take me hours of digging to fix it !

Here what i've test, done, and check :

First of all, recover the MAC adresse of the device with phone app for me "A4:C1:38:35:4F:62"

image

Be carefull, pressing the pariring button during 20s will change this MAC address

After that use the method 5 from Passive BLE integration FAQ :

5. get_beacon_key python script

https://home-is-where-you-hang-your-hack.github.io/ble_monitor/faq#how-to-get-the-mibeacon-v2v3-encryption-key

In my case :

wget https://raw.githubusercontent.com/custom-components/ble_monitor/master/custom_components/ble_monitor/ble_parser/get_beacon_key.py
apt-get install python3-pip libglib2.0-dev
pip3 install bleak asyncio
python3 get_beacon_key.py <A4:C1:38:35:4F:62> <950>

Be sure to use a relevant linux, bluetooth and python configuration

If you can't connect to your device or if it's say "Disconnected!", try this before launching the script :

hciconfig hci0 up

After that you will have something like this :

notifyData: 'ce6b3f6f42adc97421cf015f' cipheredRes: '00a486f5ff013ed04322f4e4' randomToken: '00a486f5ff013ed04322f4e4' Successful authentication! beaconKey: 'acec46f9b751b694e8167d02' firmware_version: '2.0.0_0004

Now you have you beacon_key, you can configure the BLE device to HASS on configuration.yaml

But cherry on the cake you have to add eight f to the end of the encryption_key

ble_monitor:
  discovery: true
  devices:
    - mac: 'A4:C1:38:35:4F:62'
      name: 'dimmer_yeelight'
      encryption_key: 'acec46f9b751b694e8167d02ffffffff'
      reset_timer: 1

https://github.com/custom-components/ble_monitor/issues/999#issuecomment-1904878452

Hope it will help ! Thanks to [frickeo]