Device Classes¶
Device classes provide direct control over LIFX devices. All device classes support async context managers for automatic resource cleanup.
State and Info Classes¶
Device state and information dataclasses returned by device methods.
DeviceState¶
Base device state dataclass returned by Device.state.
DeviceState
dataclass
¶
DeviceState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
)
Base device state.
| ATTRIBUTE | DESCRIPTION |
|---|---|
model |
Friendly product name (e.g., "LIFX A19")
TYPE:
|
label |
Device label (user-assigned name)
TYPE:
|
serial |
Device serial number (6 bytes)
TYPE:
|
mac_address |
Device MAC address (formatted string)
TYPE:
|
capabilities |
Device capabilities from product registry
TYPE:
|
power |
Power level (0 = off, 65535 = on)
TYPE:
|
host_firmware |
Host firmware version
TYPE:
|
wifi_firmware |
WiFi firmware version
TYPE:
|
location |
Location tuple (UUID bytes, label, updated_at)
TYPE:
|
group |
Group tuple (UUID bytes, label, updated_at)
TYPE:
|
last_updated |
Timestamp of last state refresh
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
is_fresh |
Check if state is fresh (recently updated). |
Attributes¶
as_dict
property
¶
Return DeviceState as a dictionary.
Functions¶
DeviceVersion¶
Device version information returned by Device.get_version().
DeviceVersion
dataclass
¶
DeviceInfo¶
Device runtime information returned by Device.get_info().
DeviceInfo
dataclass
¶
WifiInfo¶
WiFi module information returned by Device.get_wifi_info().
WifiInfo
dataclass
¶
WifiInfo(signal: float)
Device WiFi module information.
| ATTRIBUTE | DESCRIPTION |
|---|---|
signal |
WiFi signal strength
TYPE:
|
rssi |
WiFi RSSI
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__post_init__ |
Calculate RSSI from signal. |
FirmwareInfo¶
Firmware version information returned by Device.get_host_firmware() and Device.get_wifi_firmware().
FirmwareInfo
dataclass
¶
CollectionInfo¶
Location and group collection information returned by Device.get_location() and Device.get_group().
CollectionInfo
dataclass
¶
DeviceCapabilities¶
Device capabilities from product registry, available via Device.capabilities.
DeviceCapabilities
dataclass
¶
DeviceCapabilities(
has_color: bool,
has_multizone: bool,
has_chain: bool,
has_matrix: bool,
has_infrared: bool,
has_hev: bool,
has_extended_multizone: bool,
kelvin_min: int | None,
kelvin_max: int | None,
)
Device capabilities from product registry.
| ATTRIBUTE | DESCRIPTION |
|---|---|
has_color |
Supports color control
TYPE:
|
has_multizone |
Supports multizone control (strips, beams)
TYPE:
|
has_chain |
Supports chaining (tiles)
TYPE:
|
has_matrix |
Supports 2D matrix control (tiles, candle, path)
TYPE:
|
has_infrared |
Supports infrared LED
TYPE:
|
has_hev |
Supports HEV (High Energy Visible) cleaning cycles
TYPE:
|
has_extended_multizone |
Supports extended multizone protocol
TYPE:
|
kelvin_min |
Minimum color temperature (Kelvin)
TYPE:
|
kelvin_max |
Maximum color temperature (Kelvin)
TYPE:
|
Base Device¶
The Device class provides common operations available on all LIFX devices.
Device
¶
Device(
serial: str,
ip: str,
port: int = LIFX_UDP_PORT,
timeout: float = DEFAULT_REQUEST_TIMEOUT,
max_retries: int = DEFAULT_MAX_RETRIES,
)
Bases: Generic[StateT]
Base class for LIFX devices.
This class provides common functionality for all LIFX devices: - Connection management - Basic device queries (label, power, version, info) - State caching for reduced network traffic
Properties return cached values or None if never fetched. Use get_*() methods to fetch fresh data from the device.
Example
device = Device(serial="d073d5123456", ip="192.168.1.100")
async with device:
# Get device label
label = await device.get_label()
print(f"Device: {label}")
# Use cached label value
if device.label is not None:
print(f"Cached label: {device.label}")
# Turn on device
await device.set_power(True)
# Get power state
is_on = await device.get_power()
if is_on is not None:
print(f"Power: {'ON' if is_on else 'OFF'}")
| PARAMETER | DESCRIPTION |
|---|---|
serial
|
Device serial number as 12-digit hex string (e.g., "d073d5123456")
TYPE:
|
ip
|
Device IP address
TYPE:
|
port
|
Device UDP port
TYPE:
|
timeout
|
Overall timeout for network requests in seconds
TYPE:
|
max_retries
|
Maximum number of retry attempts for network requests
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any parameter is invalid |
| METHOD | DESCRIPTION |
|---|---|
from_ip |
Create and return an instance for the given IP address. |
connect |
Create and return a fully initialized device instance. |
get_mac_address |
Calculate and return the MAC address for this device. |
get_label |
Get device label/name. |
set_label |
Set device label/name. |
get_power |
Get device power state. |
set_power |
Set device power state. |
get_version |
Get device version information. |
get_info |
Get device runtime information. |
get_wifi_info |
Get device WiFi module information. |
get_host_firmware |
Get device host (WiFi module) firmware information. |
get_wifi_firmware |
Get device WiFi module firmware information. |
get_location |
Get device location information. |
set_location |
Set device location information. |
get_group |
Get device group information. |
set_group |
Set device group information. |
set_reboot |
Reboot the device. |
close |
Close device connection and cleanup resources. |
refresh_state |
Refresh device state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
capabilities |
Get device product capabilities.
TYPE:
|
state |
Get device state if available.
TYPE:
|
label |
Get cached label if available.
TYPE:
|
version |
Get cached version if available.
TYPE:
|
host_firmware |
Get cached host firmware if available.
TYPE:
|
wifi_firmware |
Get cached wifi firmware if available.
TYPE:
|
location |
Get cached location name if available.
TYPE:
|
group |
Get cached group name if available.
TYPE:
|
model |
Get LIFX friendly model name if available.
TYPE:
|
mac_address |
Get cached MAC address if available.
TYPE:
|
Source code in src/lifx/devices/base.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
Attributes¶
capabilities
property
¶
capabilities: ProductInfo | None
Get device product capabilities.
Returns product information including supported features like: - color, infrared, multizone, extended_multizone - matrix (for tiles), chain, relays, buttons, hev - temperature_range
Capabilities are automatically loaded when using device as context manager.
| RETURNS | DESCRIPTION |
|---|---|
ProductInfo | None
|
ProductInfo if capabilities have been loaded, None otherwise. |
state
property
¶
Get device state if available.
State is populated by the connect() factory method or by calling _initialize_state() directly. Returns None if state has not been initialized.
| RETURNS | DESCRIPTION |
|---|---|
StateT | None
|
State with current device state, or None if not initialized |
label
property
¶
label: str | None
Get cached label if available.
Use get_label() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Device label or None if never fetched. |
version
property
¶
version: DeviceVersion | None
Get cached version if available.
Use get_version() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
DeviceVersion | None
|
Device version or None if never fetched. |
host_firmware
property
¶
host_firmware: FirmwareInfo | None
Get cached host firmware if available.
Use get_host_firmware() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
FirmwareInfo | None
|
Firmware info or None if never fetched. |
wifi_firmware
property
¶
wifi_firmware: FirmwareInfo | None
Get cached wifi firmware if available.
Use get_wifi_firmware() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
FirmwareInfo | None
|
Firmware info or None if never fetched. |
location
property
¶
location: str | None
Get cached location name if available.
Use get_location() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Location name or None if never fetched. |
group
property
¶
group: str | None
Get cached group name if available.
Use get_group() to fetch from device.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Group name or None if never fetched. |
model
property
¶
model: str | None
Get LIFX friendly model name if available.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Model string from product registry. |
Functions¶
from_ip
async
classmethod
¶
from_ip(
ip: str,
port: int = LIFX_UDP_PORT,
serial: str | None = None,
timeout: float = DEFAULT_REQUEST_TIMEOUT,
max_retries: int = DEFAULT_MAX_RETRIES,
) -> Self
Create and return an instance for the given IP address.
This is a convenience class method for connecting to a known device by IP address. The returned instance can be used as a context manager.
| PARAMETER | DESCRIPTION |
|---|---|
ip
|
IP address of the device
TYPE:
|
port
|
Port number (default LIFX_UDP_PORT)
TYPE:
|
serial
|
Serial number as 12-digit hex string
TYPE:
|
timeout
|
Request timeout for this device instance
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
Device instance ready to use with async context manager |
Example
Source code in src/lifx/devices/base.py
connect
async
classmethod
¶
connect(
ip: str,
serial: str | None = None,
port: int = LIFX_UDP_PORT,
timeout: float = DEFAULT_REQUEST_TIMEOUT,
max_retries: int = DEFAULT_MAX_RETRIES,
) -> (
Light
| HevLight
| InfraredLight
| MultiZoneLight
| MatrixLight
| CeilingLight
)
Create and return a fully initialized device instance.
This factory method creates the appropriate device type (Light, etc) based on the device's capabilities and initializes its state. The returned device MUST be used with an async context manager.
The returned device subclass has guaranteed initialized state - the state property will never be None for devices created via this method.
| PARAMETER | DESCRIPTION |
|---|---|
ip
|
IP address of the device
TYPE:
|
serial
|
Optional serial number (12-digit hex, with or without colons). If None, queries device to get serial.
TYPE:
|
port
|
Port number (default LIFX_UDP_PORT)
TYPE:
|
timeout
|
Request timeout for this device instance
TYPE:
|
max_retries
|
Maximum number of retry attempts
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Light | HevLight | InfraredLight | MultiZoneLight | MatrixLight | CeilingLight
|
Fully initialized device instance (Light, MultiZoneLight, MatrixLight, etc.) |
Light | HevLight | InfraredLight | MultiZoneLight | MatrixLight | CeilingLight
|
with complete state loaded and guaranteed non-None state property. |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device cannot be found or contacted |
LifxTimeoutError
|
If device does not respond |
ValueError
|
If serial format is invalid |
Example
# Connect by IP (serial auto-detected)
device = await Device.connect(ip="192.168.1.100")
async with device:
# device.state is guaranteed to be initialized
print(f"{device.state.model}: {device.state.label}")
if device.state.is_on:
print("Device is on")
# Connect with known serial
device = await Device.connect(ip="192.168.1.100", serial="d073d5123456")
async with device:
await device.set_power(True)
Source code in src/lifx/devices/base.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
get_mac_address
async
¶
get_mac_address() -> str
Calculate and return the MAC address for this device.
Source code in src/lifx/devices/base.py
get_label
async
¶
get_label() -> str
Get device label/name.
Always fetches from device. Use the label property to access stored value.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Device label as string (max 32 bytes UTF-8) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
set_label
async
¶
set_label(label: str) -> None
Set device label/name.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
New device label (max 32 bytes UTF-8)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If label is too long |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Source code in src/lifx/devices/base.py
get_power
async
¶
get_power() -> int
Get device power state.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Power level as integer (0 for off, 65535 for on) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Source code in src/lifx/devices/base.py
set_power
async
¶
Set device power state.
| PARAMETER | DESCRIPTION |
|---|---|
level
|
True/65535 to turn on, False/0 to turn off |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If integer value is not 0 or 65535 |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_version
async
¶
get_version() -> DeviceVersion
Get device version information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
DeviceVersion
|
DeviceVersion with vendor and product fields |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_info
async
¶
get_info() -> DeviceInfo
Get device runtime information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
DeviceInfo
|
DeviceInfo with time, uptime, and downtime |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_wifi_info
async
¶
get_wifi_info() -> WifiInfo
Get device WiFi module information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
WifiInfo
|
WifiInfo with signal strength and RSSI |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_host_firmware
async
¶
get_host_firmware() -> FirmwareInfo
Get device host (WiFi module) firmware information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
FirmwareInfo
|
FirmwareInfo with build timestamp and version |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_wifi_firmware
async
¶
get_wifi_firmware() -> FirmwareInfo
Get device WiFi module firmware information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
FirmwareInfo
|
FirmwareInfo with build timestamp and version |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
get_location
async
¶
get_location() -> CollectionInfo
Get device location information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
CollectionInfo
|
CollectionInfo with location UUID, label, and updated timestamp |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
set_location
async
¶
Set device location information.
Automatically discovers devices on the network to check if any device already has the target location label. If found, reuses that existing UUID to ensure devices with the same label share the same location UUID. If not found, generates a new UUID for this label.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Location label (max 32 characters)
TYPE:
|
discover_timeout
|
Timeout for device discovery in seconds
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
ValueError
|
If label is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
get_group
async
¶
get_group() -> CollectionInfo
Get device group information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
CollectionInfo
|
CollectionInfo with group UUID, label, and updated timestamp |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
set_group
async
¶
Set device group information.
Automatically discovers devices on the network to check if any device already has the target group label. If found, reuses that existing UUID to ensure devices with the same label share the same group UUID. If not found, generates a new UUID for this label.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
Group label (max 32 characters)
TYPE:
|
discover_timeout
|
Timeout for device discovery in seconds
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
ValueError
|
If label is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/base.py
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 | |
set_reboot
async
¶
Reboot the device.
This sends a reboot command to the device. The device will disconnect and restart. You should disconnect from the device after calling this method.
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Note
After rebooting, you may need to wait 10-30 seconds before the device comes back online and is discoverable again.
Source code in src/lifx/devices/base.py
close
async
¶
Close device connection and cleanup resources.
Cancels any pending refresh tasks and closes the network connection. Called automatically when exiting the async context manager.
Source code in src/lifx/devices/base.py
refresh_state
async
¶
Refresh device state from hardware.
Fetches current state from device and updates the state instance. Base implementation fetches label, power, and updates timestamp. Subclasses override to add device-specific state updates.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/base.py
Light¶
The Light class provides color control and effects for standard LIFX lights.
Light
¶
Bases: Device[LightState]
LIFX light device with color control.
Extends the base Device class with light-specific functionality: - Color control (HSBK) - Brightness control - Color temperature control - Waveform effects
Example
light = Light(serial="d073d5123456", ip="192.168.1.100")
async with light:
# Set color
await light.set_color(HSBK.from_rgb(255, 0, 0))
# Set brightness
await light.set_brightness(0.5)
# Set temperature
await light.set_temperature(3500)
Using the simplified connect method (without knowing the serial):
| METHOD | DESCRIPTION |
|---|---|
get_color |
Get current light color, power, and label. |
set_color |
Set light color. |
set_brightness |
Set light brightness only, preserving hue, saturation, and temperature. |
set_kelvin |
Set light color temperature, preserving brightness. Saturation is |
set_hue |
Set light hue only, preserving saturation, brightness, and temperature. |
set_saturation |
Set light saturation only, preserving hue, brightness, and temperature. |
get_power |
Get light power state (specific to light, not device). |
get_ambient_light_level |
Get ambient light level from device sensor. |
set_power |
Set light power state (specific to light, not device). |
set_waveform |
Apply a waveform effect to the light. |
set_waveform_optional |
Apply a waveform effect with selective color component control. |
pulse |
Pulse the light to a specific color. |
breathe |
Make the light breathe to a specific color. |
apply_theme |
Apply a theme to this light. |
refresh_state |
Refresh light state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get light state (guaranteed to be initialized when using Device.connect()).
TYPE:
|
min_kelvin |
Get the minimum supported kelvin value if available.
TYPE:
|
max_kelvin |
Get the maximum supported kelvin value if available.
TYPE:
|
Source code in src/lifx/devices/light.py
Attributes¶
state
property
¶
state: LightState
Get light state (guaranteed to be initialized when using Device.connect()).
| RETURNS | DESCRIPTION |
|---|---|
LightState
|
LightState with current light state |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization |
min_kelvin
property
¶
min_kelvin: int | None
Get the minimum supported kelvin value if available.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
Minimum kelvin value from product registry. |
max_kelvin
property
¶
max_kelvin: int | None
Get the maximum supported kelvin value if available.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
Maximum kelvin value from product registry. |
Functions¶
get_color
async
¶
Get current light color, power, and label.
Always fetches from device. Use the color property to access stored value.
Returns a tuple containing: - color: HSBK color - power: Power level as integer (0 for off, 65535 for on) - label: Device label/name
| RETURNS | DESCRIPTION |
|---|---|
tuple[HSBK, int, str]
|
Tuple of (color, power, label) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/light.py
set_color
async
¶
Set light color.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
HSBK color to set
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/light.py
set_brightness
async
¶
Set light brightness only, preserving hue, saturation, and temperature.
| PARAMETER | DESCRIPTION |
|---|---|
brightness
|
Brightness level (0.0-1.0)
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If brightness is out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
Example
Source code in src/lifx/devices/light.py
set_kelvin
async
¶
Set light color temperature, preserving brightness. Saturation is automatically set to 0 to switch the light to color temperature mode.
| PARAMETER | DESCRIPTION |
|---|---|
kelvin
|
Color temperature in Kelvin (1500-9000)
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If kelvin is out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
Example
Source code in src/lifx/devices/light.py
set_hue
async
¶
Set light hue only, preserving saturation, brightness, and temperature.
| PARAMETER | DESCRIPTION |
|---|---|
hue
|
Hue in degrees (0-360)
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If hue is out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
Example
Source code in src/lifx/devices/light.py
set_saturation
async
¶
Set light saturation only, preserving hue, brightness, and temperature.
| PARAMETER | DESCRIPTION |
|---|---|
saturation
|
Saturation level (0.0-1.0)
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If saturation is out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
Example
Source code in src/lifx/devices/light.py
get_power
async
¶
get_power() -> int
Get light power state (specific to light, not device).
Always fetches from device.
This overrides Device.get_power() as it queries the light-specific power state (packet type 116/118) instead of device power (packet type 20/22).
| RETURNS | DESCRIPTION |
|---|---|
int
|
Power level as integer (0 for off, 65535 for on) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Source code in src/lifx/devices/light.py
get_ambient_light_level
async
¶
get_ambient_light_level() -> float
Get ambient light level from device sensor.
Always fetches from device (volatile property, not cached).
This method queries the device's ambient light sensor to get the current lux reading. Devices without ambient light sensors will return 0.0.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Ambient light level in lux (0.0 if device has no sensor) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/light.py
set_power
async
¶
Set light power state (specific to light, not device).
This overrides Device.set_power() as it uses the light-specific power packet (type 117) which supports transition duration.
| PARAMETER | DESCRIPTION |
|---|---|
level
|
True/65535 to turn on, False/0 to turn off |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If integer value is not 0 or 65535 |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/light.py
set_waveform
async
¶
set_waveform(
color: HSBK,
period: float,
cycles: float,
waveform: LightWaveform,
transient: bool = True,
skew_ratio: float = 0.5,
) -> None
Apply a waveform effect to the light.
Waveforms create repeating color transitions. Useful for effects like pulsing, breathing, or blinking.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Target color for the waveform
TYPE:
|
period
|
Period of one cycle in seconds
TYPE:
|
cycles
|
Number of cycles
TYPE:
|
waveform
|
Waveform type (SAW, SINE, HALF_SINE, TRIANGLE, PULSE)
TYPE:
|
transient
|
If True, return to original color after effect (default True)
TYPE:
|
skew_ratio
|
Waveform skew (0.0-1.0, default 0.5 for symmetric)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If parameters are out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
from lifx.protocol.protocol_types import LightWaveform
# Pulse red 5 times
await light.set_waveform(
color=HSBK.from_rgb(255, 0, 0),
period=1.0,
cycles=5,
waveform=LightWaveform.SINE,
)
# Breathe white once
await light.set_waveform(
color=HSBK(0, 0, 1.0, 3500),
period=2.0,
cycles=1,
waveform=LightWaveform.SINE,
transient=False,
)
Source code in src/lifx/devices/light.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
set_waveform_optional
async
¶
set_waveform_optional(
color: HSBK,
period: float,
cycles: float,
waveform: LightWaveform,
transient: bool = True,
skew_ratio: float = 0.5,
set_hue: bool = True,
set_saturation: bool = True,
set_brightness: bool = True,
set_kelvin: bool = True,
) -> None
Apply a waveform effect with selective color component control.
Similar to set_waveform() but allows fine-grained control over which color components (hue, saturation, brightness, kelvin) are affected by the waveform. This enables effects like pulsing brightness while keeping hue constant, or cycling hue while maintaining brightness.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Target color for the waveform
TYPE:
|
period
|
Period of one cycle in seconds
TYPE:
|
cycles
|
Number of cycles
TYPE:
|
waveform
|
Waveform type (SAW, SINE, HALF_SINE, TRIANGLE, PULSE)
TYPE:
|
transient
|
If True, return to original color after effect (default True)
TYPE:
|
skew_ratio
|
Waveform skew (0.0-1.0, default 0.5 for symmetric)
TYPE:
|
set_hue
|
Apply waveform to hue component (default True)
TYPE:
|
set_saturation
|
Apply waveform to saturation component (default True)
TYPE:
|
set_brightness
|
Apply waveform to brightness component (default True)
TYPE:
|
set_kelvin
|
Apply waveform to kelvin component (default True)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If parameters are out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
from lifx.protocol.protocol_types import LightWaveform
# Pulse brightness only, keeping hue/saturation constant
await light.set_waveform_optional(
color=HSBK(0, 1.0, 1.0, 3500),
period=1.0,
cycles=5,
waveform=LightWaveform.SINE,
set_hue=False,
set_saturation=False,
set_brightness=True,
set_kelvin=False,
)
# Cycle hue while maintaining brightness
await light.set_waveform_optional(
color=HSBK(180, 1.0, 1.0, 3500),
period=5.0,
cycles=0, # Infinite
waveform=LightWaveform.SAW,
set_hue=True,
set_saturation=False,
set_brightness=False,
set_kelvin=False,
)
Source code in src/lifx/devices/light.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
pulse
async
¶
Pulse the light to a specific color.
Convenience method for creating a pulse effect using SINE waveform.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Target color to pulse to
TYPE:
|
period
|
Period of one pulse in seconds (default 1.0)
TYPE:
|
cycles
|
Number of pulses (default 1)
TYPE:
|
transient
|
If True, return to original color after effect (default True)
TYPE:
|
Example
Source code in src/lifx/devices/light.py
breathe
async
¶
Make the light breathe to a specific color.
Convenience method for creating a breathing effect using SINE waveform.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Target color to breathe to
TYPE:
|
period
|
Period of one breath in seconds (default 2.0)
TYPE:
|
cycles
|
Number of breaths (default 1)
TYPE:
|
Example
Source code in src/lifx/devices/light.py
apply_theme
async
¶
Apply a theme to this light.
Selects a random color from the theme and applies it to the light.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
Theme to apply
TYPE:
|
power_on
|
Turn on the light
TYPE:
|
duration
|
Transition duration in seconds
TYPE:
|
Example
Source code in src/lifx/devices/light.py
refresh_state
async
¶
Refresh light state from hardware.
Fetches color (which includes power and label) and updates state.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/light.py
LightState¶
Light device state dataclass returned by Light.state.
LightState
dataclass
¶
LightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
)
Bases: DeviceState
Light device state with color control.
| ATTRIBUTE | DESCRIPTION |
|---|---|
color |
Current HSBK color
TYPE:
|
HEV Light¶
The HevLight class extends Light with anti-bacterial cleaning cycle control for LIFX HEV devices.
HevLight
¶
Bases: Light
LIFX HEV light with anti-bacterial cleaning capabilities.
Extends the Light class with HEV (High Energy Visible) cycle control. HEV uses UV-C light to sanitize surfaces and air with anti-bacterial properties.
Example
light = HevLight(serial="d073d5123456", ip="192.168.1.100")
async with light:
# Start a 2-hour cleaning cycle
await light.set_hev_cycle(enable=True, duration_seconds=7200)
# Check cycle status
state = await light.get_hev_cycle()
if state.is_running:
print(f"Cleaning: {state.remaining_s}s remaining")
# Configure defaults
await light.set_hev_config(indication=True, duration_seconds=7200)
Using the simplified connect method:
| METHOD | DESCRIPTION |
|---|---|
get_hev_cycle |
Get current HEV cycle state. |
set_hev_cycle |
Start or stop a HEV cleaning cycle. |
get_hev_config |
Get HEV cycle configuration. |
set_hev_config |
Configure HEV cycle defaults. |
get_last_hev_result |
Get result of the last HEV cleaning cycle. |
refresh_state |
Refresh HEV light state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get HEV light state (guaranteed when using Device.connect()).
TYPE:
|
hev_config |
Get cached HEV configuration if available.
TYPE:
|
hev_result |
Get cached last HEV cycle result if available.
TYPE:
|
Source code in src/lifx/devices/hev.py
Attributes¶
state
property
¶
state: HevLightState
Get HEV light state (guaranteed when using Device.connect()).
| RETURNS | DESCRIPTION |
|---|---|
HevLightState
|
HevLightState with current HEV light state |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization |
hev_result
property
¶
Get cached last HEV cycle result if available.
| RETURNS | DESCRIPTION |
|---|---|
LightLastHevCycleResult | None
|
Result or None if never fetched. |
LightLastHevCycleResult | None
|
Use get_last_hev_result() to fetch from device. |
Functions¶
get_hev_cycle
async
¶
get_hev_cycle() -> HevCycleState
Get current HEV cycle state.
Always fetches from device. Use the hev_cycle property to access stored value.
| RETURNS | DESCRIPTION |
|---|---|
HevCycleState
|
HevCycleState with duration, remaining time, and last power state |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/hev.py
set_hev_cycle
async
¶
Start or stop a HEV cleaning cycle.
| PARAMETER | DESCRIPTION |
|---|---|
enable
|
True to start cycle, False to stop
TYPE:
|
duration_seconds
|
Duration of the cleaning cycle in seconds
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If duration is negative |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/hev.py
get_hev_config
async
¶
get_hev_config() -> HevConfig
Get HEV cycle configuration.
| RETURNS | DESCRIPTION |
|---|---|
HevConfig
|
HevConfig with indication and default duration settings |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/hev.py
set_hev_config
async
¶
Configure HEV cycle defaults.
| PARAMETER | DESCRIPTION |
|---|---|
indication
|
Whether to show visual indication during cleaning
TYPE:
|
duration_seconds
|
Default duration for cleaning cycles in seconds
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If duration is negative |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/hev.py
get_last_hev_result
async
¶
Get result of the last HEV cleaning cycle.
| RETURNS | DESCRIPTION |
|---|---|
LightLastHevCycleResult
|
LightLastHevCycleResult enum value indicating success or interruption reason |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/hev.py
refresh_state
async
¶
Refresh HEV light state from hardware.
Fetches color, HEV cycle, config, and last result.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/hev.py
HevLightState¶
HEV light device state dataclass returned by HevLight.state.
HevLightState
dataclass
¶
HevLightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
hev_cycle: HevCycleState,
hev_config: HevConfig,
hev_result: LightLastHevCycleResult,
)
Bases: LightState
HEV light device state with anti-bacterial capabilities.
| ATTRIBUTE | DESCRIPTION |
|---|---|
hev_cycle |
Current HEV cycle state
TYPE:
|
hev_config |
Default HEV configuration
TYPE:
|
hev_result |
Last HEV cycle result
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_light_state |
Create HevLightState from LightState. |
Attributes¶
Functions¶
from_light_state
classmethod
¶
from_light_state(
light_state: LightState,
hev_cycle: HevCycleState,
hev_config: HevConfig,
hev_result: LightLastHevCycleResult,
) -> HevLightState
Create HevLightState from LightState.
Source code in src/lifx/devices/hev.py
Infrared Light¶
The InfraredLight class extends Light with infrared LED control for night vision on LIFX A19 + Night Vision devices.
InfraredLight
¶
Bases: Light
LIFX infrared light with IR LED control.
Extends the Light class with infrared brightness control. Infrared LEDs automatically activate in low-light conditions to provide illumination for night vision cameras.
Example
light = InfraredLight(serial="d073d5123456", ip="192.168.1.100")
async with light:
# Set infrared brightness to 50%
await light.set_infrared(0.5)
# Get current infrared brightness
brightness = await light.get_infrared()
print(f"IR brightness: {brightness * 100}%")
Using the simplified connect method:
| METHOD | DESCRIPTION |
|---|---|
get_infrared |
Get current infrared brightness. |
set_infrared |
Set infrared brightness. |
refresh_state |
Refresh infrared light state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get infrared light state (guaranteed when using Device.connect()).
TYPE:
|
infrared |
Get cached infrared brightness if available.
TYPE:
|
Source code in src/lifx/devices/infrared.py
Attributes¶
state
property
¶
state: InfraredLightState
Get infrared light state (guaranteed when using Device.connect()).
| RETURNS | DESCRIPTION |
|---|---|
InfraredLightState
|
InfraredLightState with current infrared light state |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization |
Functions¶
get_infrared
async
¶
get_infrared() -> float
Get current infrared brightness.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Infrared brightness (0.0-1.0) |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/infrared.py
set_infrared
async
¶
set_infrared(brightness: float) -> None
Set infrared brightness.
| PARAMETER | DESCRIPTION |
|---|---|
brightness
|
Infrared brightness (0.0-1.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If brightness is out of range |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/infrared.py
refresh_state
async
¶
Refresh infrared light state from hardware.
Fetches color and infrared brightness.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/infrared.py
InfraredLightState¶
Infrared light device state dataclass returned by InfraredLight.state.
InfraredLightState
dataclass
¶
InfraredLightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
infrared: float,
)
Bases: LightState
Infrared light device state with IR control.
| ATTRIBUTE | DESCRIPTION |
|---|---|
infrared |
Infrared brightness (0.0-1.0)
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_light_state |
Create InfraredLightState from LightState. |
Attributes¶
Functions¶
from_light_state
classmethod
¶
from_light_state(
light_state: LightState, infrared: float
) -> InfraredLightState
Create InfraredLightState from LightState.
Source code in src/lifx/devices/infrared.py
MultiZone Light¶
The MultiZoneLight class controls LIFX strips and beams with multiple color zones.
MultiZoneLight
¶
Bases: Light
LIFX MultiZone light device (strips, beams).
Extends the Light class with zone-specific functionality: - Individual zone color control - Multi-zone effects (move, etc.) - Extended color zone support for efficient bulk updates
Example
light = MultiZoneLight(serial="d073d5123456", ip="192.168.1.100")
async with light:
# Get number of zones
zone_count = await light.get_zone_count()
print(f"Device has {zone_count} zones")
# Set all zones to red
await light.set_color_zones(
start=0, end=zone_count - 1, color=HSBK.from_rgb(255, 0, 0)
)
# Get colors for first 5 zones
colors = await light.get_color_zones(0, 4)
# Apply a moving effect
await light.set_move_effect(speed=5.0, direction="forward")
Using the simplified connect method:
| METHOD | DESCRIPTION |
|---|---|
get_zone_count |
Get the number of zones in the device. |
get_color_zones |
Get colors for a range of zones using GetColorZones. |
get_extended_color_zones |
Get colors for a range of zones using GetExtendedColorZones. |
get_all_color_zones |
Get colors for all zones, automatically using the best method. |
set_color_zones |
Set color for a range of zones. |
set_extended_color_zones |
Set colors for multiple zones efficiently (up to 82 zones per call). |
get_effect |
Get current multizone effect. |
set_effect |
Set multizone effect. |
stop_effect |
Stop any running multizone effect. |
apply_theme |
Apply a theme across zones. |
refresh_state |
Refresh multizone light state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get multizone light state (guaranteed when using Device.connect()).
TYPE:
|
zone_count |
Get cached zone count if available.
TYPE:
|
multizone_effect |
Get cached multizone effect if available.
TYPE:
|
Source code in src/lifx/devices/multizone.py
Attributes¶
state
property
¶
state: MultiZoneLightState
Get multizone light state (guaranteed when using Device.connect()).
| RETURNS | DESCRIPTION |
|---|---|
MultiZoneLightState
|
MultiZoneLightState with current multizone light state |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization |
multizone_effect
property
¶
multizone_effect: MultiZoneEffect | None | None
Get cached multizone effect if available.
| RETURNS | DESCRIPTION |
|---|---|
MultiZoneEffect | None | None
|
Effect or None if never fetched. |
MultiZoneEffect | None | None
|
Use get_effect() to fetch from device. |
Functions¶
get_zone_count
async
¶
get_zone_count() -> int
Get the number of zones in the device.
Always fetches from device.
Use the zone_count property to access stored value.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of zones |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Source code in src/lifx/devices/multizone.py
get_color_zones
async
¶
Get colors for a range of zones using GetColorZones.
Always fetches from device.
Use zones property to access stored values.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start zone index (inclusive, default 0)
TYPE:
|
end
|
End zone index (inclusive, default 255)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors, one per zone |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If zone indices are invalid |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/multizone.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
get_extended_color_zones
async
¶
Get colors for a range of zones using GetExtendedColorZones.
Always fetches from device.
Use zones property to access stored values.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start zone index (inclusive, default 0)
TYPE:
|
end
|
End zone index (inclusive, default 255)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors, one per zone |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If zone indices are invalid |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/multizone.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
get_all_color_zones
async
¶
Get colors for all zones, automatically using the best method.
This method automatically chooses between get_extended_color_zones() and get_color_zones() based on device capabilities. Always returns all zones on the device.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors for all zones |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
Example
Source code in src/lifx/devices/multizone.py
set_color_zones
async
¶
set_color_zones(
start: int,
end: int,
color: HSBK,
duration: float = 0.0,
apply: MultiZoneApplicationRequest = APPLY,
) -> None
Set color for a range of zones.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start zone index (inclusive)
TYPE:
|
end
|
End zone index (inclusive)
TYPE:
|
color
|
HSBK color to set
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
apply
|
Application mode (default APPLY) - NO_APPLY: Don't apply immediately (use for batching) - APPLY: Apply this change and any pending changes - APPLY_ONLY: Apply only this change
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If zone indices are invalid |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
# Set zones 0-9 to red
await light.set_color_zones(0, 9, HSBK.from_rgb(255, 0, 0))
# Set with transition
await light.set_color_zones(0, 9, HSBK.from_rgb(0, 255, 0), duration=2.0)
# Batch updates
await light.set_color_zones(
0, 4, color1, apply=MultiZoneApplicationRequest.NO_APPLY
)
await light.set_color_zones(
5, 9, color2, apply=MultiZoneApplicationRequest.APPLY
)
Source code in src/lifx/devices/multizone.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
set_extended_color_zones
async
¶
set_extended_color_zones(
zone_index: int,
colors: list[HSBK],
duration: float = 0.0,
apply: MultiZoneApplicationRequest = APPLY,
*,
fast: bool = False,
) -> None
Set colors for multiple zones efficiently (up to 82 zones per call).
This is more efficient than set_color_zones when setting different colors for many zones at once.
| PARAMETER | DESCRIPTION |
|---|---|
zone_index
|
Starting zone index
TYPE:
|
colors
|
List of HSBK colors to set (max 82) |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
apply
|
Application mode (default APPLY)
TYPE:
|
fast
|
If True, send fire-and-forget without waiting for response. Use for high-frequency animations (>20 updates/second).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If colors list is too long or zone index is invalid |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond (only when fast=False) |
LifxUnsupportedCommandError
|
If device doesn't support this command (only when fast=False) |
Example
# Create a rainbow effect across zones
colors = [
HSBK(hue=i * 36, saturation=1.0, brightness=1.0, kelvin=3500)
for i in range(10)
]
await light.set_extended_color_zones(0, colors)
# High-speed animation loop
for frame in animation_frames:
await light.set_extended_color_zones(0, frame, fast=True)
await asyncio.sleep(0.033) # ~30 FPS
Source code in src/lifx/devices/multizone.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
get_effect
async
¶
get_effect() -> MultiZoneEffect
Get current multizone effect.
Always fetches from device.
Use the multizone_effect property to access stored value.
| RETURNS | DESCRIPTION |
|---|---|
MultiZoneEffect
|
MultiZoneEffect with either FirmwareEffect.OFF or FirmwareEffect.MOVE |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxProtocolError
|
If response is invalid |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/multizone.py
set_effect
async
¶
set_effect(effect: MultiZoneEffect) -> None
Set multizone effect.
| PARAMETER | DESCRIPTION |
|---|---|
effect
|
MultiZone effect configuration
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
from lifx.protocol.protocol_types import Direction, FirmwareEffect
# Apply a move effect moving forward
effect = MultiZoneEffect(
effect_type=FirmwareEffect.MOVE,
speed=5000, # 5 seconds per cycle
duration=0, # Infinite
)
effect.direction = Direction.FORWARD
await light.set_effect(effect)
# Or use parameters directly
effect = MultiZoneEffect(
effect_type=FirmwareEffect.MOVE,
speed=5000,
parameters=[0, int(Direction.REVERSED), 0, 0, 0, 0, 0, 0],
)
await light.set_effect(effect)
Source code in src/lifx/devices/multizone.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
stop_effect
async
¶
Stop any running multizone effect.
Source code in src/lifx/devices/multizone.py
apply_theme
async
¶
apply_theme(
theme: Theme,
power_on: bool = False,
duration: float = 0,
strategy: str | None = None,
) -> None
Apply a theme across zones.
Distributes theme colors evenly across the light's zones with smooth color blending between theme colors.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
Theme to apply
TYPE:
|
power_on
|
Turn on the light
TYPE:
|
duration
|
Transition duration in seconds
TYPE:
|
strategy
|
Color distribution strategy (not used yet, for future)
TYPE:
|
Example
Source code in src/lifx/devices/multizone.py
refresh_state
async
¶
Refresh multizone light state from hardware.
Fetches color, zones, and effect.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/multizone.py
MultiZoneLightState¶
MultiZone light device state dataclass returned by MultiZoneLight.state.
MultiZoneLightState
dataclass
¶
MultiZoneLightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
zones: list[HSBK],
zone_count: int,
effect: FirmwareEffect,
)
Bases: LightState
MultiZone light device state with zone-based control.
| ATTRIBUTE | DESCRIPTION |
|---|---|
zones |
List of HSBK colors for each zone |
zone_count |
Total number of zones
TYPE:
|
effect |
Current multizone effect configuration
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_light_state |
Create MatrixLightState from LightState. |
Attributes¶
Functions¶
from_light_state
classmethod
¶
from_light_state(
light_state: LightState, zones: list[HSBK], effect: FirmwareEffect
) -> MultiZoneLightState
Create MatrixLightState from LightState.
Source code in src/lifx/devices/multizone.py
MultiZoneEffect¶
Configuration dataclass for multizone effects (MOVE). Used with MultiZoneLight.set_effect() and returned by MultiZoneLight.get_effect().
MultiZoneEffect
dataclass
¶
MultiZoneEffect(
effect_type: FirmwareEffect,
speed: int,
duration: int = 0,
parameters: list[int] | None = None,
)
MultiZone effect configuration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
effect_type |
Type of effect (OFF, MOVE)
TYPE:
|
speed |
Effect speed in milliseconds
TYPE:
|
duration |
Total effect duration (0 for infinite)
TYPE:
|
parameters |
Effect-specific parameters (8 uint32 values) |
Matrix Light¶
The MatrixLight class controls LIFX matrix devices (tiles, candle, path) with 2D zone control.
MatrixLight
¶
Bases: Light
LIFX Matrix Light Device.
MatrixLight devices have 2D arrays of controllable color zones arranged in tiles. Most MatrixLight devices (LIFX Candle, LIFX Path) have a single tile. The discontinued LIFX Tile product supported up to 5 tiles in a chain (has_chain).
Zone Addressing: - Colors are applied row-by-row starting at top-left (0,0) - For tiles ≤64 zones: Single set64() call to frame buffer 0 - For tiles >64 zones (e.g., 16x8 = 128 zones): 1. First set64(): rect=(0,0), 64 colors, frame buffer 1 2. Second set64(): rect=(0,4), 64 colors, frame buffer 1 3. copy_frame_buffer(): Copy buffer 1 → buffer 0
Example
async with await MatrixLight.from_ip("192.168.1.100") as matrix: ... # Get device chain info ... chain = await matrix.get_device_chain() ... print(f"Device has {len(chain)} tile(s)") ... ... # Set colors on first tile (8x8 = 64 zones) ... colors = [HSBK.from_rgb(255, 0, 0)] * 64 ... await matrix.set64(tile_index=0, colors=colors, width=8)
See :class:Light for parameter documentation.
| METHOD | DESCRIPTION |
|---|---|
get_device_chain |
Get device chain details (list of Tile objects). |
set_user_position |
Position tiles in the chain (only for devices with has_chain capability). |
get64 |
Get up to 64 zones of color state from a tile. |
get_all_tile_colors |
Get colors for all tiles in the chain. |
set64 |
Set up to 64 zones of color on a tile. |
copy_frame_buffer |
Copy frame buffer (for tiles with >64 zones). |
set_matrix_colors |
Convenience method to set all colors on a tile. |
get_effect |
Get current running matrix effect. |
set_effect |
Set matrix effect with configuration. |
apply_theme |
Apply a theme across matrix tiles using Canvas interpolation. |
refresh_state |
Refresh matrix light state from hardware. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get matrix light state (guaranteed when using Device.connect()).
TYPE:
|
device_chain |
Get cached device chain. |
tile_count |
Get number of tiles in the chain.
TYPE:
|
tile_effect |
Get cached tile effect.
TYPE:
|
Source code in src/lifx/devices/matrix.py
Attributes¶
state
property
¶
state: MatrixLightState
Get matrix light state (guaranteed when using Device.connect()).
| RETURNS | DESCRIPTION |
|---|---|
MatrixLightState
|
MatrixLightState with current matrix light state |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization |
device_chain
property
¶
Get cached device chain.
Returns None if not yet fetched. Use get_device_chain() to fetch.
tile_count
property
¶
tile_count: int | None
Get number of tiles in the chain.
Returns None if device chain not yet fetched.
tile_effect
property
¶
tile_effect: MatrixEffect | None
Get cached tile effect.
Returns None if not yet fetched. Use get_tile_effect() to fetch.
Functions¶
get_device_chain
async
¶
Get device chain details (list of Tile objects).
This method fetches the device chain information and caches it.
| RETURNS | DESCRIPTION |
|---|---|
list[TileInfo]
|
List of TileInfo objects describing each tile in the chain |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
chain = await matrix.get_device_chain() for tile in chain: ... print(f"Tile {tile.tile_index}: {tile.width}x{tile.height}")
Source code in src/lifx/devices/matrix.py
set_user_position
async
¶
Position tiles in the chain (only for devices with has_chain capability).
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of the tile to position (0-based)
TYPE:
|
user_x
|
User-defined X position
TYPE:
|
user_y
|
User-defined Y position
TYPE:
|
Note
Only applicable for multi-tile devices (has_chain capability). Most MatrixLight devices have a single tile and don't need positioning.
Example
Position second tile at coordinates (1.0, 0.0)¶
await matrix.set_user_position(tile_index=1, user_x=1.0, user_y=0.0)
Source code in src/lifx/devices/matrix.py
get64
async
¶
get64(
tile_index: int = 0,
length: int = 1,
x: int = 0,
y: int = 0,
width: int | None = None,
) -> list[HSBK]
Get up to 64 zones of color state from a tile.
For devices with ≤64 zones, returns all zones. For devices with >64 zones, returns up to 64 zones due to protocol limitations.
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of the tile (0-based). Defaults to 0.
TYPE:
|
length
|
Number of tiles to query (usually 1). Defaults to 1.
TYPE:
|
x
|
X coordinate of the rectangle (0-based). Defaults to 0.
TYPE:
|
y
|
Y coordinate of the rectangle (0-based). Defaults to 0.
TYPE:
|
width
|
Width of the rectangle in zones. Defaults to tile width.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors for the requested zones. For tiles with ≤64 zones, |
list[HSBK]
|
returns the actual zone count (e.g., 64 for 8x8, 16 for 4x4). For tiles |
list[HSBK]
|
with >64 zones (e.g., 128 for 16x8 Ceiling), returns 64 (protocol limit). |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Get all colors from first tile (no parameters needed)¶
colors = await matrix.get64()
Get colors from specific region¶
colors = await matrix.get64(y=4) # Start at row 4
Source code in src/lifx/devices/matrix.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
get_all_tile_colors
async
¶
Get colors for all tiles in the chain.
Fetches colors from each tile in the device chain and returns them as a list of color lists (one per tile). This is the matrix equivalent of MultiZoneLight's get_all_color_zones().
For tiles with >64 zones (e.g., 16x8 Ceiling with 128 zones), makes multiple Get64 requests to fetch all colors.
Always fetches from device. Tiles are queried sequentially to avoid overwhelming the device with concurrent requests.
| RETURNS | DESCRIPTION |
|---|---|
list[list[HSBK]]
|
List of color lists, one per tile. Each inner list contains |
list[list[HSBK]]
|
all colors for that tile (64 for 8x8 tiles, 128 for 16x8 Ceiling). |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
# Get colors for all tiles
all_colors = await matrix.get_all_tile_colors()
print(f"Device has {len(all_colors)} tiles")
for i, tile_colors in enumerate(all_colors):
print(f"Tile {i}: {len(tile_colors)} colors")
# Flatten to single list if needed
flat_colors = [c for tile in all_colors for c in tile]
Source code in src/lifx/devices/matrix.py
set64
async
¶
set64(
tile_index: int,
length: int,
x: int,
y: int,
width: int,
duration: int,
colors: list[HSBK],
fb_index: int = 0,
) -> None
Set up to 64 zones of color on a tile.
Colors are applied row-by-row starting at position (x, y). For tiles >64 zones, use multiple set64() calls with copy_frame_buffer().
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of the tile (0-based)
TYPE:
|
length
|
Number of tiles to update (usually 1)
TYPE:
|
x
|
X coordinate of the rectangle (0-based)
TYPE:
|
y
|
Y coordinate of the rectangle (0-based)
TYPE:
|
width
|
Width of the rectangle in zones
TYPE:
|
duration
|
Transition duration in milliseconds
TYPE:
|
colors
|
List of HSBK colors (up to 64) |
fb_index
|
Frame buffer index (0 for display, 1 for temp buffer)
TYPE:
|
Example
Set 8x8 tile to red¶
colors = [HSBK.from_rgb(255, 0, 0)] * 64 await matrix.set64( ... tile_index=0, length=1, x=0, y=0, width=8, duration=0, colors=colors ... )
Source code in src/lifx/devices/matrix.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
copy_frame_buffer
async
¶
copy_frame_buffer(
tile_index: int,
source_fb: int = 1,
target_fb: int = 0,
duration: float = 0.0,
length: int = 1,
) -> None
Copy frame buffer (for tiles with >64 zones).
This is used for tiles with more than 64 zones. After setting colors in the temporary buffer (fb=1), copy to the display buffer (fb=0).
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of the tile (0-based)
TYPE:
|
source_fb
|
Source frame buffer index (usually 1)
TYPE:
|
target_fb
|
Target frame buffer index (usually 0)
TYPE:
|
duration
|
time in seconds to transition if target_fb is 0
TYPE:
|
length
|
Number of tiles to update starting from tile_index (default 1)
TYPE:
|
Example
For 16x8 tile (128 zones):¶
1. Set first 64 zones to buffer 1¶
await matrix.set64( ... tile_index=0, ... length=1, ... x=0, ... y=0, ... width=16, ... duration=0, ... colors=colors[:64], ... fb_index=1, ... )
2. Set second 64 zones to buffer 1¶
await matrix.set64( ... tile_index=0, ... length=1, ... x=0, ... y=4, ... width=16, ... duration=0, ... colors=colors[64:], ... fb_index=1, ... )
3. Copy buffer 1 to buffer 0 (display)¶
await matrix.copy_frame_buffer( ... tile_index=0, source_fb=1, target_fb=0, duration=2.0 ... )
For a chain of 5 tiles, update all simultaneously:¶
await matrix.copy_frame_buffer( ... tile_index=0, source_fb=1, target_fb=0, length=5 ... )
Source code in src/lifx/devices/matrix.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
set_matrix_colors
async
¶
Convenience method to set all colors on a tile.
If all colors are the same, uses SetColor() packet which sets all zones across all tiles. Otherwise, automatically handles tiles with >64 zones using frame buffer strategy.
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of the tile (0-based)
TYPE:
|
colors
|
List of HSBK colors (length must match tile total_zones) |
duration
|
Transition duration in milliseconds
TYPE:
|
Example
Set entire tile to solid red (uses SetColor packet)¶
colors = [HSBK.from_rgb(255, 0, 0)] * 64 await matrix.set_matrix_colors(tile_index=0, colors=colors)
Set 8x8 tile to gradient (uses set64 with zones)¶
colors = [HSBK(i * 360 / 64, 1.0, 1.0, 3500) for i in range(64)] await matrix.set_matrix_colors(tile_index=0, colors=colors)
Source code in src/lifx/devices/matrix.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
get_effect
async
¶
get_effect() -> MatrixEffect
Get current running matrix effect.
| RETURNS | DESCRIPTION |
|---|---|
MatrixEffect
|
MatrixEffect describing the current effect state |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
effect = await matrix.get_effect() print(f"Effect type: {effect.effect_type}")
Source code in src/lifx/devices/matrix.py
set_effect
async
¶
set_effect(
effect_type: FirmwareEffect,
speed: float = 3.0,
duration: int = 0,
palette: list[HSBK] | None = None,
sky_type: TileEffectSkyType = SUNRISE,
cloud_saturation_min: int = 0,
cloud_saturation_max: int = 0,
) -> None
Set matrix effect with configuration.
| PARAMETER | DESCRIPTION |
|---|---|
effect_type
|
Type of effect (OFF, MORPH, FLAME, SKY)
TYPE:
|
speed
|
Effect speed in seconds (default: 3)
TYPE:
|
duration
|
Total effect duration in nanoseconds (0 for infinite)
TYPE:
|
palette
|
Color palette for the effect (max 16 colors, None for no palette) |
sky_type
|
Sky effect type (SUNRISE, SUNSET, CLOUDS)
TYPE:
|
cloud_saturation_min
|
Minimum cloud saturation (0-255, for CLOUDS)
TYPE:
|
cloud_saturation_max
|
Maximum cloud saturation (0-255, for CLOUDS)
TYPE:
|
Example
Set MORPH effect with rainbow palette¶
rainbow = [ ... HSBK(0, 1.0, 1.0, 3500), # Red ... HSBK(60, 1.0, 1.0, 3500), # Yellow ... HSBK(120, 1.0, 1.0, 3500), # Green ... HSBK(240, 1.0, 1.0, 3500), # Blue ... ] await matrix.set_effect( ... effect_type=FirmwareEffect.MORPH, ... speed=5.0, ... palette=rainbow, ... )
Set effect without a palette¶
await matrix.set_effect( ... effect_type=FirmwareEffect.FLAME, ... speed=3.0, ... )
Source code in src/lifx/devices/matrix.py
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
apply_theme
async
¶
Apply a theme across matrix tiles using Canvas interpolation.
Distributes theme colors across the tile matrix with smooth color blending using the Canvas API for visually pleasing transitions.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
Theme to apply
TYPE:
|
power_on
|
Turn on the light
TYPE:
|
duration
|
Transition duration in seconds
TYPE:
|
Example
Source code in src/lifx/devices/matrix.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
refresh_state
async
¶
Refresh matrix light state from hardware.
Fetches color, tiles, tile colors for all tiles, and effect.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/matrix.py
MatrixLightState¶
Matrix light device state dataclass returned by MatrixLight.state.
MatrixLightState
dataclass
¶
MatrixLightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
chain: list[TileInfo],
tile_orientations: dict[int, str],
tile_colors: list[HSBK],
tile_count: int,
effect: FirmwareEffect,
)
Bases: LightState
Matrix light device state with tile-based control.
| ATTRIBUTE | DESCRIPTION |
|---|---|
tiles |
List of tile information for each tile in the chain
|
tile_colors |
List of HSBK colors for all pixels across all tiles |
tile_count |
Total number of tiles in chain
TYPE:
|
effect |
Current matrix effect configuration
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_light_state |
Create MatrixLightState from LightState. |
Attributes¶
Functions¶
from_light_state
classmethod
¶
from_light_state(
light_state: LightState,
chain: list[TileInfo],
tile_orientations: dict[int, str],
tile_colors: list[HSBK],
effect: FirmwareEffect,
) -> MatrixLightState
Create MatrixLightState from LightState.
Source code in src/lifx/devices/matrix.py
TileInfo¶
Information dataclass for a single tile in the device chain. Returned as part of MatrixLightState.chain.
TileInfo
dataclass
¶
TileInfo(
tile_index: int,
accel_meas_x: int,
accel_meas_y: int,
accel_meas_z: int,
user_x: float,
user_y: float,
width: int,
height: int,
supported_frame_buffers: int,
device_version_vendor: int,
device_version_product: int,
device_version_version: int,
firmware_build: int,
firmware_version_minor: int,
firmware_version_major: int,
)
Information about a single tile in the device chain.
| ATTRIBUTE | DESCRIPTION |
|---|---|
tile_index |
Index of this tile in the chain (0-based)
TYPE:
|
accel_meas_x |
Accelerometer measurement X
TYPE:
|
accel_meas_y |
Accelerometer measurement Y
TYPE:
|
accel_meas_z |
Accelerometer measurement Z
TYPE:
|
user_x |
User-defined X position
TYPE:
|
user_y |
User-defined Y position
TYPE:
|
width |
Tile width in zones
TYPE:
|
height |
Tile height in zones
TYPE:
|
supported_frame_buffers |
frame buffer count
TYPE:
|
device_version_vendor |
Device vendor ID
TYPE:
|
device_version_product |
Device product ID
TYPE:
|
device_version_version |
Device version
TYPE:
|
firmware_build |
Firmware build timestamp
TYPE:
|
firmware_version_minor |
Firmware minor version
TYPE:
|
firmware_version_major |
Firmware major version
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_protocol |
Create TileInfo from protocol TileStateDevice. |
Attributes¶
requires_frame_buffer
property
¶
requires_frame_buffer: bool
Check if tile has more than 64 zones (requires frame buffer strategy).
nearest_orientation
property
¶
nearest_orientation: str
Determine the orientation of the tile from accelerometer data.
Functions¶
from_protocol
classmethod
¶
Create TileInfo from protocol TileStateDevice.
| PARAMETER | DESCRIPTION |
|---|---|
tile_index
|
Index of this tile in the chain (0-based)
TYPE:
|
protocol_tile
|
Protocol TileStateDevice object
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TileInfo
|
TileInfo instance |
Source code in src/lifx/devices/matrix.py
MatrixEffect¶
Configuration dataclass for matrix effects (MORPH, FLAME, SKY). Used with MatrixLight.set_effect() and returned by MatrixLight.get_effect().
MatrixEffect
dataclass
¶
MatrixEffect(
effect_type: FirmwareEffect,
speed: int,
duration: int = 0,
palette: list[HSBK] | None = None,
sky_type: TileEffectSkyType = SUNRISE,
cloud_saturation_min: int = 0,
cloud_saturation_max: int = 0,
)
Matrix effect configuration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
effect_type |
Type of effect (OFF, MORPH, FLAME, SKY)
TYPE:
|
speed |
Effect speed in milliseconds
TYPE:
|
duration |
Total effect duration in nanoseconds (0 for infinite)
TYPE:
|
palette |
Color palette for the effect (max 16 colors) |
sky_type |
Sky effect type (SUNRISE, SUNSET, CLOUDS)
TYPE:
|
cloud_saturation_min |
Minimum cloud saturation (0-255, for CLOUDS sky type)
TYPE:
|
cloud_saturation_max |
Maximum cloud saturation (0-255, for CLOUDS sky type)
TYPE:
|
Ceiling Light¶
The CeilingLight class extends MatrixLight with independent control over uplight and downlight components for LIFX Ceiling fixtures.
CeilingLight
¶
CeilingLight(
serial: str,
ip: str,
port: int = 56700,
timeout: float = 0.5,
max_retries: int = 3,
state_file: str | None = None,
)
Bases: MatrixLight
LIFX Ceiling Light with independent uplight and downlight control.
CeilingLight extends MatrixLight to provide semantic control over uplight and downlight components while maintaining full backward compatibility with the MatrixLight API.
The uplight component is the last zone in the matrix, and the downlight component consists of all other zones.
Example
from lifx.devices import CeilingLight
from lifx.color import HSBK
async with await CeilingLight.from_ip("192.168.1.100") as ceiling:
# Independent component control
await ceiling.set_downlight_colors(HSBK(hue=0, sat=0, bri=1.0, kelvin=3500))
await ceiling.set_uplight_color(HSBK(hue=30, sat=0.2, bri=0.3, kelvin=2700))
# Turn components on/off
await ceiling.turn_downlight_on()
await ceiling.turn_uplight_off()
# Check component state
if ceiling.uplight_is_on:
print("Uplight is on")
| PARAMETER | DESCRIPTION |
|---|---|
serial
|
Device serial number
TYPE:
|
ip
|
Device IP address
TYPE:
|
port
|
Device UDP port (default: 56700)
TYPE:
|
timeout
|
Overall timeout for network requests in seconds (default: 0.5)
TYPE:
|
max_retries
|
Maximum number of retry attempts for network requests (default: 3)
TYPE:
|
state_file
|
Optional path to JSON file for state persistence
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxError
|
If device is not a supported Ceiling product |
| METHOD | DESCRIPTION |
|---|---|
refresh_state |
Refresh ceiling light state from hardware. |
from_ip |
Create CeilingLight from IP address. |
get_uplight_color |
Get current uplight component color from device. |
get_downlight_colors |
Get current downlight component colors from device. |
set_uplight_color |
Set uplight component color. |
set_downlight_colors |
Set downlight component colors. |
turn_uplight_on |
Turn uplight component on. |
turn_uplight_off |
Turn uplight component off. |
turn_downlight_on |
Turn downlight component on. |
set_power |
Set light power state, capturing component colors before turning off. |
set_color |
Set light color, updating component state tracking. |
turn_downlight_off |
Turn downlight component off. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
state |
Get Ceiling light state.
TYPE:
|
uplight_zone |
Zone index of the uplight component.
TYPE:
|
downlight_zones |
Slice representing the downlight component zones.
TYPE:
|
downlight_zone_count |
Number of downlight zones.
TYPE:
|
uplight_is_on |
True if uplight component is currently on.
TYPE:
|
downlight_is_on |
True if downlight component is currently on.
TYPE:
|
Source code in src/lifx/devices/ceiling.py
Attributes¶
state
property
¶
state: CeilingLightState
Get Ceiling light state.
| RETURNS | DESCRIPTION |
|---|---|
CeilingLightState
|
CeilingLightState with current state information. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If accessed before state initialization. |
uplight_is_on
property
¶
uplight_is_on: bool
True if uplight component is currently on.
Calculated as: power_level > 0 AND uplight brightness > 0
Note
Requires recent data from device. Call get_uplight_color() or get_power() to refresh cached values before checking this property.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if uplight component is on, False otherwise |
downlight_is_on
property
¶
downlight_is_on: bool
True if downlight component is currently on.
Calculated as: power_level > 0 AND NOT all downlight zones have brightness == 0
Note
Requires recent data from device. Call get_downlight_colors() or get_power() to refresh cached values before checking this property.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if downlight component is on, False otherwise |
Functions¶
refresh_state
async
¶
Refresh ceiling light state from hardware.
Fetches color, tiles, tile colors, effect, and ceiling component state.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If state has not been initialized |
LifxTimeoutError
|
If device does not respond |
LifxDeviceNotFoundError
|
If device cannot be reached |
Source code in src/lifx/devices/ceiling.py
from_ip
async
classmethod
¶
from_ip(
ip: str,
port: int = 56700,
serial: str | None = None,
timeout: float = 0.5,
max_retries: int = 3,
*,
state_file: str | None = None,
) -> CeilingLight
Create CeilingLight from IP address.
| PARAMETER | DESCRIPTION |
|---|---|
ip
|
Device IP address
TYPE:
|
port
|
Port number (default LIFX_UDP_PORT)
TYPE:
|
serial
|
Serial number as 12-digit hex string
TYPE:
|
timeout
|
Request timeout for this device instance
TYPE:
|
max_retries
|
Maximum number of retries for requests
TYPE:
|
state_file
|
Optional path to JSON file for state persistence
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CeilingLight
|
CeilingLight instance |
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
Device not found at IP |
LifxTimeoutError
|
Device did not respond |
LifxError
|
Device is not a supported Ceiling product |
Source code in src/lifx/devices/ceiling.py
get_uplight_color
async
¶
get_uplight_color() -> HSBK
Get current uplight component color from device.
| RETURNS | DESCRIPTION |
|---|---|
HSBK
|
HSBK color of uplight zone |
| RAISES | DESCRIPTION |
|---|---|
LifxTimeoutError
|
Device did not respond |
Source code in src/lifx/devices/ceiling.py
get_downlight_colors
async
¶
Get current downlight component colors from device.
| RETURNS | DESCRIPTION |
|---|---|
list[HSBK]
|
List of HSBK colors for each downlight zone (63 or 127 zones) |
| RAISES | DESCRIPTION |
|---|---|
LifxTimeoutError
|
Device did not respond |
Source code in src/lifx/devices/ceiling.py
set_uplight_color
async
¶
Set uplight component color.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
HSBK color to set
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If color.brightness == 0 (use turn_uplight_off instead) |
LifxTimeoutError
|
Device did not respond |
Note
Also updates stored state for future restoration.
Source code in src/lifx/devices/ceiling.py
set_downlight_colors
async
¶
Set downlight component colors.
| PARAMETER | DESCRIPTION |
|---|---|
colors
|
Either: - Single HSBK: sets all downlight zones to same color - List[HSBK]: sets each zone individually (must match zone count) |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any color.brightness == 0 (use turn_downlight_off instead) |
ValueError
|
If list length doesn't match downlight zone count |
LifxTimeoutError
|
Device did not respond |
Note
Also updates stored state for future restoration.
Source code in src/lifx/devices/ceiling.py
turn_uplight_on
async
¶
Turn uplight component on.
If the entire light is off, this will set the color instantly and then turn on the light with the specified duration, so the light fades to the target color instead of flashing to its previous state.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Optional HSBK color. If provided: - Uses this color immediately - Updates stored state If None, uses brightness determination logic
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If color.brightness == 0 |
LifxTimeoutError
|
Device did not respond |
Source code in src/lifx/devices/ceiling.py
turn_uplight_off
async
¶
Turn uplight component off.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
Optional HSBK color to store for future turn_on. If provided, stores this color (with brightness=0 on the device). If None, stores current color from device before turning off.
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If color.brightness == 0 |
LifxTimeoutError
|
Device did not respond |
Note
Sets uplight zone brightness to 0 on device while preserving H, S, K.
Source code in src/lifx/devices/ceiling.py
turn_downlight_on
async
¶
Turn downlight component on.
If the entire light is off, this will set the colors instantly and then turn on the light with the specified duration, so the light fades to the target colors instead of flashing to its previous state.
| PARAMETER | DESCRIPTION |
|---|---|
colors
|
Optional colors. Can be: - None: uses brightness determination logic - Single HSBK: sets all downlight zones to same color - List[HSBK]: sets each zone individually (must match zone count) If provided, updates stored state. |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any color.brightness == 0 |
ValueError
|
If list length doesn't match downlight zone count |
LifxTimeoutError
|
Device did not respond |
Source code in src/lifx/devices/ceiling.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
set_power
async
¶
Set light power state, capturing component colors before turning off.
Overrides Light.set_power() to capture the current uplight and downlight colors before turning off the entire light. This allows subsequent calls to turn_uplight_on() or turn_downlight_on() to restore the colors that were active just before the light was turned off.
The captured colors preserve hue, saturation, and kelvin values even if a component was already off (brightness=0). The brightness will be determined at turn-on time using the standard brightness inference logic.
| PARAMETER | DESCRIPTION |
|---|---|
level
|
True/65535 to turn on, False/0 to turn off |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If integer value is not 0 or 65535 |
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/ceiling.py
set_color
async
¶
Set light color, updating component state tracking.
Overrides Light.set_color() to track the color change in the ceiling light's component state. When set_color() is called, all zones (uplight and downlight) are set to the same color. This override ensures that the cached component colors stay in sync so that subsequent component control methods (like turn_uplight_on or turn_downlight_on) use the correct color values.
| PARAMETER | DESCRIPTION |
|---|---|
color
|
HSBK color to set for the entire light
TYPE:
|
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LifxDeviceNotFoundError
|
If device is not connected |
LifxTimeoutError
|
If device does not respond |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
from lifx.color import HSBK
# Set entire ceiling light to warm white
await ceiling.set_color(
HSBK(hue=0, saturation=0, brightness=1.0, kelvin=2700)
)
# Later component control will use this color
await ceiling.turn_uplight_off() # Uplight off
await ceiling.turn_uplight_on() # Restores to warm white
Source code in src/lifx/devices/ceiling.py
turn_downlight_off
async
¶
Turn downlight component off.
| PARAMETER | DESCRIPTION |
|---|---|
colors
|
Optional colors to store for future turn_on. Can be: - None: stores current colors from device - Single HSBK: stores this color for all zones - List[HSBK]: stores individual colors (must match zone count) If provided, stores these colors (with brightness=0 on device). |
duration
|
Transition duration in seconds (default 0.0)
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any color.brightness == 0 |
ValueError
|
If list length doesn't match downlight zone count |
LifxTimeoutError
|
Device did not respond |
Note
Sets all downlight zone brightness to 0 on device while preserving H, S, K.
Source code in src/lifx/devices/ceiling.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | |
CeilingLightState¶
The CeilingLightState dataclass extends MatrixLightState with ceiling-specific component information. It is returned by CeilingLight.state after connecting to a device.
CeilingLightState
dataclass
¶
CeilingLightState(
model: str,
label: str,
serial: str,
mac_address: str,
capabilities: DeviceCapabilities,
power: int,
host_firmware: FirmwareInfo,
wifi_firmware: FirmwareInfo,
location: CollectionInfo,
group: CollectionInfo,
last_updated: float,
color: HSBK,
chain: list[TileInfo],
tile_orientations: dict[int, str],
tile_colors: list[HSBK],
tile_count: int,
effect: FirmwareEffect,
uplight_color: HSBK,
downlight_colors: list[HSBK],
uplight_is_on: bool,
downlight_is_on: bool,
uplight_zone: int,
downlight_zones: slice,
)
Bases: MatrixLightState
Ceiling light device state with uplight/downlight component control.
Extends MatrixLightState with ceiling-specific component information.
| ATTRIBUTE | DESCRIPTION |
|---|---|
uplight_color |
Current HSBK color of the uplight component
TYPE:
|
downlight_colors |
List of HSBK colors for each downlight zone |
uplight_is_on |
Whether uplight component is on (brightness > 0)
TYPE:
|
downlight_is_on |
Whether downlight component is on (any zone brightness > 0)
TYPE:
|
uplight_zone |
Zone index for the uplight component
TYPE:
|
downlight_zones |
Slice representing downlight component zones
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
from_matrix_state |
Create CeilingLightState from MatrixLightState. |
Attributes¶
Functions¶
from_matrix_state
classmethod
¶
from_matrix_state(
matrix_state: MatrixLightState,
uplight_color: HSBK,
downlight_colors: list[HSBK],
uplight_zone: int,
downlight_zones: slice,
) -> CeilingLightState
Create CeilingLightState from MatrixLightState.
| PARAMETER | DESCRIPTION |
|---|---|
matrix_state
|
Base MatrixLightState to extend
TYPE:
|
uplight_color
|
Current uplight zone color
TYPE:
|
downlight_colors
|
Current downlight zone colors |
uplight_zone
|
Zone index for uplight component
TYPE:
|
downlight_zones
|
Slice representing downlight component zones
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CeilingLightState
|
CeilingLightState with all matrix state plus ceiling components |
Source code in src/lifx/devices/ceiling.py
Device Properties¶
MAC Address¶
The mac_address property provides the device's MAC address, calculated from the serial number
and host firmware version. The calculation is performed automatically when the device is used
as a context manager or when get_host_firmware() is called.
Calculation Logic (based on host firmware major version):
- Version 2 or 4: MAC address matches the serial number
- Version 3: MAC address is the serial number with the least significant byte incremented by 1 (with wraparound from 0xFF to 0x00)
- Unknown versions: Defaults to the serial number
The MAC address is returned in colon-separated lowercase hexadecimal format (e.g., d0:73:d5:01:02:03)
to visually distinguish it from the serial number format.
from lifx import Device
async def main():
async with await Device.from_ip("192.168.1.100") as device:
# MAC address is automatically calculated during setup
if device.mac_address:
print(f"Serial: {device.serial}")
print(f"MAC: {device.mac_address}")
# Returns None before host_firmware is fetched
assert device.mac_address is not None
Examples¶
Basic Light Control¶
from lifx import Light, Colors
async def main():
async with await Light.from_ip("192.168.1.100") as light:
# Turn on and set color
await light.set_power(True)
await light.set_color(Colors.BLUE, duration=1.0)
# Get device info
label = await light.get_label()
print(f"Controlling: {label}")
Light Effects¶
from lifx import Light, Colors
async def main():
async with await Light.from_ip("192.168.1.100") as light:
# Pulse effect
await light.pulse(Colors.RED, period=1.0, cycles=5)
# Breathe effect
await light.breathe(Colors.BLUE, period=2.0, cycles=3)
HEV Light Control (Anti-Bacterial Cleaning)¶
from lifx import HevLight
async def main():
async with await HevLight.from_ip("192.168.1.100") as light:
# Start a 2-hour cleaning cycle
await light.set_hev_cycle(enable=True, duration_seconds=7200)
# Check cycle status
state = await light.get_hev_cycle()
if state.is_running:
print(f"Cleaning: {state.remaining_s}s remaining")
# Configure default settings
await light.set_hev_config(indication=True, duration_seconds=7200)
Infrared Light Control (Night Vision)¶
from lifx import InfraredLight
async def main():
async with await InfraredLight.from_ip("192.168.1.100") as light:
# Set infrared brightness to 50%
await light.set_infrared(0.5)
# Get current infrared brightness
brightness = await light.get_infrared()
print(f"IR brightness: {brightness * 100}%")
Ambient Light Sensor¶
Light devices with ambient light sensors can measure the current ambient light level in lux:
from lifx import Light
async def main():
async with await Light.from_ip("192.168.1.100") as light:
# Ensure light is off for accurate reading
await light.set_power(False)
# Get ambient light level in lux
lux = await light.get_ambient_light_level()
if lux > 0:
print(f"Ambient light: {lux} lux")
else:
print("No ambient light sensor or completely dark")
Notes:
- Devices without ambient light sensors return 0.0 (not an error)
- For accurate readings, the light should be turned off (otherwise the light's own illumination interferes with the sensor)
- This is a volatile property - always fetched fresh from the device
- A reading of 0.0 could mean either no sensor or complete darkness
- Returns ambient light level in lux (higher values indicate brighter ambient light)
MultiZone Control¶
from lifx import MultiZoneLight, Colors, FirmwareEffect, Direction
async def main():
async with await MultiZoneLight.from_ip("192.168.1.100") as light:
# Get all zones - automatically uses best method
colors = await light.get_all_color_zones()
print(f"Device has {len(colors)} zones")
# Set a MOVE effect
await light.set_effect(
effect_type=FirmwareEffect.MOVE,
speed=5.0, # seconds per cycle
direction=Direction.FORWARD,
)
# Get current effect
effect = await light.get_effect()
print(f"Effect: {effect.effect_type.name}")
if effect.effect_type == FirmwareEffect.MOVE:
print(f"Direction: {effect.direction.name}")
# Stop the effect
await light.set_effect(effect_type=FirmwareEffect.OFF)
Tile Control¶
from lifx import MatrixLight, HSBK, FirmwareEffect
async def main():
async with await MatrixLight.from_ip("192.168.1.100") as light:
# Set a gradient across the tile
colors = [
HSBK(hue=h, saturation=1.0, brightness=0.5, kelvin=3500)
for h in range(0, 360, 10)
]
await light.set_tile_colors(colors)
# Set a tile effect (MORPH, FLAME, or SKY)
await light.set_effect(
effect_type=FirmwareEffect.FLAME,
speed=5.0, # seconds per cycle
)
# Get current effect
effect = await light.get_effect()
print(f"Tile effect: {effect.effect_type.name}")
# Stop the effect
await light.set_effect(effect_type=FirmwareEffect.OFF)
Ceiling Light Control¶
from lifx import CeilingLight, HSBK
async def main():
async with await CeilingLight.from_ip("192.168.1.100") as ceiling:
# Set downlight to warm white
await ceiling.set_downlight_colors(
HSBK(hue=0, saturation=0, brightness=0.8, kelvin=3000)
)
# Set uplight to a dim ambient glow
await ceiling.set_uplight_color(
HSBK(hue=30, saturation=0.2, brightness=0.3, kelvin=2700)
)
# Turn uplight off (stores color for later restoration)
await ceiling.turn_uplight_off()
# Turn uplight back on (restores previous color)
await ceiling.turn_uplight_on()
# Check component state
if ceiling.downlight_is_on:
print("Downlight is currently on")
For detailed CeilingLight usage, see the Ceiling Lights User Guide.