Skip to content
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 YLXD05YL and YLXD01YL support (Mediatek devices) #10

Open
splitatom44 opened this issue Apr 3, 2021 · 107 comments
Open

Add YLXD05YL and YLXD01YL support (Mediatek devices) #10

splitatom44 opened this issue Apr 3, 2021 · 107 comments
Labels

Comments

@splitatom44
Copy link

Is it possible to assist with flashing the YLXD05YL and YLXD01YL models of the Yeelights?
Photos attached of mainboards.
Thankyou

20210403_074056
20210403_074107
20210403_074251
20210403_075015
20210403_075017
20210403_075709
20210403_075716

@syssi
Copy link
Owner

syssi commented Apr 3, 2021

Bad news: The heart of the white daughterboard is a Mediatek microcontroller. Esphome has ESP8266 and ESP32 support only. Your device aren't Esphome compatible. :-(

@splitatom44
Copy link
Author

Ah ok, thought that might be the case when I pulled it apart. Thanks anyways

@syssi
Copy link
Owner

syssi commented Apr 4, 2021

Do you like to replace the white daughterboard with an esp32? The task isn't easy but possible.

@splitatom44
Copy link
Author

Interesting, I'd assume a fairly good understanding of the schematics of the board would be needed no?

@syssi
Copy link
Owner

syssi commented Apr 4, 2021

Yes. I try to outline the steps to get a better undestanding what needs to be done:

  1. Use the pads at J2 to power the daughter board. Attach 3.3V + GND to a power supply providing 3.3V. Don't attach the LEDs! Don't power the device with 230V AC. Attach RXD, TXD and GND to a USB-to-TTL serial adapter.
  2. Open a serial console. You should see some output of the stock firmware.
  3. Try to control the device by the android app. Do you see any output at the serial console?
  4. Remove the power. Try to understand / identify which pads of the white daugther board are connected to the led driver. Trace the lines / use a continuity tester.

