I like the solution for the lampsmart pro light in ESPhome. I have at home a combination of lampsmart pro and zhi jia lamps. I found there is an ESP32 solution for the zhi jia lamps : reverieline/bler: ESP32 BLE remote for ZhiJia (ZhiGuang) LED controller (github.com). Is it possible to add this to your esphome solution as well?
Hi jymbo. I got to the same outcome. Hitting pair in the Android app returns a different prefix. I was wondering if you ever got it working. Thanks.
Adv data: 02.01.01.1B.03.77.F8.B6.5F.2B.5E.00.FC.31.51.CC… (31)
02 01 02 1b 03 77 f8 b6 5f 2b 5e 00 fc 31 51 cc b5 32 07 2e 4a 2b fc 8c e5 f4 13 47 bb e1 2d
Not as such. I don’t have as much time to tinker as I’d like, or a decent laptop with bluetooth that I can debug from, so it’s a case of update, reflash, change rooms, try some stuff, come back, check logs, fiddle with code, update… very tedious. I’d love to have them integrated but it’s not a priority in my life.
I did see something in my last test that looked a helluvalot like a rolling counter at play (ie: after testing having to then press buttons multiple times before the lights actually respond), but I only have anecdotal evidence for that, and it could just as well be BLE flakiness.
I have a light with a remote that works with the LampSmart Pro app. I also ordered another Zhi Guang controller with remote from China and was able to link its remote to my old lamp. And by the way, the Zhi Guang app also links to my old lamp, which works with the LampSmart Pro. But the component for ESP cannot be paired, pairing does not occur when calling the service, the light does not blink… Maybe you need to somehow read the commands sent from the remote control during pairing? I can test, but I don’t know how… I also tried the project GitHub - reverieline/bler: ESP32 BLE remote for ZhiJia (ZhiGuang) LED controller it also did not work for me.
@aronsky this is brilliant! to imagine that only a few days ago i was thinking about how i could get this damn light automated - then i stumble upon this and i was up and running in no time! thank you.
Glad it works for you!
@aronsky Thank you for the code. I just bought a lamp, and with your code, I can now control it. However, I had to modify the code in two places. First, I wanted to keep my original remote, so I needed to use the same identifier as the remote. I was able to reverse-engineer it. Maybe a feature could be to use an identifier specified from the esphome code with the yaml file, instead of cafebabe or HA thing. Second, my brightness and color settings are not working with the original code. The difference is that my lamp uses 0x4000 as _20 (in your code) instead of 0. Probably this could be set from the yaml as well. Thanks again you sharing your code!
@gume, you’re welcome! I think that manually specifying the identifier is a good feature to have, you can open a PR if you have the code ready. As for the value of _20, I can’t test right now whether it breaks connectivity with my lamp or not - if you can make this field configurable via YAML as well, that’ll be great.
Hello there, I realize it’s been many months back since @aronsky gave the code for ble/java from the native app. So I’m wondering, have you attempted to code for the fan control and succeeded, or did you encounter too many problems and move on? As I am now trying to get Alexa to control the lamp+fan unit by voice, I’d greatly appreciate any pointers you might have about doing the coding for the fan controls through an esp32 device. Thank you
Sorry, but I don’t have a fan to work with, so can’t help develop and/or test this. However, I assume that it works similarly to the lights - in which case, you’ll have to decompile the APK and disassemble the library bundled within to figure out the payloads sent to the fan (that’s the process I went through to get the payloads for the lights).
Hi Lev @aronsky,
I just searched, found, and implemented your component after buying a lamp that uses a Smart Pro BLE controller. Works like a charm right out of the box!
Just wanted to send out a big THANK YOU for the work and love you have put into this. Is there some “buy me a coffee” link to send a little reward?
Cheers, Jörg
Is there anything you can do to help me make a list of the BLE commands? I’m struggling to read the Java code and the different codes… I have 2 of these fans, the light control works already, but I need the codes/commands for the fan on/off, direction and speed settings at minimum to be useful.
I can try and make the modifications to your component and add a ‘lampsmart_pro_fan’ component. As long as I have the codes/commands to send, I can do the trial and testing.
If required I can even give you access to the local environment to allow you some testing and probing.
Unfortunately, it’s not a quick task, it requires more time than I have on my hands.
Dear @aronsky, thank you very much for your development.
I have been waiting for this integration for about almost 4 years ))
But so far I have not been able to test it.
A week ago after I saw this component I immediately tried it on the board I had.
The board labeled ESP-WROOM-32, but apparently this board is not compatible with this component ((.
The first time I tried using the esp-idf framework, but an error occurred when compiling.
The configuration is the simplest:
Summary
esphome:
name: estaresble
friendly_name: estaresble
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ota:
- platform: esphome
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Estaresble Fallback Hotspot"
password: "xxxxxxxxxxxxxxxx"
captive_portal:
external_components:
# shorthand
source: github://aronsky/esphome-components
light:
- platform: ble_adv_light
type: lampsmart_pro
name: Estares BLE
duration: 800
default_transition_length: 0s`
Such an error:
Summary
INFO ESPHome 2024.6.1
INFO Reading configuration /config/esphome/estaresble.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing estaresble (board: esp32doit-devkit-v1; framework: espidf; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- framework-espidf @ 3.40407.240606 (4.4.7)
- tool-cmake @ 3.16.4
- tool-ninja @ 1.7.1
- toolchain-esp32ulp @ 2.35.0-20220830
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Reading CMake configuration...
Generating assembly for certificate bundle...
Dependency Graph
|-- noise-c @ 0.1.4
Compiling .pioenvs/estaresble/src/esphome/components/api/api_connection.o
Compiling .pioenvs/estaresble/src/esphome/components/api/api_frame_helper.o
Compiling .pioenvs/estaresble/src/esphome/components/api/api_pb2.o
Compiling .pioenvs/estaresble/src/esphome/components/api/api_pb2_service.o
Compiling .pioenvs/estaresble/src/esphome/components/api/api_server.o
Compiling .pioenvs/estaresble/src/esphome/components/api/list_entities.o
Compiling .pioenvs/estaresble/src/esphome/components/api/proto.o
Compiling .pioenvs/estaresble/src/esphome/components/api/subscribe_state.o
Compiling .pioenvs/estaresble/src/esphome/components/api/user_services.o
Compiling .pioenvs/estaresble/src/esphome/components/binary_sensor/automation.o
Compiling .pioenvs/estaresble/src/esphome/components/binary_sensor/binary_sensor.o
Compiling .pioenvs/estaresble/src/esphome/components/binary_sensor/filter.o
Compiling .pioenvs/estaresble/src/esphome/components/ble_adv_light/ble_adv_light.o
Compiling .pioenvs/estaresble/src/esphome/components/ble_adv_light/lampsmart_pro.o
src/esphome/components/ble_adv_light/lampsmart_pro.cpp: In function 'void esphome::bleadvlight::ble_whiten(uint8_t*, uint8_t, uint8_t, uint8_t)':
src/esphome/components/ble_adv_light/lampsmart_pro.cpp:68:44: error: suggest parentheses around '+' in operand of '&' [-Werror=parentheses]
buf[i] ^= XBOXES[(seed + i + 9) & 0x1f + (salt & 0x3) * 0x20];
~~~~~^~~~~~~~~~~~~~~~~~~~~
src/esphome/components/ble_adv_light/lampsmart_pro.cpp: In member function 'virtual void esphome::bleadvlight::LampSmartProLight::send_packet(uint8_t, uint8_t*)':
src/esphome/components/ble_adv_light/lampsmart_pro.cpp:104:4: warning: missing initializer for member 'esphome::bleadvlight::adv_data_t::<unnamed struct>::crc16' [-Wmissing-field-initializers]
}};
^
Compiling .pioenvs/estaresble/src/esphome/components/ble_adv_light/msc26a.o
src/esphome/components/ble_adv_light/msc26a.cpp: In function 'unsigned char* stage2(unsigned char*, unsigned int, unsigned int)':
src/esphome/components/ble_adv_light/msc26a.cpp:156:32: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uVar4 & 2 | (uVar4 & 1) << 2 | (uVar4 & 0xff) >> 2 & 1)
~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:156:77: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uVar4 & 2 | (uVar4 & 1) << 2 | (uVar4 & 0xff) >> 2 & 1)
~~~~~~~~~~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:155:36: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uVar4 >> 3 & 1 |
~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:154:44: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
((uVar4 & 0xff) >> 4 & 1 |
~~~~~~~~~~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:153:34: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uVar4 >> 5 & 1 |
~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:152:33: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uint8_t)((uVar4 >> 6 & 1 |
~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp:151:33: error: suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]
(uint8_t)(uVar4 >> 7) & 1 |
~~~~~~~~~~~~~~~~~~~~~~^~~
src/esphome/components/ble_adv_light/msc26a.cpp: In function 'void whitening_encode(unsigned char*, int, unsigned int*)':
src/esphome/components/ble_adv_light/msc26a.cpp:232:49: error: suggest parentheses around arithmetic in operand of '^' [-Werror=parentheses]
iVar4 += (uVar2 ^ bVar1 >> (uVar3 & 0xff) & 1) << (uVar3 & 0xff);
~~~~~~~~~~~~~~~~~~~~~~~~^~~
cc1plus: some warnings being treated as errors
*** [.pioenvs/estaresble/src/esphome/components/ble_adv_light/msc26a.o] Error 1
cc1plus: some warnings being treated as errors
*** [.pioenvs/estaresble/src/esphome/components/ble_adv_light/lampsmart_pro.o] Error 1
========================= [FAILED] Took 116.01 seconds =========================
Then I tried the configuration using the arduino framework.
The installation was successful on the esp module, but when the pairing service was called, pairing did not occur. The following error appears in the board log:
Summary
INFO ESPHome 2024.6.1
INFO Reading configuration /config/esphome/estaresble.yaml...
INFO Starting log output from 192.168.31.231 using esphome API
INFO Successfully connected to estaresble @ 192.168.31.231 in 0.110s
INFO Successful handshake with estaresble @ 192.168.31.231 in 0.143s
[23:20:19][I][app:100]: ESPHome version 2024.6.1 compiled on Jun 21 2024, 01:13:28
[23:20:19][C][wifi:599]: WiFi:
[23:20:19][C][wifi:427]: Local MAC: 10:06:1C:A6:A2:E0
[23:20:19][C][wifi:432]: SSID: [redacted]
[23:20:19][C][wifi:435]: IP Address: 192.168.31.231
[23:20:19][C][wifi:439]: BSSID: [redacted]
[23:20:19][C][wifi:440]: Hostname: 'estaresble'
[23:20:19][C][wifi:442]: Signal strength: -44 dB ▂▄▆█
[23:20:19][C][wifi:446]: Channel: 6
[23:20:19][C][wifi:447]: Subnet: 255.255.255.0
[23:20:19][C][wifi:448]: Gateway: 192.168.31.1
[23:20:19][C][wifi:449]: DNS1: 192.168.31.1
[23:20:19][C][wifi:450]: DNS2: 0.0.0.0
[23:20:19][C][logger:185]: Logger:
[23:20:19][C][logger:186]: Level: DEBUG
[23:20:19][C][logger:188]: Log Baud Rate: 0
[23:20:19][C][logger:189]: Hardware UART: UART0
[23:20:19][C][ble_adv_light:033]: BleAdvLight 'Estares BLE'
[23:20:19][C][ble_adv_light:034]: Cold White Temperature: 167.000000 mireds
[23:20:19][C][captive_portal:088]: Captive Portal:
[23:20:19][C][mdns:115]: mDNS:
[23:20:19][C][mdns:116]: Hostname: estaresble
[23:20:20][C][esphome.ota:073]: Over-The-Air updates:
[23:20:20][C][esphome.ota:074]: Address: estaresble.local:3232
[23:20:20][C][esphome.ota:075]: Version: 2
[23:20:20][C][api:139]: API Server:
[23:20:20][C][api:140]: Address: estaresble.local:6053
[23:20:36][D][ble_adv_light:076]: BleAdvLight::on_pair called!
**[23:20:36][W][component:237]: Component api took a long time for an operation (805 ms).**
**[23:20:36][W][component:238]: Components should block for at most 30 ms.**
I think it is the board… that is the problem.
So I quickly ordered a new ESP32-S2 board, but I forgot that it doesn’t have a bluetooth module (facepalm).
Now I ordered two more different boards (ESP32-C3 Super mini and ESP32-WROOM-32E), but I expect them in two weeks.
After I get them I will report on the results.
It would be great to make a list of boards that are guaranteed to work. Or on the contrary, in the description of the module to specify the boards that definitely do not work.
In the description there is an indication that it doesn’t work with ESP8266 boards because they don’t have Bluetooth module, but ESP32-S2 boards don’t have it either and many people don’t know about it.
Hi. It’s possible that the light you have simply doesn’t work with the protocols that are implemented in this component. The WROOM32 you originally tested should work fine - there’s nothing wrong with the log that you posted (the warning about the component taking too long to respond is expected).
So the message in the logs - “Components should block for at most 30 ms.” can be ignored?
I have two chandeliers of different models and both are controlled by the LampSmart Pro app. But maybe you are right and I was unlucky with the manufacturer.
Yes, that message is normal.
The app implements 3 versions of the communication protocol, whereas I implemented only one of them. If your lamps use one of the other 2 protocols, they won’t work with this component.
Hello, I wanted to know when you plan to start working on the other 2 protocols. This is not meant to rush you, but rather to get a sense of the project timeline because I’m hesitant to change the lamp due to its lack of compatibility with the HA. I also wanted to tanking you for the time you have already invested in this project.
@aronsky, you were right. It’s all about the specifics of the LED chandelier. The esp module is working.
For two days I tried different integrations and esp configurations.
And finally succeeded in getting it to work.
The integration from @flicker581 (GitHub - flicker581/esphome-lampsmart: Custom components for ESPHome (smart BLE lamp control)) with version v1a worked.*
*But I changed the duration parameter from 200 ms (as specified in his sample configuration), to 750 ms. With the 200 ms parameter, device pairing did not work.
I found it strange that it was the integration from @flicker581 that worked, as in this problem " I've got compilation error when tried to use the component · Issue #12 · aronsky/esphome-components · GitHub ", the user has a very similar chandelier and the same brand as my two chandeliers.
@aronsky
I have an issue with the platform: ble_adv_light.
ESPHome cannot be compiled with it and reports that it does not recognise the platform. The platform lampsmart_pro_light can be compiled without errors
INFO ESPHome 2023.7.1
INFO Reading configuration /config/lampsmartpro2.yaml...
INFO Updating https://github.com/aronsky/esphome-components.git@main
ERROR Unable to load component ble_adv_light.light:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 165, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 786, in exec_module
File "<frozen importlib._bootstrap_external>", line 923, in get_code
File "<frozen importlib._bootstrap_external>", line 853, in source_to_code
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/.esphome/external_components/c5b9a7df/components/ble_adv_light/light.py", line 65
match config[CONF_TYPE]:
^
SyntaxError: invalid syntax
Failed config
light.ble_adv_light: [source /config/lampsmartpro2.yaml:38]
Platform not found: 'light.ble_adv_light'.
platform: ble_adv_light
type: zhijia
name: Kitchen Light
duration: 750
default_transition_length: 0s