🏠🤖 Python API for TP-Link smarthome products
Go to file
2016-12-13 14:50:40 +08:00
examples Read all data from the device, disable double-encoding, implement more APIs, refactor querying, update README (#11) 2016-12-12 17:13:45 +08:00
pyHS100 Read all data from the device, disable double-encoding, implement more APIs, refactor querying, update README (#11) 2016-12-12 17:13:45 +08:00
.hound.yml set up hound-ci 2016-12-04 03:54:29 +01:00
LICENSE Update LICENSE 2016-10-18 09:40:42 +08:00
README.md Read all data from the device, disable double-encoding, implement more APIs, refactor querying, update README (#11) 2016-12-12 17:13:45 +08:00
setup.py Version bump (#16) 2016-12-13 14:50:40 +08:00

pyHS100

Python Library to control TPLink Switch (HS100 / HS110)

Usage

For all available API functions run help(SmartPlug)

from pyHS100 import SmartPlug
from pprint import pformat as pf

plug = SmartPlug("192.168.250.186")
print("Alias, type and supported features: %s" % (plug.identify(),))
print("Hardware: %s" % pf(plug.hw_info))
print("Full sysinfo: %s" % pf(plug.get_sysinfo())) # this prints lots of information about the device

Time information

print("Current time: %s" % plug.time)
print("Timezone: %s" % plug.timezone)

Getting and setting the name

print("Alias: %s" % plug.alias)
plug.alias = "My New Smartplug"

State & switching

print("Current state: %s" % plug.state)
plug.turn_off()
plug.turn_on()

or

plug.state = "ON"
plug.state = "OFF"

Getting emeter status (on HS110)

print("Current consumption: %s" % plug.get_emeter_realtime())
print("Per day: %s" % plug.get_emeter_daily(year=2016, month=12))
print("Per month: %s" % plug.get_emeter_monthly(year=2016))

Switching the led

print("Current LED state: %s" % plug.led)
plug.led = 0 # turn off led
print("New LED state: %s" % plug.led)

Example

There is also a simple tool for testing connectivity in examples, to use:

python -m examples.cli <ip>