Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lighting Clusters

Lighting clusters control color and ballast configuration for smart lights.


Color Control (0x0300)

The most complex cluster in zigbee-rs. Supports three color models (Hue/Saturation, CIE XY, and Color Temperature) plus enhanced hue and color loop functionality. All color transitions are managed by a built-in TransitionManager.

Attributes

AttributeIDTypeAccessDescription
CurrentHue0x0000U8ReportHue (0–254)
CurrentSaturation0x0001U8ReportSaturation (0–254)
RemainingTime0x0002U16ReadTransition time remaining (1/10s)
CurrentX0x0003U16ReportCIE x chromaticity (0–65279)
CurrentY0x0004U16ReportCIE y chromaticity (0–65279)
ColorTemperatureMireds0x0007U16ReportColor temp in mireds
ColorMode0x0008Enum8ReadActive mode (0=Hue/Sat, 1=XY, 2=Temp)
Options0x000FBitmap8R/WProcessing flags
EnhancedCurrentHue0x4000U16Read16-bit enhanced hue
EnhancedColorMode0x4001Enum8ReadEnhanced mode indicator
ColorLoopActive0x4002U8ReadColor loop running (0/1)
ColorLoopDirection0x4003U8ReadLoop direction (0=decrement, 1=increment)
ColorLoopTime0x4004U16ReadLoop period in seconds
ColorCapabilities0x400ABitmap16ReadSupported features bitmask
ColorTempPhysicalMin0x400BU16ReadMin supported mireds (e.g. 153 = 6500K)
ColorTempPhysicalMax0x400CU16ReadMax supported mireds (e.g. 500 = 2000K)

Color Modes

#![allow(unused)]
fn main() {
pub const COLOR_MODE_HUE_SAT: u8 = 0x00;
pub const COLOR_MODE_XY: u8 = 0x01;
pub const COLOR_MODE_TEMPERATURE: u8 = 0x02;
}

Commands

IDCommandDescription
0x00MoveToHueTransition to target hue
0x01MoveHueContinuous hue movement
0x02StepHueStep hue by increment
0x03MoveToSaturationTransition to target saturation
0x04MoveSaturationContinuous saturation movement
0x05StepSaturationStep saturation by increment
0x06MoveToHueAndSaturationTransition both
0x07MoveToColorTransition to XY color
0x08MoveColorContinuous XY movement
0x09StepColorStep XY by increments
0x0AMoveToColorTemperatureTransition to color temp
0x40EnhancedMoveToHue16-bit hue transition
0x41EnhancedMoveHue16-bit continuous hue
0x42EnhancedStepHue16-bit hue step
0x43EnhancedMoveToHueAndSaturation16-bit hue + sat
0x44ColorLoopSetStart/stop color loop
0x47StopMoveStepStop all transitions
0x4BMoveColorTemperatureContinuous temp movement
0x4CStepColorTemperatureStep color temp

Usage

#![allow(unused)]
fn main() {
use zigbee_zcl::clusters::color_control::ColorControlCluster;

let mut color = ColorControlCluster::new();
// Default: XY mode, color temp 250 mireds (~4000K), all capabilities enabled

// In your timer callback (call every 100ms):
color.tick(1); // advance transitions by 1 decisecond

// Read current state for LED driver:
let hue = color.attributes().get(AttributeId(0x0000)); // CurrentHue
let sat = color.attributes().get(AttributeId(0x0001)); // CurrentSaturation
let temp = color.attributes().get(AttributeId(0x0007)); // ColorTemperature
}

The Transition Engine

Color Control uses a TransitionManager<4> supporting 4 concurrent transitions (hue, saturation, X, Y or color temperature). When a command like MoveToColor arrives:

  1. The cluster calculates start value, target value, and transition time
  2. Starts a Transition in the TransitionManager
  3. Each tick() call interpolates the current value linearly
  4. Attribute store is updated with the interpolated value
  5. RemainingTime attribute reflects time left

Color Loop

The Color Loop engine (ColorLoopSet command 0x44) continuously cycles the hue:

  • Active: ColorLoopActive attribute (0 = off, 1 = running)
  • Direction: 0 = decrement hue, 1 = increment hue
  • Time: Full cycle period in seconds
  • tick() advances the hue based on elapsed time and loop parameters

Ballast Configuration (0x0301)

Configuration attributes for fluorescent lamp ballasts.

AttributeIDTypeAccessDescription
PhysicalMinLevel0x0000U8ReadMinimum light output
PhysicalMaxLevel0x0001U8ReadMaximum light output
BallastStatus0x0002Bitmap8ReadStatus flags
MinLevel0x0010U8R/WConfigured minimum
MaxLevel0x0011U8R/WConfigured maximum

No cluster-specific commands — configuration is done via Write Attributes.

#![allow(unused)]
fn main() {
use zigbee_zcl::clusters::ballast_config::BallastConfigCluster;

let ballast = BallastConfigCluster::new();
}

Putting It Together: Dimmable Color Light

A typical color light uses On/Off + Level Control + Color Control together:

#![allow(unused)]
fn main() {
use zigbee_zcl::clusters::on_off::OnOffCluster;
use zigbee_zcl::clusters::level_control::LevelControlCluster;
use zigbee_zcl::clusters::color_control::ColorControlCluster;

let mut on_off = OnOffCluster::new();
let mut level = LevelControlCluster::new();
let mut color = ColorControlCluster::new();

// In the 100ms timer:
on_off.tick();
level.tick(1);
color.tick(1);

// Drive the LED:
if on_off.is_on() {
    let brightness = level.current_level();
    // Read color temp from attribute store
    // Apply to LED driver
}
}