Controlling BLE ceiling light with HA

Hello @HVPereira,

I was not able to find the App ‘ZhiMeiDengKong’ in the Play store, may I ask you to provide a link to this app such as this one?

It would also help if you could capture the messages when some buttons are pressed in the app (or the remote), as detailed here for the dev branch.

Thanks in advance :slightly_smiling_face:

1 Like

@Yacko, I corrected this while pulling all my changes and recent fixes from my dev branch to main branch, it should work OK now.

I have the same light with ZhiMeiDengKong app.
Here the link to ZhiMeiDengKong app
I am trying to use zhijia coding, but still not luck…
Any ideas?

Try with encoding: zhiguang :slightly_smiling_face:
Ref doc

You can also listen the traffic generated by your phone app to shadow the config and avoid pairing.

Have issues with the compiling firmware from your fork. So I cant try encoding: zhiguang
But I have captured the packages from APP compiled from repo and can success send it by inject service.

Light ON
Work for me!!!!----->>>[13:44:43][D][ble_adv_handler:300]: raw - 02.01.1A.1B.03.48.46.4B.4A.E4.62.28.85.E6.EF.19.AE.CB.63.FA.C5.3A.96.44.2A.10.11.12.13.14.15 (31)
Not work for me----->>>[13:44:43][D][ble_adv_handler:300]: raw - 02.01.1A.1B.03.F9.08.49.B2.CE.2C.4C.61.31.CA.53.B4.78.67.B7.58.10.11.12.13.14.15.16.17.18.19 (31)
[13:44:43][D][zhijia - v1:189]: Decoded KO (CRC)

Light OFF
Work for me!!!!----->>>[13:45:04][D][ble_adv_handler:300]: raw - 02.01.1A.1B.03.48.46.4B.4A.FF.8E.82.6C.0B.D4.FE.58.B2.65.FD.35.3A.04.C2.CB.10.11.12.13.14.15 (31)
Not work for me----->>>[13:45:04][D][ble_adv_handler:300]: raw - 02.01.1A.1B.03.F9.08.49.B2.CE.2C.4D.60.30.CB.53.B5.78.66.E7.02.10.11.12.13.14.15.16.17.18.19 (31)
[13:45:04][D][zhijia - v1:189]: Decoded KO (CRC)

Looks like raw …10.11.12.13.14.15 (31) is unknow coder ?

Indeed, It does not correspond to any of our supported apps (even zhiguang btw).
You can open a request to have it supported, but that’s a lot of work for a fully unknown app, with no guarantee of success. Moreover the fact it is not available on the Play Store is not a very good point… I would rather not install it on my phone…

EDIT: opened request here

That’s exactly the one, I’ve managed to turn it off and on by sending raw data… but changing the brightness and so on is really hard.

I’ve managed to rtrieve the following information, maybe it could help to “build something”:

turn off

02.01.01.1B.03.48.46.4B.4A.9E.36.9B.BA.1C.35.5F.F9.11.4C.54.6C.51.3D.B0.A5.10.11.12.13.14.15

turn on

02.01.01.1B.03.48.46.4B.4A.FF.17.13.59.BB.D4.FE.59.B2.A7.12.D3.F8.D2.92.49.10.11.12.13.14.15

colder(only has 3 levels, but i need to make request 1 and then request 2. If I make 1 followed by 1 it stays in the same status)

1E.FF.58.55.18.48.46.4B.4A.E1.4B.0F.BF.C1.F2.1C.AF.42.EA.6D.BD.B1.EF.ED.C7.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.0A.B0.76.FA.68.C9.F3.68.6B.B1.20.CA.EF.B4.69.8E.10.11.12.13.14.15

Warmer (3 levels, same as before for colder)

1E.FF.58.55.18.48.46.4B.4A.51.D5.99.2F.31.82.AC.1F.B2.E0.61.48.BB.65.A5.D8.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.FF.8E.82.2D.53.D4.FE.5D.60.65.FD.43.39.EC.08.E0.10.11.12.13.14.15

Brightness down

