IT Nerd Space

Control your TP-Link HS100 smart plug with IFTTT

Control your TP-Link HS100 smart plug with IFTTT

Control your TP-Link HS100 smart plug with IFTTT

In my previous post we saw how we can control a TP-Link HS100 smart plug from command line from anywhere on Internet, without the Kasa app. In this post we’ll see how to switch the plug On/Off directly from IFTTT, without any third-party component, nor without any other device at home other than the smart plug itself.

In IFTTT we’ll use the Maker service, which let’s us call a custom HTTP GET/POST request with some Json payload, so that’s exactly what we need here.

Note: If you haven’t already, follow the steps in my previous post, to figure out what your Token and Device ID are.

Then create a new Recipe Applet like you normally would in IFTTT, and choose the “Maker Webhook / Make a Web Request” action service to define a new action.

For the URL, I’ve used:

https://eu-wap.tplinkcloud.com/?token=YOUR_TOKEN_HERE

and the method type is POST.

Note: For the URL: please read this other post, as you might need to use a different URL depending the region where you are from.


The Content Type is application/json, and the payload to switch the plug On should be:

{"method":"passthrough",
"params": {"deviceId": "YOUR_DEVICEID_HERE",
"requestData": "{\"system\":{\"set_relay_state\":{\"state\":1}
}
}" }
}

If you want to switch the plug Off, just replace the state 1 with state 0.

Notice how I have added extra carriage returns to separate the “}” at the end, otherwise IFTTT was giving me some error.

