Created
April 23, 2014 20:39
-
-
Save natcl/11231597 to your computer and use it in GitHub Desktop.
Smallmax javascript file to control the Philips hue system
This file contains 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
autowatch = 1; | |
var ajaxreq; | |
var ip; | |
var key; | |
function set_ip(_ip) | |
{ | |
ip = _ip; | |
} | |
function set_key(_key) | |
{ | |
key = _key; | |
} | |
function get_lights() | |
{ | |
ajaxreq = new XMLHttpRequest(); | |
ajaxreq.open("GET",'http://' + ip + '/api/' + key +'/lights'); | |
ajaxreq.onreadystatechange = readystatechange_parsejson; | |
ajaxreq.send(); | |
} | |
function on(id, state) | |
{ | |
ajaxreq = new XMLHttpRequest(); | |
ajaxreq.open("PUT",'http://' + ip + '/api/' + key +'/lights/' + id + '/state'); | |
ajaxreq.onreadystatechange = readystatechange_parsejson; | |
if (state == 1) | |
ajaxreq.send('{"on": true}'); | |
if (state == 0) | |
ajaxreq.send('{"on": false}'); | |
} | |
function brightness(id, bri) | |
{ | |
ajaxreq = new XMLHttpRequest(); | |
ajaxreq.open("PUT",'http://' + ip + '/api/' + key +'/lights/' + id + '/state'); | |
ajaxreq.onreadystatechange = readystatechange_parsejson; | |
ajaxreq.send('{"bri": ' + bri + '}'); | |
} | |
// Here we fetch data and use javascript's internal JSON.parse method to read | |
// individual elements from and array of objects (aka dictionaries) | |
function readystatechange_parsejson() | |
{ | |
if (this.readyState ==4){ | |
post(this.responseText); | |
post(); | |
} | |
} | |
Yes that's quite old, I'm pretty sure the easiest way to control hue from Max now is to use nodejs + some hue library.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this obsolete?