🏠🤖 Python API for TP-Link smarthome products
Go to file
Teemu R 0b2e371e79 move SmartDeviceException to SmartDevice, and remove types.py complet… (#95)
* move SmartDeviceException to SmartDevice, and remove types.py completely. fixes #94

* do not import skipIf anymore
2017-10-07 17:41:51 +02:00
pyHS100 move SmartDeviceException to SmartDevice, and remove types.py complet… (#95) 2017-10-07 17:41:51 +02:00
.gitchangelog.rc Add changelog & add .gitchangelog.rc (#28) 2017-03-17 14:38:58 +01:00
.gitignore Add check to ensure devices with lat/lon with _i suffix are supported (#54) (#56) 2017-04-26 18:43:50 +02:00
.hound.yml set up hound-ci 2016-12-04 03:54:29 +01:00
.travis.yml add typing hints to make it easier for 3rd party developers to use the library (#90) 2017-09-18 18:13:06 +02:00
CHANGELOG add future requirement (#47) 2017-04-08 01:58:20 +02:00
HOWTO_RELEASE Release 0.2.4 preparations (#43) 2017-03-25 23:04:32 +01:00
LICENSE Update LICENSE 2016-10-18 09:40:42 +08:00
README.md Release 0.2.4 preparations (#43) 2017-03-25 23:04:32 +01:00
requirements.txt Add new client tool (#42) 2017-03-20 19:03:19 +01:00
setup.py add typing hints to make it easier for 3rd party developers to use the library (#90) 2017-09-18 18:13:06 +02:00
tox.ini add typing hints to make it easier for 3rd party developers to use the library (#90) 2017-09-18 18:13:06 +02:00

pyHS100

Python Library to control TPLink smart plugs (HS100, HS105, HS110, HS200) and TPLink smart bulbs (LB1xx).

Usage

The package is shipped with a console tool named pyhs100, please refer to pyhs100 --help for detailed usage. Note: The tool does not currently support bulb-specific commands, please feel free to prepare a pull request!

Discovering devices

$ pyhs100 discover

Discovering devices for 5 seconds
Found device: {'ip': '192.168.250.186',
 'port': 9999,
 'sys_info': {'emeter': {'get_realtime': {'current': 0.013309,
 <snip>

Querying the state

$ pyhs100 --ip 192.168.250.186

== My Smart Plug - HS110(EU) ==
Device state: OFF
LED state:    False
Time:         1970-01-01 01:52:35
On since:     2017-03-19 17:09:16.408657
Hardware:     1.0
Software:     1.0.8 Build 151101 Rel.24452
MAC (rssi):   50:C7:BF:XX:XX:XX (-61)
Location:     {'longitude': XXXX, 'latitude': XXXX}
== Emeter ==
Current state: {'power': 0, 'total': 0.001, 'current': 0.013552, 'voltage': 223.394238}

Library usage

For all available API functions run help(SmartPlug) or help(SmartBulb).

from pyHS100 import SmartPlug, SmartBulb
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 = False # turn off led
print("New LED state: %s" % plug.led)