A python library for controlling shelly devices
Project description
ShellyControl
ShellyControl is a Python library for controlling and managing Shelly smart devices via HTTP and MQTT protocols. It provides an easy-to-use interface to interact with Shelly devices, retrieve their status, configure settings, and perform actions such as OTA updates and reboots.
Features
- Supports communication with Shelly devices via HTTP and MQTT
- Retrieve device status, settings, and actions
- Perform OTA updates and reboots
- Factory reset Shelly devices
- MQTT authentication support
- Easily extensible for different Shelly models
Installation
To install ShellyControl, you need Python 3.7 or later. Install the required dependencies using pip:
pip install requests paho-mqtt
Alternatively, if you have a requirements.txt file, install the dependencies with:
pip install -r requirements.txt
Usage
Importing the Library
from shellycontrol import ShellyDevice
Creating a Shelly Device Instance
You can initialize a Shelly device using either HTTP or MQTT:
Using HTTP:
device = ShellyDevice(deviceID="shelly1", ip="192.168.1.100")
Using MQTT:
device = ShellyDevice(deviceID="shelly1", mqttBroker="mqtt.example.com", mqttPort=1883, username="user", password="pass")
Retrieve Device Status
status = device.getStatus()
print(status)
Retrieve Device Settings
settings = device.getSettings()
print(settings)
Retrieve Device Actions
actions = device.getActions()
print(actions)
Perform OTA Update
device.OTAUpdate()
Reboot Device
device.reboot()
Factory Reset
device.factoryReset()
Available Classes and Methods
ShellyDevice Class
Constructor
ShellyDevice(deviceID, ip=None, mqttBroker=None, mqttPort=1883, username=None, password=None)
deviceID(str): Unique identifier of the Shelly device.ip(str, optional): IP address of the device (if using HTTP).mqttBroker(str, optional): MQTT broker address (if using MQTT).mqttPort(int, optional): MQTT broker port (default is 1883).username(str, optional): Username for authentication.password(str, optional): Password for authentication.
Methods
def sendHTTPRequest(endpoint, params=None)
- Sends an HTTP request to the Shelly device.
endpoint(str): API endpoint (e.g., "status").params(dict, optional): Request parameters.- Returns: JSON response if successful, else None.
def sendMQTTCommand(topic, payload)
- Sends an MQTT message.
topic(str): MQTT topic.payload(str): Message payload.
def getStatus()
- Retrieves device status.
- Returns: JSON response with device status.
def getSettings()
- Retrieves device settings.
- Returns: JSON response with device settings.
def getActions()
- Retrieves available device actions.
- Returns: JSON response with device actions.
def OTAUpdate()
- Performs an over-the-air (OTA) update.
def reboot()
- Reboots the device.
def factoryReset()
- Resets the device to factory settings.
Supported Shelly Devices
ShellyControl is designed to work with multiple Shelly devices, including:
- Shelly 3EM
- Shelly Dimmer 2
- Shelly Duo E27/GU10
- Shelly Plug
- Shelly Plus 1/1PM/2PM
- Shelly Pro 1/1PM/2/2PM/3/4PM
- Shelly RGBW2
- Shelly TRV
- Shelly Uni
- Shelly Vintage
Contributing
Contributions are welcome! Feel free to submit issues or pull requests.
License
This project is licensed under the MIT License.
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 pyshellycontrol-0.1.0.tar.gz.
File metadata
- Download URL: pyshellycontrol-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc676363011b171cb9e4b723be06ee6578914ba8d48507d457a6c7ee12f60cdd
|
|
| MD5 |
7d581db8ef165ba6d0bb8af0ee2d757d
|
|
| BLAKE2b-256 |
7e6261c61a6d8af595c906029c19614343f6e32ff19266dcc14888a264ff4169
|
File details
Details for the file PyShellyControl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: PyShellyControl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8248db1952eed64b5307d2182e8bb1caea1d13905dcf39824b2b830535aa91a
|
|
| MD5 |
ebaad148ebef1dd52b0418cee5afa2ac
|
|
| BLAKE2b-256 |
77fee9aa50ac82329e5146797482934dac00a36fcd2d4df04ca3272e260c8fab
|