We are ready if you've identified the following pins:

  • START
  • 3.3V
  • GND
  • RXD
  • TXD
  • C (Cold white), PWM signal
  • W (Warm white), PWM signal
  • Night light (if supported), PWM signal
  • Standby / Power supply (if supported)
  1. As soon we know the location of the pads of the different functions we will try to compare the pin layout with the esp32 wroom. I hope the esp32 can be attached/soldered 1:1 to the board. If not: The relevant pins needs to be wired to the corresponding pin (gnd, 3.3v, txd, rxd) of the esp32.

  2. As soon we know/assume the location/pads of C, W, N and Standby we can verify our assumption by driving the stock firmware via the app. F.e. turn on the light and drive cold white to 100%. You should measure between C and GND a voltage of max. 3.3V (if it's less than 3.3V the max voltage of C is limited. Note down the limits!). Do the same for the warm white PWM pin. Turn on the night light and measure the min/max voltage/setting of the night light. Turn the light on/off. Measure the voltage at the standby pin.

  3. As soon you know your device very well, we can replace the white daughter board. I assume a lot of pads aren't connected. If we find pads/connections without knowing the purpose we are doomed. ;-)

@splitatom44
Copy link
Author

Excellent guide, next weekend when I have time I'll start poking around

@lazzzrus
Copy link

lazzzrus commented Apr 21, 2021

Hello Syssi!

Thank you for your wonderful work!

I have similar light.
So i can see output on UART. Miio net, miio monitor etc. It reacts when i change settings in yeelight app i.e. "new britght 67".
Should i look for particular messages?

I've found g, rx, tx, 3v3 and start pins.
But i don't know how to find pwm pins. There are some pins with 3.2V, some with 0V. Current is 10, 20 and 40 mA, but it doesn't change when i change brightness.
Also i can't discover pwm signal even by oscilloscope (hantek d72). I totally new with these measurements.
Could you advice how to find pwm pins please?

@syssi
Copy link
Owner

syssi commented Apr 22, 2021

You can identify a PWM signal if you measure the voltage at a GPIO. If you change the brightness the voltage should change.

Examples:
Warm white brightness 100%: 3.2V
Warm white brightness 50%: 1,5V
Warm white brightness 1%: 0,2V

@lazzzrus
Copy link

lazzzrus commented Apr 25, 2021

Thank you!
So the reason was mediatek doesn't output pwm signal when is not connected to the mains.
Now i've managed to find cold and warm leds.

Is there way to disable mediatek without displacing it?
i'd want to connect esp32 to test everything. And only displace old MCU after everethyng is working.
Tried to connect start with the ground but no effect.

@lazzzrus
Copy link

lazzzrus commented Apr 25, 2021

So these pins i discovered so far:
image

@lazzzrus
Copy link

nightlight is very low warm leds. What the nightlight pin does and how to find it?

Same with RGB backlight. I'm not familiar with how it works yet. Should it be 3 different pins?

@syssi
Copy link
Owner

syssi commented Apr 26, 2021

The nightlight pin is a PWM pin too. It drives the warm white LEDs in a very low brightness range.

The RGB backlight are 3 PWM pins one per color.

@syssi
Copy link
Owner

syssi commented Apr 26, 2021

I prefer to remove the Mediathek MCU before assembling the ESP32 because it will be hard to remove the power supply from the Mediathek MCU only.

@lazzzrus
Copy link

Hi Sebastian!
Thanks!
So the pinout now looks like this:
image

What else should be considered before desoldering Mediatek?

Your yaml contains "power_supply" pin. Is it necessary or it could be not present in my device?

@syssi
Copy link
Owner

syssi commented Apr 27, 2021

At some devices a GPIO ist used (Low vs. High) to turn the LED driver on and off. Please check all remaining pins while turning the lamp on and off. Do you see a GPIO flipping between 0 and 3,3V?

@lazzzrus
Copy link

lazzzrus commented Apr 27, 2021

Well, now it looks this way:
image

5 pins are always high but they are not connected to 3.3pin
4 pins are always low

1 pin between warm and nightlight is low when turned off and 1.55V when turned on
1 pin between night and red is 0,87V when turned off an 1,55V when turned on.
1 pin at the bottom right is 1.55V when off and 1.4V when on
What these three pins could be meant for? Some sensors?

Also i provided 3,3V to cold and warm LED pins when the light was turned off and the LEDs worked.
Does it mean that the driver is always on and all we need is just to provide PWM output?

@syssi
Copy link
Owner

syssi commented Apr 27, 2021

5 pins are always high but they are not connected to 3.3pin
4 pins are always low

Just keep this in mind. May be the behaviour/state needs to replicated at the esphome firmware.

1 pin between warm and nightlight is low when turned off and 1.55V when turned on
1 pin between night and red is 0,87V when turned off an 1,55V when turned on.
What these two pins could be meant for?

I don't know.

Also i provided 3,3V to cold and warm LED pins when the light was turned off and the LEDs worked.
Does it mean that the driver is always on and all we need is just to provide PWM output?

Good idea. I think you are safe now. :-)

@lazzzrus
Copy link

lazzzrus commented Apr 27, 2021

Finally got it working!
Sebastian, thank you for the help!

Issues and questions so far:

  1. Noise in night mode. May be i use not correct frequency for the LEDC component. It's 1220Hz now.
  2. Need to make least voltage about 0,67V for main light. Don't know how to do it yet. So the light can disappear when i'm changing color temperature or move lovelace scale to thee left.
  3. Bluetooth dimmer probably won't work ever. There is open issue but nothing happens so far: Xiaomi Yeelight Smart Dimmer Switch esphome/feature-requests#293
  4. May be you can advice lovelace card for such ceiling lights? All-in-one card

So Mediatek controller of YLXD02YL can be replaced by ESP32.

@syssi
Copy link
Owner

syssi commented Apr 28, 2021

Could you provide a photo and your yaml as contribution?

@10bn
Copy link

10bn commented May 13, 2021

