Skip to content

Instantly share code, notes, and snippets.

@natcl
Created April 23, 2014 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natcl/11231597 to your computer and use it in GitHub Desktop.
Save natcl/11231597 to your computer and use it in GitHub Desktop.
Smallmax javascript file to control the Philips hue system
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();
}
}
@Polyterative
Copy link

is this obsolete?

@natcl
Copy link
Author

natcl commented Aug 31, 2020

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