Controlling Philips Hue using Jython and Phue
Hi.
I am trying to write a patch to control the Philips Hue lights.
I have found a Python Library that i can use in conjunction with Jython.
I just have no idea and have found little info on how to get all the components connected and running.
If anyone has been working on this, I would really appreciate a little help.
What I have been using https://github.com/studioimaginaire/phue and https://github.com/cassiel/net.loadbang.jython
Thank you so much.
Did you figure out how to install all components? I am still having trouble to get the system up and running..
The error I am getting is the following:
java.lang.NoClassDefFoundError: Could not initialize class net.loadbang.jython.JythonEngineImpl
at net.loadbang.jython.mxj.ScriptEngine.buildEngine(ScriptEngine.java:58)
at net.loadbang.scripting.ScriptEngineBase.(ScriptEngineBase.java:61)
at net.loadbang.jython.mxj.ScriptEngine.(ScriptEngine.java:42)
(mxj) unable to construct instance of net.loadbang.jython.mxj.ScriptEngine
Hi Guys, I'd be glad to help you guys, I'm the one who did the phue library.
Seems like you have a problem with your Jython installation. You will need Jython 2.7 to use phue.
Make sure you download it here.
Check out these instructions : https://github.com/cassiel/net.loadbang.jython#jython-27
Let me know if you can get it to work.
I have downloaded jyphon 2.7.
I have placed all the contents of the distribution folder of net.loadbang.jython-master and placed it in /Applications/Max5/Cycling '74/java/lib.
I have placed all the contents of the distribution folder of net.loadbang.lib-master and placed it in /Applications/Max5/Cycling '74/java/lib.
I am not quite sure were to place the phue.py to
so I have placed phue.py in both the
net.loadbang.jython-master/examples/
and
net.loadbang.jython-master/examples/max5/
Now when I open one op the .maxpat patches in the example folders I get the above errors.
In your /Applications/Max5/Cycling ’74/java/lib folder do you have a jython.jar file ?
The download on github comes with jython 2.5 which needs to be removed and you need to replace it with the jython from 2.7. Also, is there a Lib folder with a bunch of python files in the same directory ?
In the java/lib folder I have now replaced the jython.jar file.
And I have added the Lib folder with the python files.
However, still no luck.
Hmm can you post a screenshot of your lib folder ?
screenshot
hereby the screenshot
Hmm I see you have 3 net.loadbang files there, are they different versions ?
can you try with these sets of files :
still same errors
I'm out of ideas... Do other mxj objects work ? can you try it on another system ?
max works perfectly fine.
it really is installing these hue communicating tools that doesn't seem to work.
Well, from what I can see the problem doesn't come from phue but from jython, perhaps communicate with the author of the jython mxj object ?
If anything's going wrong in the Java/Jython world you should be seeing it in the Max window. The list of JARs looks reasonable (if that jython.jar is 2.7) but the contents of Lib don't match what I see in mine.
Have you made any progress with this?
no, can't get it to work
Can you provide a complete list of what's in `Cycling '74/java/lib`, and confirm what version of Jython you're using? Also: what exactly is printed in the Max window?
I have the philips hue working in Max/MSP, thanks to Tommy Bobo, and his simplified approach. http://vimeo.com/64914947
Is anyone interested check the code below:
Hi,
I tried to run the patch from Lekirst but in the max window I have this message : js: can't find file BulbArray.js
Did I miss something ?
Thanks for request
I finnaly understood that i have to copy the js BulbArray.js content in the object, I replace the ip address by mine but I have this error message :
print: [{"error":{"type":1,"address":"/lights","description":"unauthorized user"}}
Any idea ?
Not sure how the javascript system works but in order to talk to the Bridge you need to be registered with the api, this is usually done by sending a post request while the button on the bridge has been pressed...
for the unauthorized user issue see:
developers.meethue.com/gettingstarted.html
Yes it works thanks !
@enzo and lekirst
If you could post details on your working setups that would be great— Max version, OS version, installation of lib files...just want to make sure I can get this going before buying the hardware.
thanks in advance!
Can you successors post details please?
I did controlling hue from clip api debugger (http://developers.meethue.com/gettingstarted.html) with no problem.
I can't control from Max patch that Lekirst posted.
I set up ip in BulbArray.js too.
Should I still need to use these https://github.com/studioimaginaire/phue and https://github.com/cassiel/net.loadbang.jython even if using Lekirst's patch?
Thanks in advance
Jin
Hey Jin,
It's been a while so I can't exactly remember how I got it working. But check the approach by Tommy Bobo, http://vimeo.com/64914947. Also I have attached a screenshot of my lib files.
Also check: developers.meethue.com/gettingstarted.html
Hope that it is of help to you!
Hi.
Thanks for this topic, I had been able to run Hue very easily!
Now, I made a little modify on the patch following Lekirst's js and cURL approach, allows to use Max's common style message like (bri $1 sat $2) .
test patch pasted in below, and js in Gist -
https://gist.github.com/tgck/11185861#file-huerequestbuilder-js
For those curious, in Max 6.1.7 there is direct support for this using the maxcurl object (or via javascript)
This means that it should work on both Osx and Windows and doesn't require any 3rd party externals:
Hi there!
Based on your JS i have created a Max-Plugin.
Play COLORS with your Midi-Keyboard and the selcted bulb (Note / Velocity to Hue / Bri)
Filter Maximum Bri with the Bri-Filter
Mix Transition-Time from 0 (immediately) to very long and smooth transitions
The Checkbox is to keep the last Hue-State without fallback to the 0-Bri when you release the key on your keyboard - Both Options are cool - Play around!
Included in the JS is a Register-User Function to register a Max4Hue-User for this Plugin
Enjoy
Michael,
Thanks for the Max Plugin. I have it installed and and communicating with the Hue bridge, but I am getting the following errors when I send a midi signal into it:
js: [{"error":{"type":3,"address":"/lights/undefined/state","description":"resource, /lights/undefined/state, not available"}}]
any ideas as to what would cause this error? Thanks!
Take a look at Hue Server:
Where do i need to put the js? (abelton > max midi effect doesn't work)
Check the hue api documentation and use maxurl, no java needed
Now that Hue server is no longer supported,( and I can't find the download link anyway)... are there any other ways to get this working with the latest Max7 + OS sierra? cheers,
Grove
{
"boxes" : [ {
"box" : {
"maxclass" : "comment",
"text" : "hue.json:",
"numoutlets" : 0,
"patching_rect" : [ 229.0, 132.0, 150.0, 20.0 ],
"id" : "obj-4",
"style" : "",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "message",
"text" : "{ http_method : get, url : http://192.168.100.2/api/PRPyG0D6pAjFlqyZbl-MqxxlYiNMgd-Z6Kv53a0c/lights, response_dict : data1, parse_type : json }",
"linecount" : 3,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 229.0, 162.0, 368.0, 49.0 ],
"id" : "obj-2",
"style" : "",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "message",
"text" : "import hue.json",
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 74.0, 75.0, 93.0, 22.0 ],
"id" : "obj-125",
"style" : "",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "dict",
"numoutlets" : 4,
"outlettype" : [ "dictionary", "", "", "" ],
"fontname" : "Arial",
"patching_rect" : [ 74.0, 188.0, 64.0, 23.0 ],
"id" : "obj-59",
"style" : "",
"fontsize" : 13.0,
"numinlets" : 2,
"saved_object_attributes" : {
"embed" : 0,
"parameter_enable" : 0
}
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "dict @embed 1",
"numoutlets" : 4,
"outlettype" : [ "dictionary", "", "", "" ],
"fontname" : "Arial",
"patching_rect" : [ 74.0, 111.0, 99.0, 23.0 ],
"id" : "obj-60",
"style" : "",
"fontsize" : 13.0,
"numinlets" : 2,
"data" : {
"http_method" : "get",
"url" : "http://192.168.100.2/api/PRPyG0D6pAjFlqyZbl-MqxxlYiNMgd-Z6Kv53a0c/lights",
"response_dict" : "data1",
"parse_type" : "json"
}
,
"saved_object_attributes" : {
"embed" : 1,
"parameter_enable" : 0
}
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "maxurl",
"numoutlets" : 2,
"outlettype" : [ "dictionary", "" ],
"fontname" : "Arial",
"patching_rect" : [ 74.0, 149.75, 50.0, 23.0 ],
"id" : "obj-64",
"style" : "",
"fontsize" : 13.0,
"numinlets" : 1
}
}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-125", 0 ],
"destination" : [ "obj-60", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
, {
"patchline" : {
"source" : [ "obj-60", 0 ],
"destination" : [ "obj-64", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
, {
"patchline" : {
"source" : [ "obj-64", 0 ],
"destination" : [ "obj-59", 0 ],
"hidden" : 0,
"disabled" : 0
}
}
],
"appversion" : {
"major" : 7,
"minor" : 3,
"revision" : 3,
"architecture" : "x86",
"modernui" : 1
}
}
Thanks Gerardo!
Do you still need Hue Server or is the .json file enough? Not sure how to use the patch you just posted...
I was under the impression that Max was just the middle man. Cheers,
Grove