2. make least voltage about 0,67V for main light. Don't know how to do it yet. So the light can disappear when i'm changing color temperature or move lovelace scale to thee left.

try these frequency settings to get ride of the noise.

`output:

  • platform: ledc
    pin: GPIO19
    id: output_warm
    frequency: 4882Hz

  • platform: ledc
    pin: GPIO21
    id: output_cold
    frequency: 4882Hz

  • platform: ledc
    pin: GPIO23
    id: output_nightlight
    frequency: 9765Hz`

@10bn
Copy link

10bn commented May 14, 2021

I have the same light an was already thinking for a while to try this too. My soldering skills or the tools I where using have been simply not enough for the job. However I manged to restore full functionality except the Bluetooth remote.

There you go.
@syssi use any of the files for contribution if you want.

https://github.com/jaddel/ESPHome-Configurations/tree/master/Devices/Ceiling%20Yeelight%20YLXD05YL

https://github.com/jaddel/ESPHome-Configurations/blob/master/Devices/Ceiling%20Yeelight%20YLXD05YL/Ceiling%20Yeelight%20YLXD05YL.jpg

@syssi
Copy link
Owner

syssi commented May 15, 2021

@jaddel I've updated my ceiling lamps to esphome 1.18.0b3. In the past there where connection dropouts at the history. With 1.18.0 the connection is rock solidsolid.

@lazzzrus
Copy link

IMG_20210429_212349
Can't say that my soldering skills are good as well. But it works.

@lazzzrus
Copy link

lazzzrus commented May 15, 2021

  1. make least voltage about 0,67V for main light. Don't know how to do it yet. So the light can disappear when i'm changing color temperature or move lovelace scale to thee left.

try these frequency settings to get ride of the noise.

`output:

  • platform: ledc
    pin: GPIO19
    id: output_warm
    frequency: 4882Hz
  • platform: ledc
    pin: GPIO21
    id: output_cold
    frequency: 4882Hz
  • platform: ledc
    pin: GPIO23
    id: output_nightlight
    frequency: 9765Hz`

Thank you, i will try!

@syssi syssi changed the title Request YLXD05YL Support Add YLXD05YL support May 16, 2021
@syssi syssi pinned this issue May 16, 2021
@syssi syssi changed the title Add YLXD05YL support Add YLXD05YL and YLXD01YL support (Mediatek devices) May 16, 2021
@lazzzrus
Copy link

BLE-monitor custom integration now supports Yeelight dimmer and remote!
https://github.com/custom-components/ble_monitor#supported-sensors

Could you please advice how to set the mediatek controller into pairing mode? power off/on for 5 times doesn't work.
I need to add old controller to mihome app in order to get BLE encryption key.

@syssi
Copy link
Owner

syssi commented May 20, 2021

@lazzzrus The remote control can be used without any encryption key. The encryption key of the dimmer can be retrieved by a modded mihome app version. Do you want to give it a try? (No OEM firmware / Mediatek required)

@lazzzrus
Copy link

lazzzrus commented May 20, 2021

i do for sure.
Actually i have both remote and dimmer.
The dimmer is not visible by miihome mod.
Remote is visible but returns error when try to pair with mihome mod.

Now i've managed to get mediatek back into mihome mod, but no pairing .txt is available yet...
Installyng python_miio to get key from dimmer.

@stomko11
Copy link

stomko11 commented Feb 22, 2023

Thanks. I gave it a try, although one light is YLXD12YL, but pinout seems to be the same, so is the board.
Initially I used ESP-C3-12F that does not have GPIOs 19,21,22, so I used different ones and adjusted them accordingly in esphome. When I powered on the light, it did briefly (for 1/3 of second?) turn on and off, but then no reaction to any light operations from within HA.
After I have changed ESP to nodemcu-32s

#  board: esp32-c3-devkitm-1
#  framework:
#    type: arduino
esp32:
  board: nodemcu-32s

Adjusted GPIOs according to post above and all seems to work just fine

I just have issue - there is noticeable delay when I power it on (from AC) - I did read this through: #41 and added default transition, but seems to have no effect. Here is mu light config:

output:
  - platform: ledc
    pin: GPIO19
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO21
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO22
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92


light:
  - platform: monochromatic
    name: "${friendly_name} Nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${friendly_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light
    restore_mode: RESTORE_AND_ON
    default_transition_length: 0s

@stomko11
Copy link

I did go ahead and converted also YLXD01YL.
So the only thing that "bugs" me is that compared to stock yeelight FW, this one has slightly longer boot. I measured (+-) that stock takes 0,85 seconds to turn on after AC is switched on (i use relays in switches to shut it off) where this one takes about 1 second. Not big deal, but slightly noticeable.
I tried playing around with on_boot actions, priorities, default transition set to 0s - none of this makes any difference. I guess this is just the way it will be.
What is your experience - how long does it take to turn on after switched on @syssi @NopeFinder ?

@NopeFinder
Copy link

Personally I don't turn off the AC power to it (removed ac switch altogether) so I wouldn't know how long it takes right now. But I do remember it taking a bit longer than usual when I still did have a regular ac switch

@syssi
Copy link
Owner

syssi commented Feb 23, 2023

Same here. My Yeelights are always powered. I will prepare a test bench setup to reproduce the issue.

@stomko11
Copy link

stomko11 commented Feb 27, 2023

@syssi @NopeFinder
I have switched from ESP32 to ESP8266 (Wemos D1 Mini). Powering is now instant. The only issue is there is small flicker (like 3 blinks) upon powering it. Below is my config. I am saving preferences to flash every minute.
I did try on_boot automation, but even with high priority, light turned on with 100% brightness and 6000K, only after few seconds (way longer than previously on ESP32) it switched to set value (80% and 3000K). Also restore mode did not work the way it did on ESP32. So below config is something that works instantly, but I would like to see if anything can be done about those 3 short blinks upon turning power on:

#Variables
substitutions:
  device_name: kids-light
  friendly_name: Kids Light

esphome:
  name: ${device_name}
#  on_boot:
#    priority: 1200
#    then:
#      - light.turn_on:
#          id: ceiling_light
#          brightness: 80%
#          color_temperature: 3000K

esp8266:
  board: esp01_1m
  restore_from_flash : true

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxx"

ota:
  password: "xxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kids-Light Fallback Hotspot"
    password: "xxx"

captive_portal:

output:
  - platform: esp8266_pwm
    pin: GPIO5 #D1
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: esp8266_pwm
    pin: GPIO4 #D2
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: esp8266_pwm
    pin: GPIO0 #D3
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92

# Example usage in a light
light:
  - platform: monochromatic
    name: "${friendly_name} Nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${friendly_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light
    #restore_mode: RESTORE_AND_ON
    #restore_mode: ALWAYS_ON
    #default_transition_length: 0s

preferences:
  flash_write_interval: 1min

@syssi
Copy link
Owner

syssi commented Feb 28, 2023

I guess you can fix the flickering if you don't use GPIO0 for the nightlight because GPIO0 is enabled/pulled high on boot (cp. https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/). Please try GPIO14 (D5) or GPIO12 (D6) instead.

@stomko11
Copy link

Thank you @syssi , it was indeed due to this. I moved night light to GPIO14 (D5) and the issue is gone. Now it is almost perfect. The only thing that still happens is - when I power it on via AC, for a very brief moment, it looks like it starts dimmed (or night light starts) and then immediately goes to desired (either restored from flash, or set on boot) color/brightness (with or without transition, depending on how it is set). This isn't as annoying as 1 second delay or flicker, but still - maybe i am just missing something. Below is my config with omitted unnecessary piece of code:

#Variables
substitutions:
  device_name: kids-light
  friendly_name: Kids Light

esphome:
  name: ${device_name}
  on_boot:
    then:
      - light.turn_on:
          id: ceiling_light
          brightness: 90%
          color_temperature: 3100K

esp8266:
  board: esp01_1m
#  restore_from_flash : true

