Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danielhickman/7cf7890b47ea080cd625dc4d5cf4e3ab to your computer and use it in GitHub Desktop.
Save danielhickman/7cf7890b47ea080cd625dc4d5cf4e3ab to your computer and use it in GitHub Desktop.
Control TP-Link Smart Bulbs with IFTTT and HTTP Requests
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);
@adumont
Copy link

adumont commented Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment