Device Classes¶
Device classes provide direct control over LIFX devices. All device classes support async context managers for automatic resource cleanup.
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,
)
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. |
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
capabilities |
Get device product capabilities.
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
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
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. |
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
¶
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
¶
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
¶
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
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 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 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 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 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 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 device location information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
LocationInfo
|
LocationInfo 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
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 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 | |
get_group
async
¶
Get device group information.
Always fetches from device.
| RETURNS | DESCRIPTION |
|---|---|
GroupInfo
|
GroupInfo 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
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 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | |
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
Light¶
The Light class provides color control and effects for standard LIFX lights.
Light
¶
Bases: Device
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
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¶
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
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 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 | |
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
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 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 | |
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
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
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¶
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
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
infrared |
Get cached infrared brightness if available.
TYPE:
|
Source code in src/lifx/devices/infrared.py
Attributes¶
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
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
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¶
multizone_effect
property
¶
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
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 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 | |
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
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 | |
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
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 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 | |
set_extended_color_zones
async
¶
set_extended_color_zones(
zone_index: int,
colors: list[HSBK],
duration: float = 0.0,
apply: MultiZoneApplicationRequest = APPLY,
) -> 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:
|
| 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 |
LifxUnsupportedCommandError
|
If device doesn't support this command |
Example
Source code in src/lifx/devices/multizone.py
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 | |
get_effect
async
¶
Get current multizone effect.
Always fetches from device.
Use the multizone_effect property to access stored value.
| RETURNS | DESCRIPTION |
|---|---|
MultiZoneEffect | None
|
MultiZoneEffect if an effect is active, None if no effect |
| 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 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
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 | |
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
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)
| PARAMETER | DESCRIPTION |
|---|---|
serial
|
Device serial number
|
ip
|
Device IP address
|
port
|
Device port (default: 56700)
|
| 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. |
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. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
device_chain |
Get cached device chain.
TYPE:
|
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¶
device_chain
property
¶
device_chain: list[TileInfo] | None
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
¶
Get cached tile effect.
Returns None if not yet fetched. Use get_tile_effect() to fetch.
Functions¶
get_device_chain
async
¶
get_device_chain() -> list[TileInfo]
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
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 446 447 448 449 450 451 452 453 454 | |
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
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 | |
copy_frame_buffer
async
¶
copy_frame_buffer(
tile_index: int,
source_fb: int = 1,
target_fb: int = 0,
duration: float = 0.0,
) -> 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:
|
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 ... )
Source code in src/lifx/devices/matrix.py
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 | |
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
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 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | |
get_effect
async
¶
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
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 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 | |
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
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)