output:
  - platform: esp8266_pwm
    pin: GPIO5 #D1
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: esp8266_pwm
    pin: GPIO4 #D2
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: esp8266_pwm
    pin: GPIO14 #D5
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92

# Example usage in a light
light:
  - platform: monochromatic
    name: "${friendly_name} Nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${friendly_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light
    #restore_mode: RESTORE_AND_ON
    #restore_mode: ALWAYS_ON
    default_transition_length: 0s

preferences:
  flash_write_interval: 1min

@stomko11
Copy link

stomko11 commented Mar 3, 2023

I had a chance to do few more tests. It looks like that it is night light that gets triggered for a split second on the boot. If I disconnect GPIO pin that connects the night light, it is not happening.
I have tried D5, D6 and D7 and all behave the same.
Any idea why?

@syssi
Copy link
Owner

syssi commented Mar 3, 2023

If you play with the idea to add a resistor please double check the LED driver board is probably already equipped with a pull-down/pull-up resistor. Please don't destroy your driver board while tinkering!

@stomko11
Copy link

stomko11 commented Mar 3, 2023

I am not sure my skills are good enough to try that. I rather disconnected the night light completely for now as I barely used it anyway.
However I would be willing to try if I knew exactly what and how :)

@syssi
Copy link
Owner

syssi commented Mar 4, 2023

Same here. I don't want to instruct you to do dangerous things where I am not 100% sure they are a good idea.

@stomko11
Copy link

stomko11 commented Mar 4, 2023

I will give it a try and try various esp32 or esp8266. I am reading that this may be just the thing for wemos, and others (even clones) may behave differently. So i ordered a few and will report back.

@syssi
Copy link
Owner

syssi commented Mar 4, 2023

@avion23 Do you like to add your 5 cents of a professional here?

Short summary: This picture describes what we have done: https://user-images.githubusercontent.com/19818061/211223563-126fef62-f918-4a00-a9bb-7778376285ed.jpeg

We've replaced a Mediatek microcontroller with an ESP8266. The ESP is attached to a LED driver board and the three colors (RGB) can be controlled using PWM. A fourth PWM signal is used to control a subset of the LEDs as nightlight.

The issue: The nightlight flickers on boot-up of the ESP. I assume the output pin of the ESP is floating and causes the flicker. How can we make sure the LED driver isn't equipped with a pull-up/pull-down already? If the resistor is missing I would like to add one to pull the line to a logic level to "turn/keeping off the nightlight if there is no PWM signal".

@avion23
Copy link

avion23 commented Mar 4, 2023

It is recommended to use a pullup or pulldown resistor in this application. Based on the assumption that the lines switch an N-Channel MOSFET, it is appropriate to use a pulldown resistor. This is based on my assumption that a high output from the ESP8266 results in the light being turned on. A resistor value in the range of 10k Ohm to 100k Ohm should be suitable.

To provide mechanical isolation of the solder joints, consider applying a small amount of adhesive to the lines.

@syssi
Copy link
Owner

syssi commented Mar 21, 2023

@stomko11
Copy link

@syssi this works on switch only, not on pwm. So I would not be able to adjust code to make things work.

@89Amaterasu
Copy link

89Amaterasu commented Oct 5, 2023

I had a chance to do few more tests. It looks like that it is night light that gets triggered for a split second on the boot. If I disconnect GPIO pin that connects the night light, it is not happening. I have tried D5, D6 and D7 and all behave the same. Any idea why?

GPIO4 and GPIO5 are the only pins on the ESP8266 that are always high impedance and do not float or are actively pulled during boot. I'd test those if I were you. Will start to play with my YLXD01YLs in the coming days. GPIO15 might be an option as well, but there is conflicting information on its exact behavior during boot.

@stomko11
Copy link

stomko11 commented Oct 5, 2023

I did, however you need 3 PINs - night light, warm white, cold white.

@89Amaterasu
Copy link

I did, however you need 3 PINs - night light, warm white, cold white.

