Files
smart_lights/README.md
T
Matt SpencerandCopilot 575cd8896f feat: add a button gesture to return to pairing mode
A light that has a network only ever rejoins that one, so there was no way
to re-pair it or move it to another coordinator without reflashing.

Holding the encoder button for 10 seconds now makes the light flash green
twice, forget its Zigbee network (saved to flash) and restart, after which
it looks for a network with an open pairing window, in ZHA with Add device.
The coordinator is not told, so Home Assistant keeps the device and
recognises it by its IEEE address when it joins again.

While the light is looking for a network the on-board LED blinks fast
instead of once a second, so a waiting pairing window can be seen to be
picked up, and the change between joined and searching is logged.

The README documents the gesture and how pairing works, and notes that the
extended PAN ID is broadcast by the network and is not a secret.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-28 23:26:29 +00:00

4.4 KiB

smart_light

Firmware for a Zigbee-controlled LED strip light, written in Rust for the ESP32-C6. It joins a Zigbee network as an Extended Color Light, so it shows up in Home Assistant (ZHA) as a normal light with on/off, brightness, colour temperature and colour. It can also be controlled locally with a rotary encoder, and can play animated effects.

Hardware

  • Seeed Studio XIAO ESP32-C6
  • WS2812B LED strip (24 LEDs by default), data on D2 (GPIO2)
  • Rotary encoder with push button: CLK on D10, DT on D9, SW on D8 (GPIO18, GPIO20, GPIO19)

The on-board user LED (GPIO15) blinks as a heartbeat.

Controls

Input Action
Turn the encoder Brightness up or down
Click Next colour temperature preset
Long press Turn on or off
Hold for 10 seconds Forget the Zigbee network and go back to pairing mode

From Home Assistant you get on/off, brightness, colour temperature and colour. Blink and breathe effects are available through the light's flash option, and the animated scenes (rainbow, pulse, comet) are described under Effects.

Building from source

You need rustup. The repository pins a nightly toolchain in rust-toolchain.toml, so the right compiler, components and the riscv32imac-unknown-none-elf target are installed on the first build.

The Zigbee stack is a git submodule (vendor/zigbee-rs), so clone with submodules:

git clone --recurse-submodules https://gitea.m5p3nc3r.co.uk/m5p3nc3r/smart_lights.git
cd smart_lights

If you already cloned without them, run git submodule update --init. The submodule URL is an SSH address on GitHub; if you have no SSH key set up, switch it to HTTPS first with git config submodule.vendor/zigbee-rs.url https://github.com/m5p3nc3r/zigbee-rs.git.

Build:

cargo build --release

To flash a board connected over USB and open the serial log, install espflash and run:

cargo install espflash
cargo run --release

cargo run uses the runner in .cargo/config.toml, which flashes the app with the partition table in partitions.csv and then starts the monitor. The Zigbee network state is kept in the storage partition, so reflashing keeps the light on its network.

To build without Zigbee, for example to test the strip and encoder on their own:

cargo build --release --no-default-features --features esp32c6

The led_diag, pin_diag and gpio_out_diag binaries in src/bin are small hardware checks, run with cargo run --release --bin led_diag.

Configuration

  • src/config.rs: number of LEDs, maximum brightness, encoder timing.
  • src/zigbee_stack.rs: the Zigbee network to join. The extended PAN ID and channel (25) are set in the code and must match your coordinator.

Joining the network

A light that is not on a network is always in pairing mode: it scans every few seconds, and the on-board LED blinks quickly while it does. To join, open a pairing window on your coordinator (in ZHA, Add device) and the light joins as soon as it sees it. After that it rejoins by itself when it restarts.

To pair a light that is already on a network, for example to re-pair it or move it to another coordinator, hold the encoder button for 10 seconds. The strip flashes green twice, the light forgets its network and restarts, and it is then in pairing mode as above. The coordinator is not told, so Home Assistant keeps the device and recognises it when it joins again.

The same applies if it has lost its network keys, for example after a long coordinator outage: open the pairing window and it will join again.

The network it looks for is fixed in the firmware (see Configuration), so a light only pairs with a coordinator whose extended PAN ID and channel match. The extended PAN ID is broadcast by the network and is not a secret.

Effects

Beyond the standard controls, the light has a manufacturer-specific effects cluster (0xFD00) that selects an animated scene (rainbow, pulse or comet) and sets its speed and intensity. Home Assistant needs a quirk to talk to it:

  1. Copy ha/zha_quirks/smart_light.py into a folder in your Home Assistant config, for example custom_zha_quirks/.

  2. Point ZHA at it in configuration.yaml:

    zha:
      custom_quirks_path: /config/custom_zha_quirks/
    
  3. Restart Home Assistant. The light then has an Effect select and Effect speed and Effect intensity sliders.