Overview:
Why control Vera Z-wave devices and scenes from the command line you may ask? So I could program my Logitech Harmony universal remote control to be able to run these .CMD files with a little help from AutoHotKey installed on the HTPC. So for example I have added additional custom buttons to the Harmony remote’s LCD screen for my Watch Movies activity, so I can control the lights in the room via the Harmony remote at the click of a button.
The way that this works, is you teach your Harmony remote a keyboard command like Ctrl+Alt+A you then have an AutoHotKey script on the HTPC that waits for this keyboard command, once detected the script runs your .CMD file that sends a HTTP request to Vera to do something, like turn on a light. You can read more about setting up AutoHotKey and programming the Harmony remote on a previous post here. Scroll down the blog post and look for the part entitled: Logitech Harmony remote control.
Below is an example of what’s in the AutoHotKey script:
^!A::
IfWinExist Untitled - Left Lamp On
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Left.cmd
return
Getting started:
wGet
You will need to install and setup Wget on your HTPC first. I installed wGet on to my Windows 7 HTPC, I also had to add the path of where wget.exe is located which on my x64 PC was C:\Program Files (x86)\GnuWin32\bin in to the Windows Environment Variables PATH. To do this right click Computer from the start menu and select properties, then select Advanced System Settings and the Environment Variables button, under system variables scroll down to PATH click Edit and add in the path to wget.exe be sure to separate with ;
So now you have setup Wget you can look at creating some Vera HTTP commands.
Turning a Z-wave device on and off
Here is an example HTTP command which turns on my Lamp (Left) device in my living room. You need to know what your DeviceNum is?
wget --delete-after "http://192.168.1.100:3480/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1"
There are two ways to work out the device number, you can go to the Vera UI in a browser find the device in question, click the spanner icon and then go to the settings tab. You can see that this Lamp (Left) device is ID 3 and DeviceNum=3 in the above HTTP string to turn on this device.
The second method of listing the ID numbers for all your devices and scenes in Vera is to use the URL below, which displays a page of XML with all the information in it. Change IP-Address for the internal IP address of your Vera box.
http://IP-Address/port_3480/data_request?id=lu_sdata&output_format=xml
This example HTTP command turns off the Lamp (Left) device:
wget --delete-after "http://192.168.1.100:3480/data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0"
Note:
SetTarget&newTargetValue=0 = OFF
SetTarget&newTargetValue=1 = ON
To test your Vera HTTP commands you can just run them in a browser and the Z-wave device should respond. Obviously you need to change the IP address 192.168.1.100 to the IP address of your own Vera unit.
Once you have confirmed that they work you can create the .CMD files and just paste in the whole HTTP command. I won’t tell you how to create a new .CMD file as you should know how to do that. If you double click the .CMD file the HTTP command should be sent to Vera and the Z-wave device respond.
Run a Vera scene
In this example we are going to look at a HTTP command to run a scene in Vera. Again first you need to know the scene number of the particular scene you would like to create your .CMD file for. My scene is called “Lounge On” if I look at the scene in Vera I can see its number is = 1
Or if I look at the XML code from the URL I mentioned above, I can see this:
<scene active="0" name="Lounge On" id="1" room="1"/>
So now I know the ID number of the scene I want to create a .CMD file for, I can use the HTTP command below, note I have the number 1 at the end: RunScene&SceneNum=1 If my scene had an ID of 5 I would change this to be RunScene&SceneNum=5 etc.
HTTP Command to run a Vera Scene:
wget --delete-after "http://192.168.1.100:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=1"
So what I ended up with was folder on the HTPC with all my .CMD files in it to run various scenes and turn on/off various devices.
If you want to know more about how to setup AutoHotkey and program your Harmony remote control to be able to run these .CMD files then as I already said you need to read my previous post here. Ignore all the stuff about mControl Soap commands and the Amulet voice remote, the part you need to follow is entitled: Logitech Harmony remote control.
Summary:
Using the command line with your Home Theatre PC to send HTTP requests to your Vera Home Automation box, enables you to use your programmable universal remote control like a Logitech Harmony, to turn on and off Z-wave devices and also enables you to run scenes in Vera. When setup correctly it works perfectly and at the touch of a button on your remote control you will be able to initiate pretty much anything you have configured in Vera. Why spend extra money on a Z-wave compatible remote control? When you can program your existing Harmony remote to control Vera via your HTPC.
Here is a photo of my Logitech Harmony’s LCD screen with some custom buttons to control Z-wave devices like my lights and fireplace.
www.phaze1digital.com
Thanks so much for your awesome how-to! Just wanted to add that you MUST put the execution code within quotation marks or the script will keep failing! E.g.
ReplyDeletewget --delete-after "http://10.10.1.252:3480/data_request?id=lu_action&output_format=xml&DeviceNum=45&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1"
Thanks for spotting that I had missed out the "quotations" not sure how I did that? Anyways I have updated and corrected the example code. Regards Stuart.
ReplyDeleteIf you want to know how I am suppressing the command windows from popping up and being visible on the screen, see this link:
ReplyDeletehttp://forum.micasaverde.com/index.php/topic,12095.msg95508.html#msg95508