1E.FF.58.55.18.48.46.4B.4A.51.D5.99.2F.31.82.AC.21.B2.E0.61.48.BE.35.42.0D.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.99.1A.E2.87.F9.3A.64.F9.FA.70.D2.28.2E.C1.B2.44.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.9E.18.DE.8E.F4.35.5F.FA.FF.CB.26.EF.D3.F2.6C.BA.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.1C.9C.62.0C.76.B7.E1.7C.7D.26.B1.8C.72.4F.05.98.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.E4.62.28.C4.BE.EF.19.B4.45.63.FA.CB.3F.8A.11.24.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.FF.8E.82.2D.53.D4.FE.5B.60.65.FD.43.E8.8C.58.73.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.B2.5C.22.D2.90.21.4B.7E.13.6D.F0.09.3E.F8.F9.E1.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.16.BB.7D.F6.6C.BD.E7.62.77.6A.F0.60.35.97.29.CE.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.0A.C1.83.FA.68.C9.F3.66.6B.CD.09.E9.0E.54.EA.89.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.23.A9.6D.01.7F.B0.DA.6F.84.AF.40.F5.EA.1E.17.D6.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.9E.27.F9.8E.F4.35.5F.FA.FF.45.A3.59.5E.8C.79.A7.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.99.2D.F1.87.F9.3A.64.F9.FA.C5.20.F3.D8.F8.93.C1.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.51.02.CA.2F.31.82.AC.21.B2.F0.62.B8.AD.B1.39.42.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.69.1B.DF.97.C9.6A.94.C9.CA.60.F3.18.3D.0D.45.AA.10.11.12.13.14.15

Brightness up:

1E.FF.58.55.18.48.46.4B.4A.E4.75.33.C4.BE.EF.19.B4.45.55.DF.DA.4A.74.EE.C3.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.7B.07.CB.A9.D7.58.82.D7.DC.E1.94.B8.64.5C.95.57.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.1C.AB.71.0C.76.B7.E1.7C.7D.2B.83.8C.78.96.55.7E.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.78.06.CC.A8.DA.5B.85.D8.D9.26.DB.53.79.7F.5D.32.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.E1.7C.34.BF.C1.F2.1C.B1.42.63.47.C6.3E.1E.18.16.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.B2.4D.0F.D2.90.21.4B.7E.13.FD.8D.8E.AE.9C.7B.41.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.07.9A.5E.25.5B.CC.F6.53.68.18.D4.53.89.11.1B.DF.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.16.AA.70.F6.6C.BD.E7.62.77.C1.2E.EA.02.7C.51.D8.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.23.B8.7C.01.7F.B0.DA.6F.84.C3.31.E6.E6.96.EA.F3.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.0A.B0.76.FA.68.C9.F3.66.6B.B1.20.CA.E9.AC.EF.67.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.99.3C.04.87.F9.3A.64.F9.FA.39.B5.80.63.68.A9.AE.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.9E.36.FC.8E.F4.35.5F.FA.FF.CB.48.F0.D3.EA.FE.CB.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.69.0A.D2.97.C9.6A.94.C9.CA.95.3F.E4.07.14.41.27.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.51.F3.B7.2F.31.82.AC.21.B2.E0.C3.47.BE.DD.87.22.10.11.12.13.14.15
1E.FF.58.55.18.48.46.4B.4A.7B.16.E2.A9.D7.58.82.D7.DC.4E.12.05.50.A3.8B.63.10.11.12.13.14.15

RAW data are coded by special algorithm by china application. APP need to be reverse engineered to understand the encoder algorithm… Should wait if someone interested to do that…

I see… thought it might be of help :frowning:

Hi @NicoIIT,

You were right! It’s zhijia / v2, I was able to parse commands from Zhi Guang app! Interesting, but remote commands were not parsed…

In any case, it works — I paired each lantern to the app (as separate groups) and created controllers for them:

ble_adv_controller:
  - id: lights_3d
    encoding: zhijia
    variant: v2
    forced_id: 0xE59BCE
    index: 1
  - id: lights_kitchen
    encoding: zhijia
    variant: v2
    forced_id: 0xE59BCE
    index: 3
  - id: lights_tv
    encoding: zhijia
    variant: v2
    forced_id: 0xE59BCE
    index: 2

light:
  - platform: ble_adv_controller
    ble_adv_controller_id: lights_3d
    name: 3D Printer Light
  - platform: ble_adv_controller
    ble_adv_controller_id: lights_kitchen
    name: Kitchen
  - platform: ble_adv_controller
    ble_adv_controller_id: lights_tv
    name: Main
1 Like

@spherebread: great!

You were right! It’s zhijia / v2, I was able to parse commands from Zhi Guang app! Interesting, but remote commands were not parsed…

Well provide me one of those raw commands, probably a new variant to be added for this type of remote.

Here you go:
02.01.1A.14.FF.F0.FF.CF.58.EC.CF.CD.CF.30.EF.CE.6D.CC.CD.67.C8.EC.2F.C9 (24)