That’s it! Easy, right?

  • David Cooke

    Hello,

    I followed your instruction and can draw the information, but I don’t think the URL https://eu-wap.tplinkcloud.com/?token=#my hidden token# works here in Canada. Also, your URL starts with “eu”. How did you find out the URL?

    You URL i get the following measage

    {“error_code”:-10000,”msg”:”Request method ‘GET’ not supported”}

    Any help would be appreciated. Thanks.

    • Apparently you are using GET. Be sure to use the “POST” method, not “GET”.

    • D3r

      I used fiddler to get my token and device id but I cannot get my IFFT recipe to work. I have the same error as you when I paste https://use1-wap.tplinkcloud.com/?Redacted# in my browser. The recipe runs but nothing happens. Did you ever get it work? I’m also in Canada btw.

      When I paste curl –request POST “https://eu-wap.tplinkcloud.com/?token=YOUR_TOKEN_HERE HTTP/1.1”
      –data ‘{“method”:”passthrough”, “params”: {“deviceId”: “YOUR_DEVICEID_HERE”, “requestData”: “{“system”:{“set_relay_state”:{“state”:1}}}” }}’
      –header “Content-Type: application/json”
      in raspbian terminal I get this error: {“error_code”:-20104,”msg”:”Parameter doesn’t exist”}
      I’m completely lost.

  • I have edited the main HS100 post and added a Common issues based on people feedback with tips to help solve them. See
    http://itnerd.space/2017/01/22/how-to-control-your-tp-link-hs100-smartplug-from-internet/

  • Craig Poirier

    This is great! I was able to connect my Google Home w/ one TP-Link smart plug and light switch. Interestingly, though, the db/iot.1.db file only contained 2 of my 6 device IDs. I can’t find my other 4 (2 HS100 plugs and 2 light switches)

  • backslashV

    I have the TP-LINK smart LED Light Bulbs, how can I change the code above for those?

  • Rohan Patel
  • David Cooke

    Hi everyone,

    I did learn something helpful about this recently. This technique works well but when making IFTTT reciepts I found it painful if I ever had to log out of the Kasa app. Doing so meant that I was assigned a new token ID, which meant every reciept I made in IFTTT (I have like 30) needed to be updated with the new token ID.

    If you use Titanium Backup before a log out occurs, and restore the app, it will ask you to login again, but…you get the same token ID, meaning, you don’t have to update the IFTTT reciepts. Now that’s awesome 🙂

  • Christophe Van Mollekot

    Awesome !!! Can now voice-command my switch, thanks a bunch !!!

  • Tom O’Brien

    I’ve been searching for IFTTT capability with TP link devices for awhile now without success…while it took me a few hours to get through all this to get the data (along with the other post referenced below with more details), I have achieved success! This makes the TP Link devices much more useful! Thanks to the author for figuring this all out.

  • Darshan Lathia

    How to see the reply for the requested url. My url gets executed but the tplink does not turn on. I am guessing there is an error.

    P.S. with curl it runs fine.

  • Ganie Baltazar

    Or just get a Wemo or a Hue and done.

  • Alexandre T

    Hi! This worked perfectly but it stopped working about 10/15 days ago.
    I x2 checked the token and devideID and they are correct.
    Am I the only one? Did TP-Link change something?
    Thanks!

    • I’m not using IFTTT right now, but with cURL from my phone it’s still working like a charm, so I’d say from TP-Link’s end they haven’t changed anything.

  • Andy Lovell

    Hi, I believe I have followed the instructions correctly. There are no errors returned from IFTTT, yet my device is not toggling on/off (IFTTT icon does). One difference was my MAKER choices were “WeMo Maker or “Maker Webhooks”, I selected the latter.
    Any advice?

    • True. IFTTT have a tendency to periodically change names… Recipes are now called Applets, and indeed, Maker is now “Maker Webhooks / Make a Web Request”. Thanks for pointing it out, I’ll update the article.

      • Patrick Griffith

        https://uploads.disquscdn.com/images/90bafa3070540260405ebea17e2df6701442cf87eac5d45aa467ea825971d860.png

        I am using the Webhooks / Make a Web Request, but for some reason when I put the request json into the body, I get an error every time. It says ‘There is a problem with your applet. Missing ingredients opening brackets ‘{{‘. I have managed to get the entire thing to work in python via the requests package, but is there anything you see that needs to change in the setting up of the IFTTT Recipe? I’ve attached the inputs I’m selecting (with my TOKENID and DEVICEID replaced). Any help would be much appreciated.

        • I believe that’s because IFTTT notation for ingredients (variables) is like this {{name}}. In your caer IFTTT understands your }} as the end of an ingredient name, and is missing the opening. My advice try to separate every } with a new line to avoid confusion.

          • Patrick Griffith

            @adumont:disqus thank you so much for the reply. That did it! I saw someones comment about making sure the json was without spaces, but I didn’t think the line breaks would make a difference. Much appreciated.

  • HowardRoark

    After much trial and error, I finally retrieved my token and device ID via an android packet capture app. Much easier. After following the above instructions to a T however (using the new “Maker Webhooks” option on IFTTT, which I assume is just the Maker channel renamed), I’m getting no action after triggering the IFTTT applet. There may be something to what the last 2 comments have said about it no longer working.

    EDIT: Woohoo, figured it out! The URL has changed (at least for me).

    Old URL: https://eu-wap.tplinkcloud.com/?token=

    New URL: https://use1-wap.tplinkcloud.com/?token=

    • I’m glad you finally managed to work out the token and ID :). I’ve updated the article with a warning about the URL that depend on the user’s location (TP Link have partitioned their servers, and they have end-points in several AWS regions. I’ve noticed that the url prefix actually corresponds with AWS regions, except for the EU one).

      • NelsonGTi

        Alexandre this is great but I’m not sure where to start with the dd command on windows.

  • I thought you liked me

    Hi, is this still working? Or has the tplinkcloud settings changed – no longer working for me. Was working great.

    • I would say it does. Maybe your token has expired?
      Anyway I’m working on a new way which would render this pretty much obsolete, a new way I believe much more powerful, although maybe trickier.

      • I thought you liked me

        Thanks for your response. I’ll see if it’s changed.

        Ooo look forward to it.

  • David

    It seems that TP Link server is rejecting the white spaces between the closing }, even carriage return to bypass IFTTT doesnt work anymore.
    Anyone else facing this issue ?
    I tested it out using https://www.hurl.it/

  • nima

    WHATEVER YOU DO, DONT FORGET TO REMOVE THE SPACES OTHERWISE IT WONT WORK. TOOK ME 4 HOURS TO FIGURE IT OUT.

    Does anyone know how to control the smart bulbs?

  • JeremyH

    Alex, this has been very useful, thank you for he time you have invested in this and sharing with the community. All progressed well, managed to work around the fact that I’m a Windows guy not Linux etc for commands, but JSON is not my thing and I’ve come to an impasse, the script does not work when I run it. I have tried it in Hurl.it, the getDevicelist works so I know the URL and my Token are correct. But when I try to change the switch state I get an error
    {“error_code”:-10100,”msg”:”JSON format error”}

    script is:
    {
    “method”: “passthrough”,
    “params”: {
    “deviceId”: “800676FD5F0A287A6137E090F5DD916D183CXXXX”,
    “requestData”: “{“system”:{“set_relay_state”:{“state”:1}
    }
    }
    ” }
    }

    When I put the JSON script through a validator: https://jsonlint.com/
    I get the error like this…

    Error: Parse error on line 5:
    …”, “requestData”: “{“system”:{“set_
    ———————-^
    Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{‘, ‘[‘, got ‘undefined’

    ANy ideas what I am doing wrong ? – I copied and pasted the script from the instructions so don’t believe I have a formatting error etc.

    Many thanks
    (originally posted on wrong thread in error)

    • stefien

      I had the same issue. The problem ended up being the rows the braces were on. It had to be formatted as below for it to work.

      {
      “method”: “passthrough”,
      “params”: {
      “deviceId”: “800676FD5F0A287A6137E090F5DD916D183CXXXX”,
      “requestData”: “{“system”:{“set_relay_state”:{“state”:1}}}”
      }
      }

      • IFTTT is definitely susceptible to the payload format. How I formatted it, it worked, at least when I took the screen shot you can see in the post. Follow my formatting in case of doubts.

        • stefien

          In the case above, he wasn’t testing in IFTTT, but in jsonlint which appears to have different formatting rules than IFTTT. With IFTTT, you had to have the curly braces on different lines, with jsonlint, you had to bring them together. Different online sites with different ways of interpreting the input. In reality, either one, technically, should be fine. But you work with what you have. 🙂

          If he’s going to be testing his code on jsonlint, he’s going to need to adjust his curly brace location there, but then re-adjust once he brings it over to IFTTT

  • MJKienzle

    An even easier way to do this is by running HomeAssistant on a small Linux server such as a Pi. Just google it and all your dreams will come true. HomeAssistant can control the switches natively without any tokens of logins.

    • That’s a totally different approach, this post is about controlling the plug using the cloud service API.

      • MJKienzle

        Use the maker channel through HomeAssistant? Works great.

    • Jon Homer

      Home assistant doesn’t support tp-link as far as I can see

  • Adam Parsons

    Can anyone advise on adding multiple device ids so I can turn on more than one at a time?

  • stefien

    Hoping either the OP or someone else with more JSON knowledge than me can assist. Got this working smoothly (thanks to the OP as well as some of the tips I saw in the comments. Thank you everyone!)

    I’m attempting to tie this into my alarm system so that when my alarm is triggered, IFTTT will flash the lights. As it works now, it will turn the lights ON, but I’m unable to figure out how to string multiple commands, so the connection sends a state ON/state OFF/state ON/state OFF etc.

    Any thoughts?