Controlling Philips Hue using Jython and Phue

IamTheTommy's icon

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.

Thank you so much.

lekirst's icon

Did you figure out how to install all components? I am still having trouble to get the system up and running..

lekirst's icon

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

Nat's icon

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.

Let me know if you can get it to work.

lekirst's icon

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.

Nat's icon

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 ?

lekirst's icon

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.

Nat's icon

Hmm can you post a screenshot of your lib folder ?

lekirst's icon

screenshot

lekirst's icon

hereby the screenshot

screenshot-lib-folder-maxmsp.jpg
jpg
Nat's icon

Hmm I see you have 3 net.loadbang files there, are they different versions ?

Nat's icon

can you try with these sets of files :

lekirst's icon

still same errors

Nat's icon

I'm out of ideas... Do other mxj objects work ? can you try it on another system ?

lekirst's icon

max works perfectly fine.
it really is installing these hue communicating tools that doesn't seem to work.

Nat's icon

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 ?

nick rothwell | project cassiel's icon

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.

nick rothwell | project cassiel's icon

Have you made any progress with this?

lekirst's icon

no, can't get it to work

nick rothwell | project cassiel's icon

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?

lekirst's icon

I have the philips hue working in Max/MSP, thanks to Tommy Bobo, and his simplified approach. http://vimeo.com/64914947

Max Patch
Copy patch and select New From Clipboard in Max.

Is anyone interested check the code below:

enzo's icon

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

enzo's icon

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 ?

Nat's icon

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...

lekirst's icon

for the unauthorized user issue see:

developers.meethue.com/gettingstarted.html‎

enzo's icon

Yes it works thanks !

antialias's icon

@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!

jin's icon

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

lekirst's icon

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!

tgck's icon

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) .

Max Patch
Copy patch and select New From Clipboard in Max.

test patch pasted in below, and js in Gist -
https://gist.github.com/tgck/11185861#file-huerequestbuilder-js

Nat's icon

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:

Max Patch
Copy patch and select New From Clipboard in Max.
Michael's icon

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

MaxHue.amxd
amxd
MaxHue.js
js
Mark Hines's icon

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!

gerardo.pellicer's icon
wardd's icon

Where do i need to put the js? (abelton > max midi effect doesn't work)

gerardo.pellicer's icon

Check the hue api documentation and use maxurl, no java needed

Gmix's icon

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

gerardo.pellicer's icon

{

    "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

    }

}

Gmix's icon

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