Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Created January 25, 2022 23:04
Show Gist options
  • Select an option

  • Save MarkTiedemann/752346082a7c8125c019d3d7d0ea43b9 to your computer and use it in GitHub Desktop.

Select an option

Save MarkTiedemann/752346082a7c8125c019d3d7d0ea43b9 to your computer and use it in GitHub Desktop.
<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