Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. danielhickman revised this gist Sep 12, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -86,5 +86,6 @@ Request Data > Transition Light State:

    **Links:**

    * [Reddit discussion I made](https://www.reddit.com/r/ifttt/comments/6zla2d/guide_control_tplink_smart_bulbs/)
    * [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/WNkYa02.png)
    * [Reddit discussion I made](https://www.reddit.com/r/ifttt/comments/6zla2d/guide_control_tplink_smart_bulbs/)
    ![The above image example](https://i.imgur.com/WNkYa02.png)
  2. danielhickman revised this gist Sep 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -86,5 +86,5 @@ Request Data > Transition Light State:

    **Links:**

    * [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/Bnd3fz3.png)
    * [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/WNkYa02.png)
    * [Reddit discussion I made](https://www.reddit.com/r/ifttt/comments/6zla2d/guide_control_tplink_smart_bulbs/)
  3. danielhickman revised this gist Sep 12, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    **IFTTT Webhooks:**

    1. Create an applet with IFTTT Webhooks as the "That" portion (you can use anything for the "This")
    2. For the URL use your URL you created like:
    2. For the URL use your URL you created like (you may have to change your token in IFTTT if your token expires):
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    @@ -60,7 +60,7 @@ https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE

    **The API Docs:**

    Formatted as a JSON object, with an escaped object as a string for the `requestData` property, it includes the device to be selected as well as all the data sent to that device. Some properties only change while the light is being turned on or is already on. If you can contribute to this or provide information on unknowns, please comment!
    Formatted as a JSON object, with an escaped object as a string for the `requestData` property, it includes the device to be selected as well as all the data sent to that device. Some properties only change while the light is being turned on or is already on. You can emulate anything that can be done in the Kasa app by performing it in Kasa and then checking Packet Capture. If you can contribute to this or provide information on unknowns, please comment!

    Root Level:

  4. danielhickman revised this gist Sep 12, 2017. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/ifttt/comments/5pii8v/control_your_tplink_hs100_smart_plug_with_ifttt/), I found updated information on the TP-Link API and how to use it. I only have used it with my single smart bulb, but it might be helpful for other TP-Lin products. The guide should be intermediate level, but it contains a lot of verbiage; just expect to tinker a bit. It took me a while to figure this out from scratch, but it shouldn't take longer than 30 minutes to your first applet. [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/Bnd3fz3.png)
    Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/ifttt/comments/5pii8v/control_your_tplink_hs100_smart_plug_with_ifttt/), I found updated information on the TP-Link API and how to use it. I only have used it with my single smart bulb, but it might be helpful for other TP-Link products. The guide should be intermediate level, but it contains a lot of verbiage; just expect to tinker a bit. It took me a while to figure this out from scratch, but it shouldn't take longer than 30 minutes to your first applet.


    **Tools Used:**

    @@ -16,9 +17,6 @@ Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/i
    * You must have Kasa's "Remote Control" feature enabled for the devices you are going to automate


    *Now to the fun stuff!*


    **Your API Token and Device IDs:**

    1. Install [Packet Capture](https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture) (make sure it has access to your SSL packets by adding the certificate it requests you to add if you face any issues, you can remove this later to remove the warning shown in quick settings)
    @@ -83,4 +81,10 @@ Request Data > Transition Light State:
    * `hue` - Number, range from 0 to 360 for the color hue. Incompatible with color_temp, to be used with saturation.
    * `saturation` - Number, range from 0 to 100 for the color saturation. Incompatible with color_temp, to be used with hue.
    * `ignore_default` - Unknown
    * `mode` - Unknown
    * `mode` - Unknown


    **Links:**

    * [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/Bnd3fz3.png)
    * [Reddit discussion I made](https://www.reddit.com/r/ifttt/comments/6zla2d/guide_control_tplink_smart_bulbs/)
  5. danielhickman revised this gist Sep 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ Host: use1-wap.tplinkcloud.com
    ```
    6. Make sure you can create a URL like the following from your token and host (in case the host changes in the future):
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    7. Also, find a send packet like the following, the important part is your deviceId:
    ```json
  6. danielhickman revised this gist Sep 12, 2017. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -27,22 +27,22 @@ Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/i
    4. Switch back to the Packet Capture app and stop recording, the faster the better to eliminate extra packets
    5. Search through all packets from Kasa until you find something like the following in your headers:
    ```
    POST /?token=[YOUR-TOKEN-HERE]&[...]
    Host: use1-wap.tplinkcloud.com
    POST /?token=[YOUR-TOKEN-HERE]&[...]
    Host: use1-wap.tplinkcloud.com
    ```
    6. Make sure you can create a URL like the following from your token and host (in case the host changes in the future):
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    7. Also, find a send packet like the following, the important part is your deviceId:
    ```json
    {
    "method": "passthrough",
    "params": {
    "deviceId": "YOUR-ID-HERE",
    "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\":{\"brightness\":100,\"color_temp\":3500,\"ignore_default\":0,\"mode\":\"normal\",\"on_off\":1,\"transition_period\":2500}}}"
    }
    }
    {
    "method": "passthrough",
    "params": {
    "deviceId": "YOUR-ID-HERE",
    "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\":{\"brightness\":100,\"color_temp\":3500,\"ignore_default\":0,\"mode\":\"normal\",\"on_off\":1,\"transition_period\":2500}}}"
    }
    }
    ```
    8. Save the required packets as text files so you can easily copy them or send them to a desktop

    @@ -52,7 +52,7 @@ Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/i
    1. Create an applet with IFTTT Webhooks as the "That" portion (you can use anything for the "This")
    2. For the URL use your URL you created like:
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    3. For the method, use POST and application/json for the content type
    4. The body should be the JSON object that includes your device ID as well as any thing you want to see changed on the bulb
  7. danielhickman created this gist Sep 12, 2017.
    86 changes: 86 additions & 0 deletions Control-TP-Link-Smart-Bulbs-with-IFTTT.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    Extending from [this Reddit thread and linked artcle](https://www.reddit.com/r/ifttt/comments/5pii8v/control_your_tplink_hs100_smart_plug_with_ifttt/), I found updated information on the TP-Link API and how to use it. I only have used it with my single smart bulb, but it might be helpful for other TP-Lin products. The guide should be intermediate level, but it contains a lot of verbiage; just expect to tinker a bit. It took me a while to figure this out from scratch, but it shouldn't take longer than 30 minutes to your first applet. [Example applet that turns on my light when I long press my WeMo switch (ID and token removed)](https://i.imgur.com/Bnd3fz3.png)

    **Tools Used:**

    * Android Phone (to capture packets without jailbreak or another device to intercept, I've not looked for other platforms' apps)
    * [Kasa App](https://play.google.com/store/apps/details?id=com.tplink.kasa_android)
    * [Packet Capture](https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture)
    * [IFTTT Webhooks](https://ifttt.com/maker_webhooks)


    **Requirements and Cautions:**

    * Understand you are sharing your API token to your Kasa account and could result in someone changing your lights or worse if they got ahold of it
    * Understand that a packet sniffer could theoretically send personal information to another server
    * Understand that you are using TP-Link's private API without their consent
    * You must have Kasa's "Remote Control" feature enabled for the devices you are going to automate


    *Now to the fun stuff!*


    **Your API Token and Device IDs:**

    1. Install [Packet Capture](https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture) (make sure it has access to your SSL packets by adding the certificate it requests you to add if you face any issues, you can remove this later to remove the warning shown in quick settings)
    2. Start recording your traffic in Packet Capture by pressing the green play button in the app bar
    3. Navigate to the Kasa app and power on or off the bulb you'd like to use
    4. Switch back to the Packet Capture app and stop recording, the faster the better to eliminate extra packets
    5. Search through all packets from Kasa until you find something like the following in your headers:
    ```
    POST /?token=[YOUR-TOKEN-HERE]&[...]
    Host: use1-wap.tplinkcloud.com
    ```
    6. Make sure you can create a URL like the following from your token and host (in case the host changes in the future):
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    7. Also, find a send packet like the following, the important part is your deviceId:
    ```json
    {
    "method": "passthrough",
    "params": {
    "deviceId": "YOUR-ID-HERE",
    "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\":{\"brightness\":100,\"color_temp\":3500,\"ignore_default\":0,\"mode\":\"normal\",\"on_off\":1,\"transition_period\":2500}}}"
    }
    }
    ```
    8. Save the required packets as text files so you can easily copy them or send them to a desktop


    **IFTTT Webhooks:**

    1. Create an applet with IFTTT Webhooks as the "That" portion (you can use anything for the "This")
    2. For the URL use your URL you created like:
    ```
    https://use1-wap.tplinkcloud.com/?token=YOUR-TOKEN-HERE
    ```
    3. For the method, use POST and application/json for the content type
    4. The body should be the JSON object that includes your device ID as well as any thing you want to see changed on the bulb
    5. Before completing the applet, make sure there aren't two brackets next to each other like `{{` or `}}`, separate them with a space or carriage return to not confuse IFTTT



    **The API Docs:**

    Formatted as a JSON object, with an escaped object as a string for the `requestData` property, it includes the device to be selected as well as all the data sent to that device. Some properties only change while the light is being turned on or is already on. If you can contribute to this or provide information on unknowns, please comment!

    Root Level:

    * `"method": "passthrough"` - Unknown
    * `"params": {}` - An object with your ID and data

    Params:

    * `"deviceId": "YOUR-ID-HERE"` - How you tell TP-Link which device to target
    * `"requestData": "[...]"` - Data to be sent to the device

    Request Data > Transition Light State:

    * `on_off` - Number, state for the device. 0 = off, 1 = on. No color, brightness, etc is require to toggle the light.
    * `transition_period` - Number, number of milliseconds to transition the state (on_off); brightness; hue; and saturation.
    * `brightness` - Number, range from 0 to 100 for the brightness of the device.
    * `color_temp` - Number, range from unknown to unknown for the color temperature in kelvins. Incompatible with hue and saturation.
    * `hue` - Number, range from 0 to 360 for the color hue. Incompatible with color_temp, to be used with saturation.
    * `saturation` - Number, range from 0 to 100 for the color saturation. Incompatible with color_temp, to be used with hue.
    * `ignore_default` - Unknown
    * `mode` - Unknown
    1 change: 1 addition & 0 deletions dance-party-bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    javascript:var deviceID = "YOUR-ID-HERE";var token = "YOUR-TOKEN-HERE";alert("Close tab to stop dance party");function postJSON(url, json) {return new Promise(function(resolve, reject) {function handleError() {console.error("There was a connection error of some sort");reject();}var request = new XMLHttpRequest();request.open("POST", url, true);request.addEventListener("load", function() {if (request.status >= 200 && request.status < 400) {if (request.getResponseHeader("content-type") === "application/json") {var data = JSON.parse(request.response);} else {var data = request.response;}resolve(data);return;}handleError();});request.addEventListener("error", function() {handleError();});request.send(JSON.stringify(json));});}var url = "https://use1-wap.tplinkcloud.com/?token=" + token;window.setInterval(function() {var hue = Math.floor((Math.random() * 360));var saturation = Math.floor((Math.random() * 40) + 60);console.log(hue, saturation);var json = {"method": "passthrough","params":{"deviceId": deviceId,"requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\":{\"brightness\":100,\"color_temp\":0,\"hue\":" + hue + ",\"ignore_default\":1,\"mode\":\"normal\",\"on_off\":1,\"saturation\":" + saturation + ",\"transition_period\":1500}}}"}};postJSON(url, json).then(function(data) {console.log(data);});}, 1500);