Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ I finally came across Peter's work written in python and it was exactly what I w

Use pip or easy_install

> pip install sonoff-python
> pip install git+https://github.com/Baton34/sonoff-python

The requirements are requests and websocket-client, see _requirements.txt_

Expand All @@ -38,38 +38,18 @@ Here's a really simple example of how you can use this library.

```
import sonoff
import json
import signal
import sys
import requests

device_name = 'SonoffBridge'
sensor_name = 'Motion sensor 1'

def signal_handler(signal, frame):
sys.exit(0)

def on_message(*args):
data = json.loads(args[-1])
print(data)

def on_error(*args):
print(args[-1])

def main():
signal.signal(signal.SIGINT, signal_handler)

connection = sonoff.Sonoff(
'username',
'password',
'eu'
)
connection = sonoff.Sonoff('username', 'password', 'eu')

for device in connection.get_devices():
print(device['name'])

if device['name'] == device_name:
device_data = connection.get_device(device['deviceid'])
connection.wait_for_notice(device['deviceid'], on_message, on_error)
break
print(device_data)

if __name__ == '__main__':
main()
Expand Down