Created
November 10, 2017 21:39
-
-
Save MichaelWhi/89fe680a233927a6aa368574d71627f7 to your computer and use it in GitHub Desktop.
Turn TP Link SmartPlug on and off via Command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $1 = "1" ]; then | |
curl -XPOST -H "Content-type: application/json" -d '{"method":"passthrough", | |
"params": {"deviceId": "DEVICEID", | |
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}}}" } | |
}' 'https://eu-wap.tplinkcloud.com?token=TOKEN' | |
else | |
curl -XPOST -H "Content-type: application/json" -d '{"method":"passthrough", | |
"params": {"deviceId": "DEVICEID", | |
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":0}}}" } | |
}' 'https://eu-wap.tplinkcloud.com?token=TOKEN' | |
fi | |
exit 0 | |
============= | |
Nothing down here will be executed. | |
This is just DOCUMENTATION. | |
============= | |
How to get TOKEN: | |
================== | |
1) Get an UUID v4 from https://www.uuidgenerator.net/version4 or run `uuid` in the Mac terminal. Replace it in the command below. | |
2) Replace your username (email address) and password from your Kasa account below. | |
2) Run this with the replaced UUID and your email address (as user name) and your password in the console: | |
curl -XPOST -H "Content-type: application/json" -d '{ | |
"method": "login", | |
"params": { | |
"appType": "Kasa_Android", | |
"cloudUserName": "[email protected]", | |
"cloudPassword": "PASS", | |
"terminalUUID": "REPLACE THIS WITH A v4 UUID!!!" | |
}}' 'https://wap.tplinkcloud.com' | |
3) write it down here, look for the "token": | |
Your TOKEN ("token"): | |
> ... | |
# from http://itnerd.space/2017/06/19/how-to-authenticate-to-tp-link-cloud-api/ | |
How to get Device ID(s): | |
======================= | |
1) Use your token from above and replace the command below with it. | |
2) Run the command in the console with your token. | |
3) You will get a list of your devices. Check for the "deviceId". | |
If you need to format the response to better read it, paste it at http://jsonviewer.stack.hu and click the "Viewer" tab. | |
curl -s --request POST "https://wap.tplinkcloud.com?token=TOKEN HTTP/1.1" \ | |
--data '{"method":"getDeviceList"}' \ | |
--header "Content-Type: application/json" | |
4) Search your "deviceId" and write it down: | |
Your Device ID ("deviceId"): | |
> ... | |
FINALLY: | |
========= | |
1) Replace those two variables in the two commands at the top. | |
You will need to replace twice the TOKEN and twice the DEVICEID. | |
2) Then save. You can now run the script in the console with | |
./tplink.sh 1 # to turn on | |
or | |
./tplink.sh 0 # to turn off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment