A package to integrate Yeelight bulbs and lamps with MQTT Broker.
Project description
YeelightPool
A package to integrate Yeelight Bulbs with MQTT Brokers. This package intends to integrate Bulbs into Lamps within the network and manage it as a pool of devices that can be accessible through the MQTT Broker.
Introduction
The package is intended to establish an MQTT interface with the Yeelight device. The equipment attributes will be readable in the MQTT Broker through a topic in the form /<level0>/<level1>/attribute. The equipment will be located within a hierarchy of levels in the MQTT Broker, being the device located into 2 levels, typically location and equipment, and within the equipment all the attributes of this device.
The special attribute /<level0>/<level1>/<command> is serving as a special attribute to send commands to the device. The commands are those available from the library yeelight and the function behind this package simply wraps a json command with its arguments. This json content is simply passed onto the package yeelight and executes the command onto the equipment. The json document including the execution of a command is in the form:
{
"action": "name of the method",
"args": "{
"arg1": "value 1",
"arg2": "value 2",
"argN": "value N"
}
}
The name of the the method is one of the yeelight methods.
Workflow diagram
The device and the MQTT have the following communication diagram
sequenceDiagram
Device ->> YeelightPool: Device Status
YeelightPool -->> MQTT Broker: Publish Topics
MQTT Broker ->> User Program: Status attributes
User Program ->> MQTT Broker: { command, args }
MQTT Broker -->> YeelightPool: Subscribe Topics<br/>(command)
YeelightPool ->> Device: Function call<br/> Execution command
Note right of User Program: Async calls to execute<br/>commands on device.
Configuration file
The package gives the possibility to configure parameters through a configuration file. This file can be, as an example, like this:
[yeelight] logfile=yeelightpool.log lamps=[ ["192.168.0.101", "192.168.0.102"], ["192.168.0.103"] ] room=[ "Living Room", "Kids Room" ] device=[ "Ceiling Lamp", "Desk Lamp" ]
[broker] ip=127.0.0.1 port=1883
The configuration file will be splitted into two areas:
- [yeelight]: this area defines the lamps as a serie of bulb's ip addresses. The room name for the lamps. And the device name of the lamp. It also gives the chance to log data to a logfile.
- [broker]: this is the broker ip:port to connect to. This broker is to be setup apart from this package.
How to install
To install the library just execute:
pip install YeelightPool
Example
import sys import YeelightPool
def main(): # Configuration of the Shelly device config = YeelightPool.YeelightConfig(sys.argv[1]) params_yeelight = config.read(section="yeelight") params_broker = config.read(section="broker")
print(f"Yeelight Devices Pool Version {YeelightPool.version}") print(f"Creating Pool of Yeelight Devices . . . ", end="") pool = YeelightPool.YeelightPool(params_broker['ip'], int(params_broker['port'])) print(f"[ OK ]")
print(f"Running the pool") pool.start( eval(params_yeelight['lamps']), eval(params_yeelight['room']), eval(params_yeelight['device']) )
print(f"Finalizing Yeelight Pool . . . [ OK ]") > if name == "main": main()
Release Notes
0.1.1 - Initial release
Credits
- yeelight - https://pypi.org/project/yeelight/
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 yeelightpool-0.1.1.tar.gz.
File metadata
- Download URL: yeelightpool-0.1.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b84286d2184eadb7b40c415e45a1c61c4b4e7b3fe9f34e01fe641c6d9084af5
|
|
| MD5 |
d91d0ea8a3f798cf6a31c7f7a6ce9cd7
|
|
| BLAKE2b-256 |
b3c5a80d447dc09502f9cadcfa9a7e3757cd0e2549e51e747f122555b4a1300a
|
File details
Details for the file yeelightpool-0.1.1-py3-none-any.whl.
File metadata
- Download URL: yeelightpool-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
438462d10ed9208338373aff58222ac9ceb6efc00a8cfdcde08a5dd8ed646ae1
|
|
| MD5 |
a32ce2b26321ebafc2afc180c5c03dfe
|
|
| BLAKE2b-256 |
3d2d1a22e98fa54adaaafe3ee376443d951d52ce96223050a2f7e64f3105826b
|