Created
January 25, 2022 23:04
-
-
Save MarkTiedemann/752346082a7c8125c019d3d7d0ea43b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <meta http-equiv="x-ua-compatible" content="ie=9" /> | |
| <script> | |
| var ip = "192.168.0.xxx"; | |
| var username = "xxxxxxxxxxxxx"; | |
| function api_get(path, callback) { | |
| var req = new ActiveXObject("MSXML2.ServerXMLHTTP.3.0"); | |
| req.setOption(2, 13056); // allow self-signed certificate | |
| req.onreadystatechange = function () { | |
| if (req.readyState === 4) { | |
| callback(JSON.parse(req.responseText)); | |
| } | |
| }; | |
| req.open("GET", "https://" + ip + "/clip/v2/resource" + path); | |
| req.setRequestHeader("hue-application-key", username); | |
| req.send(); | |
| } | |
| function api_put(path, data, callback) { | |
| var req = new ActiveXObject("MSXML2.ServerXMLHTTP.3.0"); | |
| req.setOption(2, 13056); // allow self-signed certificate | |
| req.onreadystatechange = function () { | |
| if (req.readyState === 4) { | |
| callback(JSON.parse(req.responseText)); | |
| } | |
| }; | |
| req.open("PUT", "https://" + ip + "/clip/v2/resource" + path); | |
| req.setRequestHeader("hue-application-key", username); | |
| req.send(JSON.stringify(data)); | |
| } | |
| // Switch first light on/off | |
| api_get("/light", function(res) { | |
| api_put( | |
| "/light/" + res.data[0].id, | |
| { on: { on: !res.data[0].on.on } }, | |
| close | |
| ); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment