-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new ble_adv_controller component integrating the handling of fan, lights, pairing button and new variants #17
Conversation
…ir button as well as all encoding for ZhiJia(3) andFanLamp(4)
Thank you for the hard work! That's a huge PR, I'll go over it when I find the time, and hopefully will merge it soon. |
I have many lamp controlled by FanLamp and ZhiJia App. In app lamp controlled separately. My esphome config: external_components: ble_adv_controller:
light:
button:
ESPHome log: [20:50:45][D][light:036]: 'bedroom_bedsidelamp_my' Setting: Lamp ID in config not implemented by ble packet |
@cRazyK67, thanks a lot for your testing and input! Still there is some mystery in how the App is controlling multiple lights, I am not sure the UUID is effectively the key used to differentiate the lights, especially because from the app it is using the AndroidId... Could you please try to change them to 0xC630B100 and 0xC630B200 and check it it works? If not, I will add some debug options to be able to have other for now "fixed" parameters to vary, such as GROUP and MAC. Another question: did you manage to have the lights work separately with previous 'ble_adv_light' component ? |
The change you suggested (changing the first 3 significant bytes of the UUID) allowed the lamps to be controlled separately.
With the previous component, all sources worked simultaneously for me. I also have a problem with lamps flickering when changing brightness or color temperature. It seems that the brightness is first set to 100%, and then to the desired value. I’ll post a video of the lamp’s behavior on YouTube a little later. Also need reversed option for ZhiJia.
|
I observe inappropriate fan behavior FanLamp v2
log for last action (4,5)
|
…eviewed logging. Reviewed ID computation for ZhiJia.
@cRazyK67, I reviewed the Fan and Light Algo to be smarter, this may solve your issues. Please note you can still experience flickering on first switch onjust after flash / power cut or things like that, but no more in standard usage. This includes the change of min_brigthness to a percentage value (0.21 or 21% for example), but it is the default so you can remove the line. |
@NicoIIT Thanks for the quick fixes.
Works
Works without re-paring
Fan works fine. The change in brightness also occurs without flickering, however, when the color temperature changes, the brightness increases, according to my feelings, to a level of 40-50% I do the following sequence of steps:
After step 4, the brightness, as I wrote, is ~40-50% Below is the log of these actions:
I also noticed errors during compilation.
|
@cRazyK67, For the compilation warning, the code is not mine but taken from someone else, I will correct but I need to perform some supplementary testing to be sure it does not impact the functionality (ZhiJia v0 and v1). For the issue you have, from what I see in the logs, there is no "brightness" command issued when changing the color temperature, so it means the color temperature command itself is having an unexpected behavior. Still the command is quite basic (a code and a 1-byte value). I have 2 hypothesis but I would need your help to test it as I do not own any ZhiJia lamp. Could you please:
Last questions:
Thanks in advance! |
This is awesome! Thank you for giving some love to this already-awesome attempt to support FanLamp ceiling fans 🧡 I'm an owner of 2
My current config: external_components:
# shorthand
source: github://NicoIIT/esphome-components
ble_adv_controller:
- id: despacho_fanlamp
encoding: fanlamp_pro
variant: v1b
duration: 500
reversed: false
forced_id: 0
light:
- platform: ble_adv_controller
ble_adv_controller_id: despacho_fanlamp
name: Despacho Fanlamp
index: 0
- platform: ble_adv_controller
ble_adv_controller_id: despacho_fanlamp
name: Despacho Fanlamp Luz Indirecta
index: 2
fan:
- platform: ble_adv_controller
ble_adv_controller_id: despacho_fanlamp
name: Despacho Fanlamp
speed_count: 6
use_direction: true
button:
- platform: ble_adv_controller
ble_adv_controller_id: despacho_fanlamp
name: Pair Despacho Fanlaml
cmd: pair Thank you again! |
I think this is from my code, I will try to correct it, But feel free to so if you want, I may have still have some test vectors to verify the change
I can confirmed that I had the same issue before my lamp broke, and no messages where sent, so I am wondering if there is a compensation on the app to keep the brightness perceived as constant? I had no time to investigate |
@afharo, Thanks for the testing, you are the first to use Fan with fanlamp_pro v1x ! For the 'index' feature to handle multiple lights, I never tested it as I do not have such lights, this was a guess but this was maybe a complete wrong read of the code... Could you please use the custom service in order to make a few tests ? If this is switching your secondary light then I could implement the proper handling, else I will have to dive into java and android code and I really hate that 🥲 |
@14roiron, I already corrected the warning in my last commit, quite easy in fact 😄 |
It's working! This is the way!
It still doesn't... 😢 FWIW, I tried the HA service with the command I wonder if the code is missing a handler somewhere. Other actions, I can see lines like However, when changing the direction via HA, I get this other log warning:
|
…keep it in the background
@afharo, this is strange, you should not have this Warning anymore. I tested on my side and it is working. Are you sure you pulled the changes? AFAIK esphome is not updating repos on his own, you have to do it manually... or simply delete the content of folder config/.esphome/external_components, this should trigger a re download of the repo. BTW I added the proper handling of the secondary light, just add the following light to your config with option 'secondary':
and remove the 'index' option now deprecated. voilà 😄 |
@NicoIIT, I had the default You're a true hero! Thanks for the iterations and for the quick responses and fixes! 🧡 🧡 |
@afharo Thanks for the hint.
The same button is also available in the ZhiJia application.
I have not tested the 'ble_adv_light' component in such detail because... it didn't work correctly for me.
Yes.
in both tests, after changing the color temperature, the brightness increases |
This works nearly perfectly for my needs, thank you @NicoIIT (also, this has come just in time for when I ordered a fan from aliexpress). Only issue I'm facing at the moment is that if I tie the light with a configuration of adaptive lighting (https://github.com/basnijholt/adaptive-lighting) it seems that while the light comes on, it immediately turns off, however commands still appear to be sent as per the logs below logs_fanlamppro-controller_logs.txt I will adjust the settings of adaptive lighting, perhaps the brightness / mired config is not going to work for this light. Also noted in the logs is the following warning:
|
@pantherale0, from what I saw in the logs the component you are using is sending a lot of commands to the light in a very short time-frame, and this not recommended. I updated the doc to highlight the technical limitations of this kind of lights due to the To make it work you will either need:
|
Nice, yeah I had assumed it was sending too much too quickly and sending the controller into another universe. Thank you 🙂 I pulled my controller apart earlier to see what sort of chips are inside (all I saw in the ad was a picture of an app so had assumed there was some tuya based chip inside as thats what we normally get). There are 4 pads exposed on the bottom of my controller, I'm assuming its for programming purposes but maybe there are some signals that can be sent/received over this (I'd suggest some UART protocol but probably too advanced for the chips on these). |
With the above information in mind, I think I've got adaptive lighting working. In case anyone else comes across this, within the config for transition: |
@cRazyK67, I added the secondary light control for ZhiJia, based on the fact the name in the software would be the same than for FanLamp Pro (Aid, do not ask me why 😄). Could you please test and tell me if it is working ? Concerning the flickering issue, the next steps to progress on this will be quite huge:
Given the amount of work, that the problem was already pre-existing and that the fix is not in the direct scope of this PR, I would recommend that we open a dedicated issue for this to track investigation progresses and resolution. Sorry for not being able to solve this issue within the scope of this change 😢. |
@cRazyK67, as it is working, I pushed the changes to main. You can have a look to the Dynamic Configuration section and try to use the Pairing using all variants, as done by the Phone App. EDIT: and for the flickering problem, you could try to use the |
@NicoIIT - all working perfect again now, thanks for all of this. Was thinking, at the moment we default everything to an off state, perhaps we could store the last known state and use that instead? I've chucked the remote in the bottom of a drawer so assuming the state is suitable for my config as a bunch of automation is responsible for controlling the fan and light. If you did think about implementing that, would probably recommend as a separate PR as this one seems quite big lol. |
…lean-up, added documentation.
@Privet-zdarova, @cRazyK67, I just corrected a potential issue on ZhiJia encoding when changing brightness / color temperature that might be a cause of the flickering you experienced. To be tested to see if it helps. |
@NicoIIT It didn't help me. I have an n52840 dongle, When I have time I will intercept packets from the application |
@cRazyK67 , I am searching if the issue is coming from my software or was already existing in the software I used as a basis. Could you please try to use the component from this repo and attempt a pairing?
I found small differences for both cases, and I would appreciate if you could help. Base configuration: external_components:
# shorthand
source: github://flicker581/esphome-lampsmart
lampsmart_pro_light:
light:
- platform: lampsmart_pro_light
name: V1A light
duration: 200
variant: v1a Please remove any reference to other source repo as it could conflict during the build. EDIT: I corrected the first point, so just tell me if you manage to pair with this correction in fact 😄 |
@NicoIIT Im use this config https://github.com/flicker581/esphome-lampsmart/blob/main/example_lampsmart_pro_light.yaml my chandelier still not pairing for all variants (v1..v3). |
@pantherale0, in fact this is already implemented by base ESPHome Light, using |
@aronsky , I think the fork is now very far from this initial repo with 600 new lines of docs and 2700 new lines of code, so I will continue the work there. |
Thank you very much!)) Everything works great for me with both zhijia v0 and zhijia v2! The only problem is that I can't select "v0" in the latest update. But this can be solved by selecting "v1" in the configuration file. And after loading, you can change it to "v0" in the device settings. This is the only small problem, everything else is great! |
@NicoIIT, I didn't get a chance to follow this discussion thoroughly, but taking a look at the fork, it certainly looks like you've done a fantastic job. I am considering merging this PR as is, as it seems that the discussion here is much more of a review than I could ever have done :) Additionally, I've started work on transitioning this component to Home Assistant directly (without an explicit need for ESPHome). That's in early stages, we'll see how it goes. It'll be a lot easier for end users, I believe (and open up the component to people who have Bluetooth on their hub, but no ESP32 devices). But I imagine that translating all the encoding functions to Python is going to be a colossal PITA. |
@aronsky , good luck to port this to home assistant! With the work done on the encoders/decoders this should be much more easy (only standard 'crc16' functions, only 2 'whiten' simple functions). The main issue will be with the bluetooth stack that is much less stable in a linux docker environment, I let you refer to this comment. I personally tried to implement some standard BLE Leds in HA component requiring to maintain a BLE connection and it never worked ok, whereas I needed 20 lines of code to do it in ESP32. |
Creation of a new component 'ble_adv_controller' able to handle not only lights but also fans combined in a same lamp. It is based mainly on your component 'ble_adv_light' and the fork from @flicker581, with a lot of refactoring. It does not support only lights and has a centralized controller so I renamed it.
New Features:
encoding
,duration
,min_brightness
Related Issues:
#18 : Resolving flickering issue with Zhi Jia lamps
#16 : Add of Fan Support
#13 : Solved by the support of more encoding on ZhiJia
#12 : No more compilation issues on the new component
#11: Added encoding proposed
#5: Solved already in @flicker581 repo, encoding added here
#1: Changing the default value of 'default_transition_length' to 0s