Well I think I decoded it, it was a Pairing command :slightly_smiling_face: .
May you provide a few more commands in this issue so that I can confirm and implement a decoder ? Thanks!

1 Like

@ All, new version pushed to main branch:

  • Support for physical remote sync with HA: the ble_adv_remote component allows you to listen to your physical remote (or phone) commands and publish them to HA (promoted from dev branch)
  • Support for native config listening and Shadow: No more pairing needed! (promoted from dev branch)
  • Support for RGB light type (beta), using type: rgb at light level
  • Support for ZhiMeiDengKong App (beta), encoding: zhimei
  • Possibility to increase the bluetooth range with option use_max_tx_power
  • More Actions and Automation Triggers available

Please note that:

  • The native buttons are deprecated (including pair button), they can be replaced by standard template button with corresponding action
  • The native scanner it includes to listen to config and remote commands makes it incompatible with the ESP32 BLE Tracker or the components that would include it, such as Bluetooth Proxy.
  • 3 components are now used: ble_adv_handler, ble_adv_remote, ble_adv_controller

Do not hesitate to open issues in case you are facing problems.

Enjoy :slightly_smiling_face:

3 Likes

I came here in search of a solution to integrate my new fan that works with the FanLampPro app. I just ordered one of the recommended ESP-32 boards off AliExpress and will report back in a couple of weeks :slight_smile:
Can’t wait to try @NicoIIT’s integration :slight_smile:

New version pushed to main, probably one of my last refactoring as the software looks quite clean now!

Features:

  • Adding support for Smart Light App, encoding: agarce
  • Change log and Developer’s Guide added
  • Bug fixes on RGB lights and Fan Speed speed_count handling
  • Many features for Developers or experienced users to be able to add new codecs or translators by configuration (see wiki)

As always it comes with a bit of migrations that you can find in the change log.
Hope I have not break everything :slight_smile:

3 Likes

Splendid – works great with my “FanLampPro” fan :slight_smile: Thank you @NicoIIT !

1 Like

help me figure out why errors appear

Summary

