Make use of your sonoff smart switches without flashing them via the cloud APIs, this should work in Python 2 or Python 3.
This project is heavily inspired (read: almost entirely borrowed) by the work that Peter Buga did on a Simple Home Assistant integration for Ewelink https://github.com/peterbuga/HASS-sonoff-ewelink
I spent a day looking into various ways to work with Sonoff switches and drew a bit of a blank. There seeem to be quite a few projects that are designed to replace the Ewelink cloud platform either by flashing the Sonoff switches with new firmware, or hijacking the setup process and running a fake cloud service locally on a Raspberry Pi or similar.
I tried this approach but it didn't work for me as I was using a 4 channel switch, and it seems that most of them had only been tested with single channel switches. Also many of these were not maintained actively or had clearly been written for a specific use case.
I finally came across Peter's work written in python and it was exactly what I was looking for, a class that I could instantiate and control my switch remotely without flashing or having to use Charles to sniff my authentication code etc.
## Configuration
Configuration is simple and basically passed to the class when you instantiate it. Username is either the email address you use to log in to Ewelink, or your phone number with the country code in front.
> **username** - The email address or phone number you signed up with on Ewelink. Preface phone number with the country code
> **password** - Your password to Ewelink.
> **api_region** - The API region you use, valid ones are apparently 'us', 'eu' and 'cn'
> **grace_period** - This defaults to 600, I don't know why yet.
## Usage
Here's a really simple example of how you can use this library.
```
import sonoff
import config
s = sonoff.Sonoff(config.username, config.password, config.api_region)
devices = s.get_devices()
if devices:
# We found a device, lets turn something on
device_id = devices[0]['deviceid']
s.switch('on', device_id, 0)
```
## Support
I have tested in Python 2 and Python 3, however as we all know there may be some library weirdness.
I mainly put this together for my own use, I have learned a little about how the Sonoff kit works but for support it might be better to look at the library Peter Buga put together. I'm happy to look at any issues though.
Metadata
Release files for sonoff-python 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sonoff-python-0.1.tar.gz | 5.5 kB | Without provenance | Details for sonoff-python-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sonoff_python-0.1-py3-none-any.whl | Python 3 | none | any | Details for sonoff_python-0.1-py3-none-any.whl |
Total release size: 12.2 kB
Release files / sonoff-python-0.1.tar.gz
| Download URL | sonoff-python-0.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
724513cd23dc409dee54a7474db53dd9457180012a16792cd18966b4da36c2fc
|
|
BLAKE2b-256 checksum How to use checksums |
41117841f2c3ee85b0249363c743f205ada079d39fa2f7936c5673dc7959c157
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.5
|
Release files / sonoff_python-0.1-py3-none-any.whl
| Download URL | sonoff_python-0.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7694df006686961cfafb34b9c8962b6a8a671146d4d0f69ebd5386a3b7821ce5
|
|
BLAKE2b-256 checksum How to use checksums |
34b46786bf85bd64be2aa715850b6ae16ac0e58a7aa13651dfcd22deb16f2115
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.5
|
Security for sonoff-python 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.