Feature request: Support for Xiaomi/Yeelight BLE Candela

Any hope of getting support for the Xiaomi/Yeelight Ambiance Candela? It’s a mesh BLE device that works with the Yeelight app. It’s a fairly cool mesh BLE light - would love to get it working w/ MQTT. I found a github repository where someone got it working with Python: GitHub - rytilahti/python-yeelightbt: Python library for Yeelight's bedside (btle) and candela lamps

Thanks!

Hello,

You could try first to command it directly with the service / characteristic / value like below:

If you find the good trio you should be able to control the light, we can integrate it after into OMG.

That’s a great suggestion. Thank you. I’ll start there.

Follow up - is this the best way to start reverse engineering any BLE device?

You can take the infos (service/char/value) from existing program like below:

And see if you succeed controlling

Also helpful for the various ON, OFF, INTENSITY, FLICKER command values

I am fairly new to BLE and OMG, i started using it just to use it mainly for 2 yeelight candelas. What i achieved so far:

{
  "ble_write_address":"XX:XX:XX:XX:XX:XX",
  "ble_write_service":"0000fe87-0000-1000-8000-00805f9b34fb",
  "ble_write_char":"AA7D3F34-2D4F-41E0-807F-52FBF8CF7443",
  "ble_write_value":"434002",
  "value_type":"HEX",
  "ttl":1,
  "immediate":true }

Change “XX:XX:XX:XX:XX:XX” with your candela BLE address.
“ble_write_value”:“434002” Turns off the candela.
“ble_write_value”:“434001” Turns on the candela.
“ble_write_value”:“4342XX” Adjusts the brightness of the candela between “01-64” hex.

This is for pairing:

{
  "ble_write_address":"XX:XX:XX:XX:XX:XX",
  "ble_write_service":"0000fe87-0000-1000-8000-00805f9b34fb",
  "ble_write_char":"AA7D3F34-2D4F-41E0-807F-52FBF8CF7443",
  "ble_write_value":"4367XXXXXXXXXXXX",
  "value_type":"HEX",
  "ttl":1,
  "immediate":true }

Although i could not confirm if i made the pairing right since i do not know how to read incoming message from BLE devices, either success of failure is not confirmed. I also want to read the status but i do not know how to subscribe to candela NOTIFY_UUID with MQTT, nor could i find any document or sample here.

1 Like

Thanks @febalci for sharing your details for the Yeelight candelas controls.

Pairing and subscribing to NOTIFY is not currently possible through OMG. Only the above WRITE command and the READ command are available, which connect to the device and get/set the service/characteristics available.

Thanks @febalci for providing the information, my Yeelight BLE Candela is a small different with yours, my service is ‘FE87’.

I’m using hombridge-mqttthing to send mqtt message to OMG:

{
  "accessories": [{
    "accessory": "mqttthing",
    "type": "lightbulb-OnOff",
    "name": "Yeelight烛光氛围灯",
    "manufacturer": "Yeelight",
    "serialNumber": "XXXXXXXXXXXX",
    "model": "yeelight_ms",
    "url": "mqtt://localhost:1883",
    "username": "homebridge",
    "password": "",
    "topics": {
        "setOn": {
            "topic": "home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config",
            "apply": "return JSON.stringify({ ble_write_address: 'XX:XX:XX:XX:XX:XX', ble_write_service: 'FE87', ble_write_char: 'AA7D3F34-2D4F-41E0-807F-52FBF8CF7443', ble_write_value: message ? '434001' : '434002', value_type: 'HEX', ttl: 1, immediate: true })"
        },
        "setBrightness": {
            "topic": "home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoBT/config",
            "apply": "return JSON.stringify({ ble_write_address: 'XX:XX:XX:XX:XX:XX', ble_write_service: 'FE87', ble_write_char: 'AA7D3F34-2D4F-41E0-807F-52FBF8CF7443', ble_write_value: (parseInt('434200', 16) + message).toString(16), value_type: 'HEX', ttl: 1, immediate: true })"
        }
    }
  }]
}

It’s working with about 2 seconds latency, and the problem is, it’s not 100% success. Sometime will failed and OMG & Homebridge doesn’t know it is failed.