[07:17:34][D][light:036]: ‘BLE Светильник’ Setting:
[07:17:34][D][light:047]: State: OFF
[07:17:34][D][ble_adv_light:038]: Switch OFF
[07:17:34][D][zhimei - v0:227]: UUID: ‘0x5025’, index: 1, tx: 56, enc: 0xB2 - args[0,0,0]
[07:17:34][D][zhimei - v1:227]: UUID: ‘0x5025’, index: 1, tx: 56, enc: 0xB2 - args[0,0,0]
[07:17:34][D][zhimei - v1b:227]: UUID: ‘0x5025’, index: 1, tx: 56, enc: 0xB2 - args[0,0,0]
[07:17:34][D][zhimei - v2:227]: UUID: ‘0x5025’, index: 1, tx: 56, enc: 0xB2 - args[0,0,0]
[07:17:34][D][ble_adv_handler:336]: request start advertising - 55: 02.01.19.0B.03.55.01.38.25.50.B2.00.00.00.B5 (15)
[07:17:34][D][ble_adv_handler:336]: request start advertising - 55: 02.01.1A.1B.03.48.46.4B.4A.0A.63.30.E7.90.C9.F3.6D.A5.19.7A.A3.88.48.08.A9.10.11.12.13.14.15 (31)
[07:17:34][D][ble_adv_handler:336]: request start advertising - 55: 02.01.1A.1E.FF.58.55.18.48.46.4B.4A.0A.63.30.E7.90.C9.F3.6D.A5.19.7A.A3.88.48.08.A9.10.11.12.13.22.00 (34)
[07:17:34][D][ble_adv_handler:336]: request start advertising - 55: 02.01.1A.1B.03.F9.08.49.B2.CE.2C.9A.07.57.AC.34.62.C8.01.08.E2.10.11.12.13.14.15.16.17.18.19 (31)
[07:17:34][W][component:237]: Component ble_adv_handler took a long time for an operation (53 ms).
[07:17:34][W][component:238]: Components should block for at most 30 ms.
[07:17:35][D][ble_adv_handler:343]: request stop advertising - 55
[07:17:37][D][esp32.preferences:114]: Saving 1 preferences to flash…
[07:17:37][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[07:17:43][D][light:036]: ‘BLE Светильник’ Setting:
[07:17:43][D][light:047]: State: ON
[07:17:43][D][ble_adv_light:046]: Switch ON
[07:17:43][D][zhimei - v0:227]: UUID: ‘0x5025’, index: 1, tx: 57, enc: 0xB3 - args[0,0,0]
[07:17:43][D][zhimei - v1:227]: UUID: ‘0x5025’, index: 1, tx: 57, enc: 0xB3 - args[0,0,0]
[07:17:43][D][zhimei - v1b:227]: UUID: ‘0x5025’, index: 1, tx: 57, enc: 0xB3 - args[0,0,0]
[07:17:43][D][zhimei - v2:227]: UUID: ‘0x5025’, index: 1, tx: 57, enc: 0xB3 - args[0,0,0]
[07:17:43][W][component:237]: Component api took a long time for an operation (51 ms).
[07:17:43][W][component:238]: Components should block for at most 30 ms.
[07:17:43][D][ble_adv_handler:336]: request start advertising - 56: 02.01.19.0B.03.55.01.39.25.50.B3.00.00.00.B7 (15)
[07:17:43][D][ble_adv_handler:336]: request start advertising - 56: 02.01.1A.1B.03.48.46.4B.4A.0A.63.2F.E7.90.C9.F3.6C.A5.70.58.08.2D.F1.C3.A8.10.11.12.13.14.15 (31)
[07:17:43][D][ble_adv_handler:336]: request start advertising - 56: 02.01.1A.1E.FF.58.55.18.48.46.4B.4A.0A.63.2F.E7.90.C9.F3.6C.A5.70.58.08.2D.F1.C3.A8.10.11.12.13.22.00 (34)
[07:17:43][D][ble_adv_handler:336]: request start advertising - 56: 02.01.1A.1B.03.F9.08.49.B2.CE.2C.9B.06.56.AD.34.63.C8.00.58.B8.10.11.12.13.14.15.16.17.18.19 (31)
[07:17:43][W][component:237]: Component ble_adv_handler took a long time for an operation (59 ms).
[07:17:43][W][component:238]: Components should block for at most 30 ms.
[07:17:44][D][ble_adv_handler:343]: request stop advertising - 56
[07:17:57][D][light:036]: ‘Дополнительный свет’ Setting:
[07:17:57][D][light:047]: State: ON
[07:17:57][D][ble_adv_light:046]: Switch ON
[07:17:57][D][zhimei - v0:227]: UUID: ‘0x5025’, index: 1, tx: 58, enc: 0xA6 - args[2,0,0]
[07:17:57][D][zhimei - v1:227]: UUID: ‘0x5025’, index: 1, tx: 58, enc: 0xA6 - args[2,0,0]
[07:17:57][D][zhimei - v1b:227]: UUID: ‘0x5025’, index: 1, tx: 58, enc: 0xA6 - args[2,0,0]
[07:17:57][D][zhimei - v2:227]: UUID: ‘0x5025’, index: 1, tx: 58, enc: 0xA6 - args[2,0,0]
[07:17:57][W][component:237]: Component api took a long time for an operation (52 ms).
[07:17:57][W][component:238]: Components should block for at most 30 ms.
[07:17:57][D][ble_adv_handler:336]: request start advertising - 57: 02.01.19.0B.03.55.01.3A.25.50.A6.02.00.00.AD (15)
[07:17:57][D][ble_adv_handler:336]: request start advertising - 57: 02.01.1A.1B.03.48.46.4B.4A.0A.63.32.E7.90.C9.F3.79.A5.1C.79.A2.81.45.DD.B5.10.11.12.13.14.15 (31)
[07:17:57][D][ble_adv_handler:336]: request start advertising - 57: 02.01.1A.1E.FF.58.55.18.48.46.4B.4A.0A.63.32.E7.90.C9.F3.79.A5.1C.79.A2.81.45.DD.B5.10.11.12.13.22.00 (34)
[07:17:57][D][ble_adv_handler:336]: request start advertising - 57: 02.01.1A.1B.03.F9.08.49.B2.CE.2C.98.07.55.AE.22.60.C8.01.3A.CA.10.11.12.13.14.15.16.17.18.19 (31)
[07:17:57][W][component:237]: Component ble_adv_handler took a long time for an operation (55 ms).
[07:17:57][W][component:238]: Components should block for at most 30 ms.
[07:17:58][D][ble_adv_handler:343]: request stop advertising - 57
[07:18:03][D][light:036]: ‘Дополнительный свет’ Setting:
[07:18:03][D][light:047]: State: OFF
[07:18:03][D][ble_adv_light:038]: Switch OFF
[07:18:04][D][zhimei - v0:227]: UUID: ‘0x5025’, index: 1, tx: 59, enc: 0xA6 - args[1,0,0]
[07:18:04][D][zhimei - v1:227]: UUID: ‘0x5025’, index: 1, tx: 59, enc: 0xA6 - args[1,0,0]
[07:18:04][D][zhimei - v1b:227]: UUID: ‘0x5025’, index: 1, tx: 59, enc: 0xA6 - args[1,0,0]
[07:18:04][D][zhimei - v2:227]: UUID: ‘0x5025’, index: 1, tx: 59, enc: 0xA6 - args[1,0,0]
[07:18:04][W][component:237]: Component api took a long time for an operation (52 ms).
[07:18:04][W][component:238]: Components should block for at most 30 ms.
[07:18:04][D][ble_adv_handler:336]: request start advertising - 58: 02.01.19.0B.03.55.01.3B.25.50.A6.01.00.00.AD (15)
[07:18:04][D][ble_adv_handler:336]: request start advertising - 58: 02.01.1A.1B.03.48.46.4B.4A.0A.63.31.E7.90.C9.F3.79.A5.B8.DE.01.E5.A9.8C.9E.10.11.12.13.14.15 (31)
[07:18:04][D][ble_adv_handler:336]: request start advertising - 58: 02.01.1A.1E.FF.58.55.18.48.46.4B.4A.0A.63.31.E7.90.C9.F3.79.A5.B8.DE.01.E5.A9.8C.9E.10.11.12.13.22.00 (34)
[07:18:04][D][ble_adv_handler:336]: request start advertising - 58: 02.01.1A.1B.03.F9.08.49.B2.CE.2C.99.05.54.AF.23.61.C8.03.24.16.10.11.12.13.14.15.16.17.18.19 (31)
[07:18:04][W][component:237]: Component ble_adv_handler took a long time for an operation (57 ms).
[07:18:04][W][component:238]: Components should block for at most 30 ms.
[07:18:05][D][ble_adv_handler:343]: request stop advertising - 58

my code

Summary

esphome:
name: ble
friendly_name: ble

esp32:
board: esp32dev
framework:
type: arduino

Включаем логирование

logger:

Включаем Home Assistant API

api:
encryption:
key: “2myKnVCUFapZm5uF0KPBsCc92CHLjFl9vFaCKQkd+zM=”

Настройка OTA

ota:
platform: esphome
password: “ea1351cd167f764889858adbc768b4ca”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Включаем fallback hotspot (captive portal) на случай, если Wi-Fi недоступен

ap:
ssid: “Ble Fallback Hotspot”
password: “EzYqBwAO1oI1”

captive_portal:

external_components:

  • source: github://NicoIIT/esphome-components@main
    components: [ble_adv_controller, ble_adv_handler]

Контроллер BLE-рекламы (для управления светильником)

ble_adv_controller:

  • id: my_light_controller
    encoding: zhimei # Возможно, потребуется изменить на другой протокол
    duration: 300
    variant: v2
    forced_id: 0x5025
    index: 1

Определяем светильник как BLE-устройство

light:

  • platform: ble_adv_controller
    ble_adv_controller_id: my_light_controller
    name: “BLE Светильник”
    type: cww
  • platform: ble_adv_controller
    ble_adv_controller_id: my_light_controller
    name: “Дополнительный свет”
    type: onoff
    index: 1

button:

  • platform: template
    name: Pair
    on_press:
    ble_adv_controller.pair: my_light_controller

#ble_adv_handler:
#log_raw: true
#log_command: true
#log_config: true

Hello @stels2250 , there are no errors in the logs you attached, only Warnings. The reason why they appear and how to get ride of them is explained in the doc.

You should also avoid to keep the ‘all’ dynamic configuration (that generates 4 messages on each transaction) and find the proper encoding / variant to use, as explained in another part of the doc

Hi,
not sure if it’s completely off but… would it be possible to make it work as standalone on ESP32?
So far I managed to avoid additional hardware other than Alexa ( and as a backup Google Home) to control all my Iot installations.
FanLamp Pro seems to be the only exception and your awesome work seems to be my only way to go but means also install somewhere an HA just to control a Ceiling fan.

I can think about install it temporarily ( if this can help) but I was wondering if the command can be somehow embedded .
I don’t know much on BLE, if it’s using a sort of “mac address” to identify the transmitter, by right a raw command sent after the registration is supposed to work ( I don’t know…maybe reinstalling the ESP with Tasmota or with the same ESPHome).

Any idea?

Regards

Dave