The setup below works fine for me. One of the pins not being on GPIO4, GPIO5, or GPIO15 leads to a short flash of the respective color during boot.

ESP8266 D1 mini clone
GPIO4: WW
GPIO5: CW
GPIO15: Nightlight

@stomko11
Copy link

stomko11 commented Oct 5, 2023

It is that flash that annoyed me on esp2866. And delay on esp32 (got used to it)

@89Amaterasu
Copy link

It is that flash that annoyed me on esp2866. And delay on esp32 (got used to it)

The flash is gone if you use those three pins on the esp8266.

Here's an explanation for the flashes during boot if other pins are used:
https://rabbithole.wwwdotorg.org/2017/03/28/esp8266-gpio.html

@wmlex
Copy link

wmlex commented Nov 18, 2023

Tell me why, when I turn off the light, the lamp (YLXD17YL) does not go out evenly?
Cold&Warm 50/50
https://youtu.be/jaf6tGkBfgs
Cold&Warm 0/100
https://youtu.be/ibINSGMekM0
Cold&Warm 100/0
https://youtu.be/JFTfzDFalsA
photo_2023-11-18_10-17-32
photo_2023-11-18_10-18-02
photo_2023-11-18_10-17-59

output:
  - platform: ledc
    pin: GPIO19
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO21
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO23
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92

light:
  - platform: monochromatic
    name: "${board_name}_nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${board_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light

@wmlex
Copy link

wmlex commented Nov 21, 2023

Tell me why, when I turn off the light, the lamp (YLXD17YL) does not go out evenly? Cold&Warm 50/50 https://youtu.be/jaf6tGkBfgs Cold&Warm 0/100 https://youtu.be/ibINSGMekM0 Cold&Warm 100/0 https://youtu.be/JFTfzDFalsA photo_2023-11-18_10-17-32 photo_2023-11-18_10-18-02 photo_2023-11-18_10-17-59

output:
  - platform: ledc
    pin: GPIO19
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO21
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO23
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92

light:
  - platform: monochromatic
    name: "${board_name}_nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${board_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light

Solved the problem by adding

gamma_correct: 0.4
default_transition_length: 200ms

@bedson87
Copy link

I converted YLXD01YL - thx! I tore out this "Mediatek" chip with a regular soldering iron, losing a few pads, but fortunately they were unimportant (butcher) :P

20231207_160026_10Tp LMC JOLE 96

Everything works, but... in cwww mode, when the brightness is set to 1-30%, flickering occurs. This problem does not occur in "nightlight" mode. I tried different frequencies (9765Hz/20000Hz) but I didn't see any changes. Anyone have an idea how to fix this?

My yaml:

#Variables
substitutions:
  device_name: komputerowy-yeelight-ceiling
  friendly_name: komputerowy-yeelight-ceiling

esphome:
  name: ${device_name}
  friendly_name: komputerowy-yeelight-ceiling

esp32:
  board: esp32dev
  framework:
    type: arduino
#  framework:
#    type: esp-idf
#    version: recommended

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "XXXX"

ota:
  password: "XXXX"

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

#do pilota
#external_components:
#  - source: github://dentra/esphome-components
  
output:
  - platform: ledc
    pin: GPIO19
    id: output_warm
#    frequency: 9765Hz
#    frequency: 20000Hz
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO21
    id: output_cold
#    frequency: 9765Hz
#    frequency: 20000Hz
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO22
    id: output_nightlight
    frequency: 9765Hz
#    frequency: 20000Hz
    max_power: 0.92


light:
  - platform: monochromatic
    name: "${friendly_name} Nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${friendly_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    on_turn_on:
      - light.turn_off: night_light
    
external_components:
  - source: github://dentra/esphome-components

