juanboro / cync2mqtt

Bridge Cync bluetooth mesh to mqtt
38 stars 7 forks source link

Does this work with "direct connect" bulbs? (Either the old C by GE branded ones, or the newer "Cync" branded ones) #14

Closed CaptainN closed 1 year ago

CaptainN commented 2 years ago

Hi! Thanks for your great work!

Does this work with "direct connect" bulbs? Either the old C by GE branded ones, or the newer "Cync" branded ones (all mine are Cync branded).

I've tried it, but I get a consistent set of errors:

kevin@pop-os:~$ ~/venv/cync2mqtt/bin/cync2mqtt ~/cync_mesh.yaml
2022-02-17 19:49:15,365 - cync2mqtt - INFO - Unable to connect to mesh mac: 78:6D:EB:77:46:B8
2022-02-17 19:49:17,917 - cync2mqtt - INFO - Unable to connect to mesh mac for notify: 78:6D:EB:C5:67:DB - [org.bluez.Error.NotPermitted] Write not permitted
2022-02-17 19:49:23,362 - cync2mqtt - INFO - Unable to connect to mesh mac for notify: 78:6D:EB:6B:D6:6D - [org.bluez.Error.NotPermitted] Write not permitted
2022-02-17 19:49:36,664 - cync2mqtt - INFO - Unable to connect to mesh mac: 78:6D:EB:C4:74:CA
2022-02-17 19:50:10,097 - cync2mqtt - INFO - Unable to connect to mesh mac for notify: 78:6D:EB:12:0B:F2 - [org.bluez.Error.Failed] Operation failed with ATT error: 0x0e (Connection Rejected Due To Security Reasons)
2022-02-17 19:50:22,050 - cync2mqtt - INFO - Unable to connect to mesh mac: 78:6D:EB:13:A0:B7
2022-02-17 19:50:22,152 - cync2mqtt - ERROR - No mesh network connections!

I get a similar set of errors from other laurel based solutions.

I also have an idea to integrate hass with the cloud - and i wondered what would be involved in either porting from cbyge, or writing an integration with it that goes through that, instead of through BLE mesh. Just some ideas. I'm happy to help, if I can (I'm not so familiar with Go or Python, but do plenty of other dev work, and will likely try some stuff - just don't know what yet haha.)

juanboro commented 2 years ago

I don't have any of the direct connect bulbs. The short answer is I don't think it will work. However, looking at how they work --- my suspicion is they either use Zigbee or the official Bluetooth SIG BLE mesh since they work directly with Echo hubs. If they use Zigbee - then it's just a matter of pairing to something that supports MQTT or some other protocol via that hub. BLE mesh is a little tricker -- I've been looking at this time permitting with some Sengled BLE bulbs I have. The bluez software is still somewhat primitive on support for this -- I have been able to pair and control these bulbs with the Nordic bluetooth mesh android app.

CaptainN commented 2 years ago

A different mesh tech would explain why they won't connect. I assume the "Direct Connect" bulbs are using BLE, since they require BT on your phone to set them up (but then they use wifi to be controlled through an xlink domain, except for the button battery powered Switches, which seem to pair with the bulbs directly to control them). I'm pretty sure they don't use zigbee, given the relatively low price (roughly $10 USD for a single bulb).

It's a shame GE/xlink don't provide any developer APIs for these - the light quality they put out is top notch, IMHO, compared even with much more expensive bulbs.

What would need to change to make this script work with BT SIG BLE mesh? (If it's not locked down by encryption or something.) Edit: Er, I think you explained that - bluez would need to support it. This is what I get for posting about home automation at 2am!

juanboro commented 2 years ago

Yeah - it must be BLE mesh and wifi. Telink actually has pretty good documentation on their SoCs (https://www.telink-semi.com/for-developers/). There is a ton of information on BT mesh... i.e: https://www.bluetooth.com/learn-about-bluetooth/recent-enhancements/mesh/. Yeah - the problem is bluez support is still pretty early from what I've seen. What I really want is new python script to handle the various mesh models (simple on/off, level control, etc). I haven't seen much open source out on the web at least as far as PB-GATT to do this outside of pieces in bluez meshctl (which I got simple on/off to work with a little hacking of the C source). Time permitting, I plan to try to write PB-GATT mesh model controls in python using meshctl in bluez as a how-to reference... but that's gonna take some time.

CaptainN commented 2 years ago

Sounds fun! I did just figure out they are Telink tech, by poking around with the nRF Android app. I'm starting from scratch to understand all this protocol stuff. Probably won't be much help to you. It's pretty fun to poke around though!

juanboro commented 2 years ago

I obtained some direct connect bulbs. A few initial observations:

  1. As expected, unfortunately it doesn't bridge between the legacy mesh network and the direct connect wifi network using the wifi plug hub :-(.
  2. I tried bluetooth pairing with the TuyaSmart app. It began to pair, then failed.
  3. FCC certification: https://fcc.report/FCC-ID/PUU-A19-DMFCV/
  4. SOC; https://www.realtek.com/en/products/communications-network-ics/item/rtl8720cm
juanboro commented 1 year ago

I finally had a chance to dig out my newer direct connect bulbs and try one out. I think they do work with this using telink bluetooth mesh protocol when setup with the cync app now. The one I'm trying now seems to be working (at least brightness and on/off). I'm not sure if they let you control the mesh through this though... have more experiments to do.

juanboro commented 1 year ago

I am making progress with this.

  1. Direct connect bulbs are Telink mesh bulbs. They join a telink mesh and will work with cync2mqtt indirectly if cync2mqtt connects to non direct connect BT devices.
  2. They seem to be finicky with bluez ble connect. I think (from looking at btsnoop logs) this might be because bluez is getting duplicate advertisements during discovery and mixing the mesh beacon up with the connectable advertisement.
  3. I see similar problems with gatttool connect, but can connect with bluetoothctl.

Hopefully will have this working soon.

poaudet commented 1 year ago

I have tried your integrations ,and I can tell that it is working with direct connect via Bluetooth on legacy bulb (c by ge)

juanboro commented 1 year ago

I have tried your integrations ,and I can tell that it is working with direct connect via Bluetooth on legacy bulb (c by ge)

Cool. Yeah - the "easy" way to get the DC bulbs to work appears to be just to buy an older non DC device to connect into the mesh :-).

I how have a proof of concept work-around to connect directly to the newer bulbs and receive notifications properly using bluepy (which works directly on the hci device using a custom version bluez instead of using the bluez dbus to interact with the bluez bluetooth daemon). Before getting that integrated as a backup connection method, I'm first trying to compile a complete set of details on the issue to send to the bluez developers so hopefully there will be a way to use bluez in the future to work with these.

juanboro commented 1 year ago

If necessary, this should now be able to connect directly with the direct connect bulbs by using bluepy instead of bleak to work around the bluez-dbus issues around the issues with the gatt profiles.

See: https://github.com/juanboro/cync2mqtt/blob/main/cync_mesh_example.yaml for how to set this.