sputnikdev / eclipse-smarthome-bluetooth-binding

Eclipse SmartHome Bluetooth Binding
46 stars 10 forks source link

Test and add support for Yeelight Bluetooth Dimmer #86

Open BMOtheConsole opened 4 years ago

BMOtheConsole commented 4 years ago

I bought this Dimmer Switch from Yeelight (https://tinyurl.com/y48jvmne) and would like to implement this to Openhab with your binding. How can i contribute and help to add this thing?

meccup commented 4 years ago

Hi @BMOtheConsole, this is an interesting device. Afaik it's got nice design and potentially good functionality. I ordered 220v version a while ago, but I burnt it straight away. There is not any documentation/manual on how you install/connect it, so I assumed it works like MiLight switches, e.g. directly connect power like it is normal appliance. I did that and it burned straight away with a magic smoke.

Anyways, I think what's burned is only AC-DC converter, so 3.3v logic should be still working I hope. So I should be able to help you.

First of all you will need to identify all GATT services and characteristics it has by using something like Nordic NRF Toolbox android app. Also try to identify what characteristics get changed when you interact with it.

meccup commented 4 years ago

You may also use the binding for identifying GATT characteristics by setting "GATT serivices and characteristics parsing strategy" to All binary:

image

Then find your device in the inbox, add it and enable "Connection control". If this device does not have any authentication requirements, you should be able to see all channels. Make a screenshot and post it here. Also try to interact with the device and notice what values get changed.

BMOtheConsole commented 4 years ago

Here is the Screenshot: Yeelight Dimmer The Last Value did change ones, but no anymore. I did every possible Movement i could with the Dimmer Switch.

meccup commented 4 years ago

It clearly shows that your device is not connected ("Connected" channel), that's why you do not see any updates.

Does it get enabled/disabled periodically (the "Connected")?

BMOtheConsole commented 4 years ago

I'm new to this stuff so i hope these Screenshot are helpful. If you need more Informations or Screenshots just tell me. I will do my best to provide it and hopefully learn a bit in the Progress

I don't know if this is helpful too, but here is the Screenshot from the APP: unnamed

BMOtheConsole commented 4 years ago

It clearly shows that your device is not connected ("Connected" channel), that's why you do not see any updates.

Does it get enabled/disabled periodically (the "Connected")?

EDIT: I does show "Connected" until i push the Button on the Dimmer Switch, than i have to push the Pair Button again

The "Connected" Channel is showing as OFF, but the Last Value is still updating if i turn or push the Button to wat looks like partially Random HEX-Values. Here is a List of Moves i made and the Value it changed to.

[58, 30, b6, 03, ee, 78, 6f, c2, 41, 24, f8, ce, 10, 0b, 0c, 5f, 12, 00, 00, 00, c6] Turn Left [58, 30, b6, 03, ef, 78, 6f, c2, 41, 24, f8, 24, 90, e5, 15, 57, 39, 00, 00, 00, 30] Turn Right [58, 30, b6, 03, f0, 78, 6f, c2, 41, 24, f8, ab, b1, 2f, 58, e5, ae, 00, 00, 00, 21] Button Push [58, 30, b6, 03, f4, 78, 6f, c2, 41, 24, f8, f4, 14, 3d, c7, bc, 1c, 00, 00, 00, 04] Button Push [58, 30, b6, 03, f6, 78, 6f, c2, 41, 24, f8, b3, 14, c9, e6, d5, 00, 00, 00, 00, e2] Turn Right [58, 30, b6, 03, f7, 78, 6f, c2, 41, 24, f8, 09, a8, 7d, e8, 7e, dd, 00, 00, 00, e5] Turn Left

meccup commented 4 years ago

Right, strange behaviour re connect/disconnect. Are there any error logs in OH?

When you use nordic app and connect to your device, does it stay connected all the time? If so, could you please take the device close to your BT adapter that is used by OH? It might be that it is too far and that's why you get sporadic disconnections.

Anyways could you please be more specific. Those 6 readings, are they from which channel (characterisitc)?

From what I can see, those values look very similar to Xiaomi devices, we should be able to decode it.

Please also do another separate test. In your nordic app, go to Scanner tab, find your device there, tap on it (do not tap "Connect"), then tap on "MORE". You should see something like that:

image

There must be that FE95 service somewhere there (check also "FLAGS & SERVICES" tab). When you find it, observe values that get changed when you interact with the device.

meccup commented 4 years ago

Just so you know, this is what I see from your examples:

[58, 30, - flags and version b6, 03, - product ID ee, - frame counter (should increment by 1) 78, 6f, c2, 41, 24, f8, - device MAC address the rest is depended on the flags and version bytes (this is what we need to decode based on interaction with your device, should be fairy easy) 10, 0b, 0c, 5f, 12, 00, 00, 00, c6]

In that remaining part, there should be a flag (a few bytes) that specifies what event it is (e.g. dimmer, colour, push button etc). Do some experiments and try to match a few readings and identify event. There could be much more events generated, e.g. not only triggered by you (those are some system events) so you will have to capture quite a few readings.

meccup commented 4 years ago

After that flag, there should be actual data.

vkolotov commented 4 years ago

Not sure how proficient you are in software engineering, anyways here is where the structure defined: https://github.com/sputnikdev/bluetooth-gatt-parser/blob/0e8f1f74bbe501abf7333defae9864de04848fda/src/main/resources/gatt/characteristic/com.xiaomi.bluetooth.characteristic.mi_service.xml

And actual data payload (this is what we will need to extend):

https://github.com/sputnikdev/bluetooth-gatt-parser/blob/0e8f1f74bbe501abf7333defae9864de04848fda/src/main/resources/gatt/characteristic/com.xiaomi.bluetooth.characteristic.events_data.xml

vkolotov commented 4 years ago

Further to it. Those readings that you posted above (with left, right etc), those ones are encrypted, this would be problematic to decode. Where did you get those (in the binding or in the app, please give a complete description)?

These are two first bytes:

0b1011000 0x58 
0b0110000 0x30

Combined together: 01100001011000 Which translates (according to mi_services.xml, read bits/flags from right to left) to: 0 - NewFactory (not sure what's that) 0 - Connected 0 - Central 1 - Encrypted 1 - MacAddressPresent 0 - CapabilityPresent 1 - EventPresent 0 - CustomDataPresent 0 - SubTitle 0 - BindingFrame

Another screenshot that you attached of the binding contains a reading that is NOT encrypted, this one we should be able to read easily:

Raw: [51, 32, b6, 03, 01, 78, 6f, c2, 41, 24, f8, 02, 00, 02, 01, 10]

First two bytes

0b1010001 0x51 
0b0110010 0x32

combined together:

01100101010001

Which is: 1 - NewFactory (not sure what's that) 0 - Connected 0 - Central 0 - Encrypted 1 - MacAddressPresent 0 - CapabilityPresent 1 - EventPresent 0 - CustomDataPresent 1 - SubTitle 0 - BindingFrame

Which says that it is not encrypted and the event is present. The even goes after MAC address.

Here are some details:

Raw:

[
51, 32, - flags
b6, 03, - product ID
01, - frame counter
78, 6f, c2, 41, 24, f8, - mac address
02, - event ID (e.g. dimmer, colour, button etc)
00, - unknown
02, - event (not sure what's that)
01, 10 - actual data (e.g. for dimmer it would be 0 to 100% I think)
]

Please disable "Connection control" in the binding and observe how that FE95 channel changes, try to map the values to actual interaction with the device. More importantly try to match event ID byte. This will tell you what even it is, e.g. dimmer, colour etc...