sensor:
  # Presence based on MAC address
  - platform: miot_ylyk01yl
    mac_address: "XXXX"
    bindkey: "XXXX"
    on_click:
      # String (Required), The button name (case insensitive):
      #     on, off, dimmable or sun or moon, plus or +, moonlight or M, minus or -
      - button: "on"
        then:
          - logger.log: button ON click
          - light.turn_on: night_light
      - button: "off"
        then:
           - logger.log: button OFF click
           - light.turn_off: night_light
           - light.turn_off: ceiling_light
      - button: "+"
        then:
           - logger.log: button PLUS click
           - if:
              condition:
                light.is_on: ceiling_light
              then:
                - light.dim_relative:
                    id: ceiling_light
                    relative_brightness: 5%
                    transition_length: 0.1s
                - delay: 0.1s
           - if:
              condition:
                light.is_on: night_light
              then:
                - light.dim_relative:
                    id: night_light
                    relative_brightness: 5%
                    transition_length: 0.1s
                - delay: 0.1s      
           - if:
              condition:
                - light.is_off: night_light
                - light.is_off: ceiling_light
              then:
                - light.dim_relative:
                    id: ceiling_light
                    relative_brightness: 5%
                    transition_length: 0.1s
                - delay: 0.1s      
            
      - button: "-"
        then:
           - logger.log: button MIN click
           - if:
              condition:
                light.is_on: ceiling_light
              then:
                - light.dim_relative:
                    id: ceiling_light
                    relative_brightness: -5%
                    transition_length: 0.1s
                - delay: 0.1s
           - if:
              condition:
                light.is_on: night_light
              then:
                - light.dim_relative:
                    id: night_light
                    relative_brightness: -5%
                    transition_length: 0.1s
                - delay: 0.1s  
      - button: "M"
        then:
           - logger.log: button MOON click
           - if:
              condition:
                light.is_on: ceiling_light
              then:
                - light.turn_off: ceiling_light
                - light.turn_on: night_light
           - if:
              condition:
                light.is_on: night_light
              then:
                - light.turn_off: night_light
                - light.turn_on: ceiling_light
      - button: "sun"
        then:
          - light.control:
              id: ceiling_light
              color_temperature: !lambda |-
                if(id(ceiling_light).remote_values.get_color_temperature()==167){
                  return 370;
                }
                else{
                  return 167;
                }
          - logger.log: button SUN click

  - platform: miot_ylkg0xyl
    # String (Required), device MAC-address.
    mac_address: "XXXX"
    # String, (Optional), device bind key. Will use "xiaomi_account" from "miot" if absent to automaticaly get the bindkey.
    bindkey: "XXXX"
    # List, Automation (Optional), The automation activated when you make specified action
    on_short_press:
      # List, Any automation
      - then:
          - logger.log:
              format: knob was short pressed %u times
              args: ["x"]
          - if:
             condition:
               and:
                 - light.is_off: night_light
                 - light.is_off: ceiling_light
             then:
               - light.turn_on: night_light
#          - if:
#             condition:
#               light.is_on: ceiling_light
#             then:
#               - light.turn_off: ceiling_light
#               - light.turn_on: night_light
          - if:
             condition:
               light.is_on: ceiling_light
             then:
               - light.turn_off: ceiling_light
          - if:
             condition:
               light.is_on: night_light
             then:
               - light.turn_off: night_light
               - light.turn_on: ceiling_light
    on_long_press:
      - then:
          - logger.log: knob was long pressed
          - light.turn_off: night_light
          - light.turn_off: ceiling_light
    on_rotate_left:
      - then:
          - logger.log:
              format: knob was rotating left on %u
              args: ["x"]
          - if:
             condition:
               light.is_on: ceiling_light
             then:
               - light.dim_relative:
                   id: ceiling_light
                   relative_brightness: -15%
                   transition_length: 0.1s
               - delay: 0.1s
          - if:
             condition:
               light.is_on: night_light
             then:
               - light.dim_relative:
                   id: night_light
                   relative_brightness: -15%
                   transition_length: 0.1s
               - delay: 0.1s 
    on_rotate_right:
      - then:
          - logger.log:
              format: knob was rotating right on %u
              args: ["x"]
          - if:
             condition:
               light.is_on: ceiling_light
             then:
               - light.dim_relative:
                   id: ceiling_light
                   relative_brightness: 15%
                   transition_length: 0.1s
               - delay: 0.1s
          - if:
             condition:
               light.is_on: night_light
             then:
               - light.dim_relative:
                   id: night_light
                   relative_brightness: 15%
                   transition_length: 0.1s
               - delay: 0.1s      
          - if:
             condition:
               - light.is_off: night_light
               - light.is_off: ceiling_light
             then:
               - light.dim_relative:
                   id: ceiling_light
                   relative_brightness: 15%
                   transition_length: 0.1s
               - delay: 0.1s  
    on_rotate_left_pressed:
      - then:
          - logger.log:
              format: knob was pressed and rotating left on %u
              args: ["x"]
    on_rotate_right_pressed:
      - then:
          - logger.log:
              format: knob was pressed and rotating right on %u
              args: ["x"]

