Install
$ brew install npm
$ npm install -g tplink-smarthome-api
Search Device
$ tplink-smarthome-api search
Searching...
startDiscovery({
discoveryInterval: 2000,
discoveryTimeout: 10000,
breakoutChildren: true,
broadcast: '255.255.255.255'
})
HS105(JP) plug IOT.SMARTPLUGSWITCH 192.168.xxx.xxx 9999 XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX HS105-1
Power ON/OFF
$ IP_ADDRESS="192.168.xxx.xxx"
// Power ON
$ tplink-smarthome-api -D send $IP_ADDRESS:9999 '{"system":{"set_relay_state":{"state":1}}}'
// Power OFF
$ tplink-smarthome-api -D send $IP_ADDRESS:9999 '{"system":{"set_relay_state":{"state":0}}}'
// Check stauts
$ tplink-smarthome-api getInfo $IP_ADDRESS:9999
Reference
https://github.com/plasticrake/tplink-smarthome-api
Install
$ sudo pip3 install --upgrade pip
$ pip3 install git+https://github.com/vrachieru/tplink-smartplug-api.git
Get info
$ emacs info.py
from tplink_smartplug import SmartPlug
plug = SmartPlug('192.168.xxx.xxx')
print('Name: %s' % plug.name)
print('Model: %s' % plug.model)
print('Mac: %s' % plug.mac)
print('Time: %s' % plug.time)
print('Is on: %s' % plug.is_on)
print('Nightmode: %s' % (not plug.led))
print('RSSI: %s' % plug.rssi)
$ python3 ./info.py
Name: HS105-1
Model: HS105(JP)
Mac: 00:00:00:00:00:00
Time: 2021-02-03 22:13:26
Is on: False
Nightmode: False
RSSI: -42
Toggle Power
$ emacs toggle.py
from tplink_smartplug import SmartPlug
plug = SmartPlug('192.168.xxx.xxx')
if plug.is_on:
plug.turn_off()
print('Plug turned off')
else:
plug.turn_on()
print('Plug turned on')
$ python3 ./toggle.py
Plug turned off
$ python3 ./toggle.py
Plug turned on
Count down
$ emacs count_down.py
from tplink_smartplug import SmartPlug
plug = SmartPlug('192.168.xxx.xxx')
# delete countdown table
print(plug.command('{"count_down":{"delete_all_rules":null}}'))
# set countdown off ("act": 0)
print(plug.command('{"count_down":{"add_rule":{"enable":1,"delay":60,"act":0,"name":"turn off"}}}'))
$ python3 ./count_down.py
Reference