Hardware PWM output component for Lightning LN882H chips in ESPHome.
ESPHome's built-in libretiny_pwm component does not work on LN882H because analogWrite() is not implemented in LibreTiny for this chip. This component bypasses that limitation by directly using the LN882H SDK's Advanced Timer peripheral for true hardware PWM — no flicker, no workarounds.
- True hardware PWM using the LN882H Advanced Timer peripheral
- Up to 6 simultaneous PWM channels (channels 0–5)
- Works on any GPIOA or GPIOB pin
- Configurable frequency (default 1 kHz)
- Compatible with ESPHome's
light,fan, andoutputcomponents - Fully dimmable LED control via Home Assistant
Add this to your ESPHome YAML:
external_components:
- source:
type: git
url: https://github.com/Nouxii/esphome-ln882h-pwm
components: [ln882h_pwm]output:
- platform: ln882h_pwm
id: my_light_pwm
port: 0 # 0 = GPIOA, 1 = GPIOB
pin_num: 10 # Pin number within the port (e.g. 10 = GPIOA10)
timer_channel: 0 # Advanced Timer channel (0–5)
frequency: 1000 # PWM frequency in Hz
light:
- platform: monochromatic
name: "My Dimmable Light"
output: my_light_pwmoutput:
- platform: ln882h_pwm
id: pwm_red
port: 0
pin_num: 13
timer_channel: 0
frequency: 1000
- platform: ln882h_pwm
id: pwm_green
port: 0
pin_num: 14
timer_channel: 1
frequency: 1000
- platform: ln882h_pwm
id: pwm_blue
port: 0
pin_num: 15
timer_channel: 2
frequency: 1000
- platform: ln882h_pwm
id: pwm_cold_white
port: 0
pin_num: 9
timer_channel: 3
frequency: 1000
- platform: ln882h_pwm
id: pwm_warm_white
port: 0
pin_num: 12
timer_channel: 4
frequency: 1000
light:
- platform: rgbww
name: "LED Strip"
red: pwm_red
green: pwm_green
blue: pwm_blue
cold_white: pwm_cold_white
warm_white: pwm_warm_white
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2700 K| Parameter | Required | Default | Description |
|---|---|---|---|
port |
Yes | — | GPIO port: 0 for GPIOA, 1 for GPIOB |
pin_num |
Yes | — | Pin number within the port (0–15) |
timer_channel |
No | 0 |
Advanced Timer channel (0–5). Each output needs its own channel. |
frequency |
No | 1000 |
PWM frequency in Hz |
The LN882H QFN32 (LN882HKI) has 20 GPIOs across two ports. Here are the commonly used PWM-capable pins:
| GPIO | ESPHome name | Port | Pin Num | QFN32 Pin | Notes |
|---|---|---|---|---|---|
| GPIOA7 | PA7 | 0 | 7 | 15 | PWM capable |
| GPIOA9 | PA9 | 0 | 9 | 17 | Also BOOT pin |
| GPIOA10 | PA10 | 0 | 10 | 21 | PWM capable |
| GPIOA11 | PA11 | 0 | 11 | 22 | PWM capable |
| GPIOA12 | PA12 | 0 | 12 | 23 | PWM capable |
| GPIOB3 | PB3 | 1 | 3 | 24 | PWM capable |
Pins GPIOA13–GPIOB2 are reserved for QSPI flash and should not be used.
The LN882H has 6 Advanced Timer channels, each capable of generating independent PWM signals. This component:
- Enables the Advanced Timer clock gate
- Configures the timer with the desired frequency using the APB0 clock
- Maps the selected GPIO to the timer channel via the AFIO (Alternate Function I/O) multiplexer
- Sets the duty cycle by adjusting the timer's compare register
The implementation is based on the PWM code from OpenBeken, adapted to work as a native ESPHome external component.
This component was created because:
- The LN882H chip is increasingly used in Tuya WiFi devices as a replacement for BK7231/ESP modules
- ESPHome supports LN882H via LibreTiny, but
libretiny_pwmfails to compile becauseanalogWrite()is not implemented for this platform - OpenBeken has working PWM for LN882H, proving the hardware supports it — the gap was only in the ESPHome/LibreTiny Arduino layer
- Tested on: LN882HKI (QFN32, 2MB flash)
- ESPHome: 2026.3.1+
- LibreTiny: v1.12.1+
- Board:
generic-ln882hki
MIT
- PWM implementation based on OpenBeken's LN882H HAL
- LibreTiny for LN882H ESPHome platform support
- Elektroda.com community for LN882H documentation and teardowns