Add a Gitea Actions workflow that builds the firmware and publishes a release whenever main changes. The version is MAJOR.MINOR from the version in Cargo.toml plus the number of commits on main as the patch number, so it only ever goes up and can be worked out again from any commit. The workflow stamps it into Cargo.toml for the build, which puts it in the app descriptor, and the firmware now logs it at boot. The release is tagged v plus the version. Each release carries a full image (bootloader, partition table and application, stopping short of the storage partition so flashing it keeps the Zigbee network), the application image alone, the unstripped build for backtraces, and checksums. The submodule is declared with an SSH address, so the workflow rewrites it to HTTPS for the runner, which has no key. The README documents the scheme. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5.7 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:
-
Copy
ha/zha_quirks/smart_light.pyinto a folder in your Home Assistant config, for examplecustom_zha_quirks/. -
Point ZHA at it in
configuration.yaml:zha: custom_quirks_path: /config/custom_zha_quirks/ -
Restart Home Assistant. The light then has an Effect select and Effect speed and Effect intensity sliders.
Releases
Every commit to main builds the firmware on the Gitea runner and publishes a
release (.gitea/workflows/release.yml).
The version is the MAJOR.MINOR of the version in Cargo.toml followed by the
number of commits on main, so with 0.1.0 in Cargo.toml the 57th commit
becomes 0.1.57. It only goes up, and can be worked out again from any commit.
To start a new series, change the major or minor number in Cargo.toml. The
build writes the version into the firmware, which logs it at boot, and the
release is tagged v plus the version.
Each release has:
smart-light-<version>-full.bin: bootloader, partition table and application. Write it at address 0 withespflash write-bin 0x0 smart-light-<version>-full.bin. It stops short of thestoragepartition, so the light keeps its Zigbee network.smart-light-<version>.bin: the application alone, for a firmware slot.smart-light-<version>.elf.gz: the unstripped build, for decoding backtraces.SHA256SUMS.
The workflow's runs-on must match a label of your Gitea runner. If the job's
own token is not allowed to create releases, add a token with write access to
the repository as a secret named RELEASE_TOKEN.
License
Released under the MIT License. The Zigbee stack in
vendor/zigbee-rs is a separate project with its own licenses.