A Python library for interacting with Lytiva devices via MQTT.
Project description
Lytiva Connect Library
A standalone Python library for interacting with Lytiva smart devices via MQTT. This library handles the protocol logic for Lytiva lights, including dimmers, CCT (Color Temperature), and RGB devices.
Installation
pip install lytiva-connect
How to use with MQTT
Lytiva devices communicate via JSON payloads over MQTT. This library helps you generate those payloads and parse the status messages returned by devices.
1. Basic Light Control (Dimmer)
To turn on a light and set its brightness:
import json
from lytiva import LytivaDevice
# Initialize device at address 10
device = LytivaDevice(address=10, device_type="dimmer")
# Generate the ON payload with 75% brightness (191 out of 255)
payload_dict = device.get_turn_on_payload(brightness=191)
payload_json = json.dumps(payload_dict)
# Publish payload_json to your MQTT command topic
# Example topic: LYT/{unique_id}/NODE/CONTROL
print(f"Publish to MQTT: {payload_json}")
# Output: {"address": 10, "type": "dimmer", "dimming": 75}
2. CCT (Color Temperature) Control
device = LytivaDevice(address=20, device_type="cct")
# Set brightness to 100% and temperature to 4000K
payload = device.get_turn_on_payload(brightness=255, kelvin=4000)
# Output: {"address": 20, "type": "cct", "dimming": 100, "color_temperature": 50}
3. RGB Color Control
device = LytivaDevice(address=30, device_type="rgb")
# Set color to Red (255, 0, 0)
payload = device.get_turn_on_payload(rgb=(255, 0, 0))
# Output: {"address": 30, "type": "rgb", "r": 255, "g": 0, "b": 0, "dimming": 100}
4. Decoding Status Messages
Lytiva devices return status with nested objects. This library decodes them into simple Python dictionaries:
# Example topic : LYT/{unique_id}/NODE/E/STATUS
# Actual message format:
raw_mqtt_message = '{"address": 10, "type": "cct", "cct": {"dimming": 40, "color_temperature": 100}}'
status = device.decode_status(raw_mqtt_message)
print(status)
# Returns: {'is_on': True, 'brightness': 102, 'kelvin': 6500}
Features
- Scalable payload generation for all Lytiva device types.
- Nested JSON support for robust status decoding.
- Automatic Color Temperature scaling (0-100) and Kelvin conversion.
- Helper functions for Mireds/Kelvin conversion.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lytiva_connect-1.0.1.tar.gz.
File metadata
- Download URL: lytiva_connect-1.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61d2a6ab2a578c2ee227a617f904d2e51d230ba42ac33316a36597c846bce3a6
|
|
| MD5 |
507fcda9fb68409297ac6148f3f50dea
|
|
| BLAKE2b-256 |
f3b982bd25e3c6de302dd8f2de079003e990f0c259b520ec9a7eee3d480d7567
|
File details
Details for the file lytiva_connect-1.0.1-py3-none-any.whl.
File metadata
- Download URL: lytiva_connect-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ab7d21d1c8953017be0fd176dbc3f3822222f30a804b17498e1d81051b8c12c
|
|
| MD5 |
57e4e25f14321602572e57f7da0c1499
|
|
| BLAKE2b-256 |
c82923b33047b870cf504156811c614251ca24d3d43ddf327829a1f267f8eaac
|