Author Topic: Philips Hue Demo Plugin  (Read 4354 times)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 1268
Philips Hue Demo Plugin
« on: July 20, 2016, 09:50:30 pm »
Ok, so I got some Philips Hue lights... they are a little pricey, but are a LOT of fun.  I decided to slap together a VoiceAttack plugin just to see what could be done to make it more entertaining and for sharing with the group.  Attached is the compiled plugin for use and a sample profile.  The full source code (C#) will come soon, after I clean it up a bit and add some documentation (if you would like it sooner, just email me at support@voiceattack.com).

I made a goofy video to show it off: 

https://youtu.be/7LquElrXVRA

I'm not going to say what the captain showed me o_O


It uses the popular, 'Orion' pack from HCS (http://www.hcsvoicepacks.com) plus some sounds found on the web.

The underlying Hue api is Q42.HueApiban :  https://github.com/Q42/Q42.HueApi




Installing

In the .zip attachment, you will find the VAHueDemo folder.  Copy the WHOLE folder (folder and contents) into your Apps directory located in your VoiceAttack installation folder (usually C:\Program Files (x86)\VoiceAttack\Apps).  When you start VoiceAttack, the plugin should be recognized as, 'VoiceAttack Hue Demo Plugin - v1.5.8+' (make sure you have turned on plugin support in options and restart VoiceAttack if needed).


Inside the VAHueDemo folder you just copied, you will find, 'SetupHueDemo.exe'.  You will need to run this app first in order to associate the plugin with your Hue bridge.
If your bridge is dectected, it will show up in the list.  You can also type in the ip address manually.  Once a bridge/ip is indicated, click on, 'Register'.  You'll have about 30 seconds to press the button on your bridge.  If successful, the plugin will use the ip address provided and the app key that the bridge generates to talk to the bridge.  Note that this plugin only supports one bridge for now.


Also inside the .zip, you will find a sample profile (Hue Demo-Profile.vap) with some of the commands used in the video ;)  Note that the profile uses lights id'd as '1', '2' and '3'.  Some sounds are included.  Just copy the WHOLE, 'VAHueSounds' folder (folder and contents) into the Sounds folder in the VoiceAttack installation directory.



VAHueDemo Plugin Usage

First, add a plugin action to your command by clicking, 'other' then, 'advanced' and then 'Execute an External Plugin Function'.

Next, select the, 'VoiceAttack Hue Demo' plugin from the list.

All you have to do is just indicate what you want to do in the 'Plugin Context' field.  There are just a few functions to do what you need to do, with some simple syntax.


on

To turn all the lights on, just type 'on' (no quotes) in the Context field.  If you want to turn off a single light, type, 'on', then a colon, then the id of the light.  The lights are usually id'd as, '1', '2', '3', etc.  So, to turn on light, '1', type 'on:1' in the context field.  To turn on multiple lights at the same time, type, 'on' a colon and then the ids separated by a comma.  So, to turn on lights '1' and '3', type, 'on:1,3'.



off

The same procedure as, 'on'.  To turn off all lights, just put 'off' in the context field.  To turn off lights '1' and '3', type, 'off:1,3'.



reset

This does basically what turning off the power and turning it back on will do (resets he color and brightness).  Just like 'on' and 'off', to reset all lights, just type, 'reset' in the context field.  To reset just lights '1' and '3', type, 'reset:1,3'.



color

To change the color of your lights, you need to get and provide the hex value of the color you would like them to be.  A hex value simply a six-character code to represent the color.  For example, 'ff0000' is red, '00ff00' is green, '0000ff' is blue, ffff00 is yellow and so on.  The best way to find a color code is to open up Paint.NET or Photoshop (or other application with a color picker (unfortunately, MS Paint lacks a, 'hex' value indicator)).  To change the color of all lights to red at once, type, 'color:ff0000' in the context box.  To change the color of lights '1' and '3' to purple, type, 'color:1,3:ff00ff'.



bright

Brightness has a value of 0 to 255 (dim to bright).  To set the brightness of all lights to half, type, 'bright:128' in the context field.  To set lights '1' and '3' to full brightness, type, 'bright:1,3:255'.

Note: Somehow a brightness of 0 does not turn the lights completely off... you'll need, 'off' to do that.



fade

Fade will transition the brightness of your lights over time.  You will need to provide the brightness on a scale of 0 to 255, plus the amount of time represented in milliseconds.  To fade all of your lights to full brightness (255) over a period of 3.5 seconds (3500 milliseconds), type, 'fade:255:3500'.  To fade lights '1' and '3' to half brightness (128) over four seconds (4000 milliseconds) type, 'fade:1,3:128:4000'.


Hope somebody can use it ;)

Exigeous

  • Newbie
  • *
  • Posts: 22
Re: Philips Hue Demo Plugin
« Reply #1 on: October 05, 2016, 05:32:26 am »
This looks fantastic, recently I posted to Reddit trying to find a command line solution to control Hue so I could setup something with VoiceAttack.  Can't wait to try this later today.

Question - right now I have 3 Hue bulbs upstairs in my house with the base unit in the next room.  All works great.  I took one of the bulbs downstairs (in a rather small 1400 sq/ft house) which is about 50 feet in a straight line away and I couldn't control the light at all.  The Hue app doesn't see it as online.  Any thoughts on why that would be?