@PsychoRS
Copy link

PsychoRS commented Jan 8, 2024

Hi,
I'm planning to replace the Mediatek board on my Jiaoyue 650, and I have a question: did I need a power supply to power the board and check the voltages on the outputs or will be fine with the current provided by the USB-TTL adapter (CP2012 and CH431 I have)? Can the Mediatek module connect to wifi when powered by those adapters?

@justr0st
Copy link
Contributor

justr0st commented Jul 29, 2024

Replaced MTK board in my YLXD05YL with ESP32-WROOM-32UE and it worked perfectly, however i needed to change pwm frequency for night light pin to 19531Hz, because it produced audible whining noise on 4882Hz and 9765Hz.

@yvolchkov
Copy link

I am very late to the party, but I have successfully replaced mediatek with ESP32-C3 SuperMini. Haven't tried yet to connect dimmer. So far works seamless except dificulties to set ambient light to warm light (pure red/gree/blue works perfectly though).

Just in case, attaching my configuration. Which is a composition from configurations posted previously with adaptation for c3 SuperMini, and some minor additions like turn on light on power restore.

#Variables
substitutions:
  device_name: bedroom-light
  friendly_name: Bedroom

esphome:
  name: ${device_name}
  friendly_name: ${device_name}

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino
  
# Enable Home Assistant API
api:
  encryption:
    key: ""
logger:

ota:
  password: ""

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


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${device_name} Fallback Hotspot"
    password: !secret wifi_ap_password

captive_portal:

output:
  - platform: ledc
    pin: GPIO00
    id: output_warm
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO01
    id: output_cold
    frequency: 4882Hz
    min_power: 0.07
    max_power: 0.92
    zero_means_zero: true

  - platform: ledc
    pin: GPIO02
    id: output_nightlight
    frequency: 9765Hz
    max_power: 0.92

  - platform: ledc
    pin: GPIO05
    id: rgb_red

  - platform: ledc
    pin: GPIO06
    id: rgb_green

  - platform: ledc
    pin: GPIO7
    id: rgb_blue

light:
  - platform: monochromatic
    name: "${friendly_name} Nightlight"
    id: night_light
    output: output_nightlight
    gamma_correct: 0
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - light.turn_off: ceiling_light
  - platform: cwww
    name: "${friendly_name}"
    id: ceiling_light
    cold_white: output_cold
    warm_white: output_warm
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 2700 K
    gamma_correct: 0
    constant_brightness: true
    restore_mode: ALWAYS_ON
    on_turn_on:
      - light.turn_off: night_light
  - platform: rgb
    name: "${friendly_name} Ambient"
    id: ambient_light
    red: rgb_red
    green: rgb_green
    blue: rgb_blue

@rufik
Copy link

rufik commented Dec 1, 2024

Why do you use these two settings, especially for ESP8266?

min_power: 0.07
max_power: 0.92

@syssi
Copy link
Owner

syssi commented Dec 2, 2024

@rufik It should act like a calibration of the brightness setting. Let's assume the LED goes off if you set the brightness to 5% or the LED doesn't get brighter for values above 90% you can adjust here. The second idea is to replicate the behaviour (voltage levels) of the OEM firmware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests