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

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Philips Hue Demo Plugin
« on: July 20, 2016, 10: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: 23
Re: Philips Hue Demo Plugin
« Reply #1 on: October 05, 2016, 06: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: 23
Re: Philips Hue Demo Plugin
« Reply #2 on: October 22, 2016, 12:15:03 AM »
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

  • Guest
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

  • Guest
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: 2832
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

  • Guest
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: 23
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

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

Obi-Shinobi

  • Newbie
  • *
  • Posts: 6
Re: Philips Hue Demo Plugin
« Reply #9 on: September 22, 2019, 07:20:05 PM »
I love this, thank you!

Obi-Shinobi

  • Newbie
  • *
  • Posts: 6
Re: Philips Hue Demo Plugin
« Reply #10 on: June 06, 2020, 02:36:11 AM »
Any way to make some lights flash in and out?  I have zero coding skills so I wouldn't know where to start.  I got the lights to go red and fade as I like but I do have some light strips I'd like to "flash" or "fade" in and out until I end the command.

thanks

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Philips Hue Demo Plugin
« Reply #11 on: June 06, 2020, 09:26:08 AM »
One way to do it is to use one command for the loop, and another to stop, E.G.
Start flashing
Code: [Select]
Execute external plugin, 'Hue Plugin'
Pause 1 second
Execute external plugin, 'Hue Plugin'
Pause 1 second
Where the first plugin call turns on the lights, and the second turns them off again.

Set the "Repeating" option for the command to "Repeat continuously until stopped".

Stop flashing
Code: [Select]
Kill command, 'Start flashing'
Execute external plugin, 'Hue Plugin'
Where the plugin call turns off the lights (to make sure they're off even if the loop is interrupted while they were on).


For fading, you'd need to account for the timing of the fade as well, E.G. if you have it fade over 3.5 seconds as in the example
Code: [Select]
Execute external plugin, 'Hue Plugin'
Pause 4.5 seconds
Execute external plugin, 'Hue Plugin'
Pause 4.5 seconds
If you want the fade to transition from in to out immediately you'd obviously want to use a pause length matching your exact fade time.

Obi-Shinobi

  • Newbie
  • *
  • Posts: 6
Re: Philips Hue Demo Plugin
« Reply #12 on: June 13, 2020, 11:31:28 PM »
Thank you very much, your the man!


One way to do it is to use one command for the loop, and another to stop, E.G.
Start flashing
Code: [Select]
Execute external plugin, 'Hue Plugin'
Pause 1 second
Execute external plugin, 'Hue Plugin'
Pause 1 second
Where the first plugin call turns on the lights, and the second turns them off again.

Set the "Repeating" option for the command to "Repeat continuously until stopped".

Stop flashing
Code: [Select]
Kill command, 'Start flashing'
Execute external plugin, 'Hue Plugin'
Where the plugin call turns off the lights (to make sure they're off even if the loop is interrupted while they were on).


For fading, you'd need to account for the timing of the fade as well, E.G. if you have it fade over 3.5 seconds as in the example
Code: [Select]
Execute external plugin, 'Hue Plugin'
Pause 4.5 seconds
Execute external plugin, 'Hue Plugin'
Pause 4.5 seconds
If you want the fade to transition from in to out immediately you'd obviously want to use a pause length matching your exact fade time.

Malic

  • Full Member
  • ***
  • Posts: 105
Re: Philips Hue Demo Plugin
« Reply #13 on: August 15, 2021, 01:12:00 AM »
Have been using this plugin and love it, but just came across something different when I got a set of lights that I am planning on putting under my desk.

It is the unit from this link:  https://www.amazon.com/gp/product/B07ZQC29J9

It is not a Hue branded light, but can be controlled using it.

I can do the RGB just fine, however this light also has dedicated lights for the 6000K and 4000k white temperatures, and it does not seem to be able to take advantage of those.  Is there something else I need to do to make it use these?  Setting the lights to 255,255,255 just has the three LED RGB lights fully lit up only

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Philips Hue Demo Plugin
« Reply #14 on: August 20, 2021, 09:44:37 AM »
It makes sense that 3rd party vendors want to make lighting hardware that "works with" the current Hue Bridge and API due to how well Hue is integrated with other things. However as you've found, you'll be limited to the API and hardware functionality available to Gary when he built that plugin. The Hue API was updated a couple times and new Hue hardware was released following Gary's release of that plugin.

If you have experience with C# and you're serious about making your lights fully work, then I strongly recommend checking out Q42.HueAPI. It's probably the most popular C# wrapper for the Hue API.

I WAS working on a plugin that updated and expanded on Gary's "VAHueDemo Plugin," but then I got sidetracked so it's still a WIP. Regardless, my project leveraged Q42.HueAPI (whatever functionality was available ~6 months ago), so definitely go check it out if you're inclined.

Obi-Shinobi

  • Newbie
  • *
  • Posts: 6
Re: Philips Hue Demo Plugin
« Reply #15 on: December 28, 2023, 06:11:41 PM »
Hello,

I know this is an old plugin and maybe it no longer works, but I'm getting the following error:

UNABLE TO INVOKE PLUGIN, 'VoiceAttack Hue Demo Plugin - v1.5.8+'.  DUE TO EXCEPTION: One or more errors occurred.

When I open the the plugin action in my profile, I get the following popup:

The plugin that is referenced by this action is not valid for this version of VoiceAttack.  The plugin is available for selection, however, if you try to run this plugin, it will fail.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Philips Hue Demo Plugin
« Reply #16 on: January 10, 2024, 12:25:10 AM »
Was this plugin working for you previously? If not, try downloading and extracting it again.


Testing this on my machine by extracting the plugin, importing the demo profile, and executing the "dim" command, seems to work without issue. Though, given that I have no Hue products, the configuration would not be complete.