I tried change ttl to 5, not sure if it is useful.

And the latency, is there any solution to solve this? Can I make OMG to keep connection with the Yeelight Candela, but not with other sensors? Maybe keep connection can shorten the latency ?

Hey @0x5e, glad that it worked out, in some way…

Actually mine is called the Yeelight Ambiance, but i think candela and the ambiance s the same product. So, mine also works with FE87 instead of “0000fe87-0000-1000-8000-00805f9b34fb”.

I am sending the mqtt message with MQTTExplorer for test purposes. The latency is not instant but about 1 second. I am not sure if it makes any difference but these devices work as “mac_type”: 0, so you can also add this in your “apply” message. I have no idea what ttl does since i am a total newbie on OMG.

I checked out BLE properties with LightBlue on IOS. The interestğng thing is whenever i connect to yl_candela with LightBlue, the connection drops every 30 secs or so. Then you have to connect it again. I honestly don’t know if all BLE acts this way or it is only candela. It might be because it is not paired; or it might be that candela rests its advertisement every 30 secs.

In fact, the command returns back a success ack:

{"id":"XX:XX:XX:XX:XX",
"service":"0xfe87",
"characteristic":"aa7d3f34-2d4f-41e0-807f-52fbf8cf7443",
"write":"434002",
"success":true}

If the command fails, it returns “false”.

As @DigiH stated in his message, there is no way to subscribe to NOTIFY; it normally provides all status like on/off and brightness value.

Thanks @febalci , I’m new in OMG too. Where did you get the success ack, from mosquitto_pub? I’m curious why it can receive success ack, I’ve never seen any MQTT client can do this before. I didn’t see the ack from MQTTExplorer too.

To compare with, the Yeelight App can control almost without any latency. And no 30 secs drop issue.

Hey @0x5e, I am using MQTT Explorer; whenever i send a message to candela from “home/OpenMQTTGateway/commands/MQTTtoBT/config”, i check this out “home/OpenMQTTGateway/BTtoMQTT/XXXXXXXXX(candela)”.
Before sending any commands, the yl_candela message there is only RSSI etc. But when you send an on/off or brightness command the message in “home/OpenMQTTGateway/BTtoMQTT/XXXXXXXXX(candela)” changes to the sample i provided in my previous message. So it is technically not an ACK but a response from the candela.

Also, for the latency, if i send the message directly from IOS Lightblue (without MQTT etc, just direct bluetooth transfer command) the latency is close to 0 secs. That means, the route of message from MQTTExplorer to MQTT Server to OpenMQTTGateway to deserialize and send the command to candela, takes more than 1 second as far as i understand.

Thanks! That really answers my questions which may not clearly written in the docs :slight_smile:
I’ve seen the response now, however it will be overwritten after another advertisement…

Edit: my latency and low success rate maybe is the long distance, after moving the device, now it response in about 1 second an almost succeed every time.

And I removed the brightness, at many time, when I modify the brightness, HomeKit will publish a ‘On’ command in addition, which will override the brightness command and decrease the stability.

The tip at

Also might not some/all of the service/chars also be READable, to get the status when wanted instead of a notification? Maybe as an additional check to get the status when the immediate response message is not available?

Are you using HomeKit with Homebridge and which Plugin? All up to date?

I also used to have this behaviour, but it was fixed in a recent update.

Yeelight BLE Candela’s status seems not available to read or notify, tested on iOS Lightblue, get constant value “0x43ff00000…00000” forever.
I’m using HomeKit with Homebridge and “homebridge-mqttthing” plugin, set command works well in most times, get command not implemented so it only display the status from Homebridge’s accessory cache.

The brightness issue is not a big problem, just because using “homebridge-mqttthing” to read and write has some limitations so it’s not very easy to handle :slight_smile: So it’s not the issue for OMG, it’s for plugin I think.

1 Like

Well, it wasn’t that recent, and it was for the homebridge-openhab2-complete Homebridge plugin, which I am using, but this commit addressed and fixed the issue on this plugin side by allowing Homekit to only "sendOnOnlyWhenOff": "true"

with related issues, like

So might be a possible similar solution for the homebridge-mqttthing plugin.

1 Like

Wow, thanks for the information!