-Ross

Exigeous

  • Newbie
  • *
  • Posts: 22
Re: Philips Hue Demo Plugin
« Reply #2 on: October 21, 2016, 11:15:03 pm »
As I got this worked out I thought I'd reply so if anyone else wants to set it up they can.

First download curl.exe (for Windows) and copy it to a directory somewhere (perhaps c:\windows or if you have another folder where you store scripts and game stuff)

Next create batch files for each command you want (lights-on.bat, lights-off.bat)

Determine the IP address of your Hue Bridge (apps like Huetro, etc. will tell you)  When you have the IP address hit that with a browser with the following URL: http://192.168.1.104/debug/clip.html (replace the IP address with the one from above)

On the debug page enter "/api" for the URL (no quotes) and paste the following into message body
{"devicetype":"my_hue_app#iphone peter"} (just like that)

You then need to go press the pair/sync button on the Phillips Bridge.  When that's done click "GET" on the debug page, you'll get a response with a very long string, that's the username.

The commands you'll use to control the lights are below.  These can be run at a command prompt or from a batch file.  You'll then call that batch file from your custom VoiceAttack comman.

d:\games\lights\curl.exe -X PUT -d "{\"hue\": 33333,\"on\": true,\"bri\": 254}" http://192.168.1.104/api/6ZXc29kazYH7nuPOLeRMED0P2XFkhFjO64S9imF3/lights/1/state

(replace d:\games\lights with the path to where you put curl.exe)
You can change a few parameters, where it says "true" means turn the light on, false would turn it off.  The number 33333 is the color (that's close to white), colors run from 0 to 65535 with that being red)
The number after lights/ (in my case 1) is the number of the device.  Just experiment until you find the correct number for the light you want to control.

Finally create a custom VoiceAttack command that executes the batch files you created above.  You should do some testing with the scrips to make sure they run correctly before adding VoiceAttack to the mix.

I setup a few commands:
- Computer lights (lights come on)
- Computer lights off (uh, lights off)
- Computer Red Alert (lights go red, weapons are deployed, full power to shields)
- Computer Stand down (same as lights off) and it stows my weapons.

Just another of those little things that make VoiceAttack such a great tool to further immersion.

Andydigital

  • Newbie
  • *
  • Posts: 20
Re: Philips Hue Demo Plugin
« Reply #3 on: November 17, 2016, 01:13:31 am »
Does this plugin still work with the latest version of VA, when I try it I get an error.

08:12:08 - UNABLE TO INVOKE PLUGIN. PLUGIN NOT VALID FOR THIS VERSION OF VOICEATTACK.
« Last Edit: November 17, 2016, 01:22:13 am by Andydigital »

reedjam99

  • Newbie
  • *
  • Posts: 5
Re: Philips Hue Demo Plugin
« Reply #4 on: December 09, 2016, 07:29:21 am »
I got the demo up and running just now with version 1.5.12 of VoiceAttack. The out of the box commands worked fine. I started tweaking commands and setting them up for my own subset of lights, also worked fine.

Then out of the blue I started getting this error: "UNABLE TO INVOKE PLUGIN DUE TO EXCEPTION:Exception has been thrown by the target of an invocation."

I restarted VoiceAttack, and the first command I tried worked, then back to the error again.

Any idea?

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 1268
Re: Philips Hue Demo Plugin
« Reply #5 on: December 09, 2016, 09:06:45 am »
Hmmm.  I'm not entirely sure what is going on there.  I do know that if you make a mistake an raise an exception, the whole thing comes down.  I'm probably going to update this one soon to be plugin v4 compatible, and bolster up some of the functions so that it doesn't explode on contact o_O

reedjam99

  • Newbie
  • *
  • Posts: 5
Re: Philips Hue Demo Plugin
« Reply #6 on: December 09, 2016, 10:04:00 am »
Hmm, can't promise I didn't have an error in my commands. I'll double check. Definitely would love to see this updated and simplified. I've got my whole office set up with Hues lights, and would absolutely love to be able to control them with VoiceAttack. Thanks!

Exigeous

  • Newbie
  • *
  • Posts: 22
Re: Philips Hue Demo Plugin
« Reply #7 on: January 08, 2017, 12:50:50 pm »
I started getting this error: "UNABLE TO INVOKE PLUGIN DUE TO EXCEPTION:Exception has been thrown by the target of an invocation."

Make sure that on the main VoiceAttack screen (the small rectangular one) you have "Send Commands To" either set to "Active Window" or the name of the process you wan to control.  I've run into that a lot while creating some custom commands.

That do it?

macdaddyb

  • Newbie
  • *
  • Posts: 1
Re: Philips Hue Demo Plugin
« Reply #8 on: February 03, 2017, 07:11:45 am »
  :D Great Work!

I was looking at doing this same thing with a command line utility but this is a much better solution. Getting the correct lights with only ID numbers is more of a pain when you have 18 lights on the hue bridge though. Maybe consider polling the bridge for the actual name of the light if you decide to update?
I had a command line utility called WinHue 3 which the ID numbers matched the ones in the plugin, so I referenced it to find the names of the lights I wanted. I'll only have to do that once anyway, so not a big deal.

Thank you for sharing this plugin! This weekend I'll be tying it to events from the EDDI plugin.