Google Search

Custom Search

Powered by...

Find us on Facebook

Showing posts with label Command. Show all posts
Showing posts with label Command. Show all posts

Saturday, 6 October 2012

How to control Vera Z-wave devices and run Vera scenes from the command line .CMD

In my last post I looked at integrating mControl with VeraLite. The next thing I wanted to setup was to be able to control Z-wave devices associated with Vera and run scenes that I’d setup in Vera via the command line on the Windows 7 Home Theatre PC.

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.

image

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

image

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.

image

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.

image



www.phaze1digital.com

Tuesday, 30 August 2011

How to use command line with mControl and Amulet / Harmony remotes

Background:

I am currently using mControl version 2.1.3818 installed on my WHS V1 server for use with my Z-WAVE lights. I have a few Z-Wave plug-in lamp modules and use the Aeon Labs Z-Stick USB dongle which is plugged in to the WHS box. mControl have an nice MCML add-in for Windows Media Center and there are also mControl HTML webpages including a mobile version which I use on my iPod touch device. The other user interface which I tend to use on my laptop is the mPanel software that was ported to work on regular Windows PCs and not just their mPanel embedded Windows CE device which is now discontinued anyways. All this means I can control my lights from various user interfaces on different devices.

mControl version 3 beta has a native iOS app for the iPhone but currently installing mControl beta 3 on WHS V1 or WHS 2011 is not supported which is why I haven’t upgraded as yet.

mControl User Interfaces:

mControl in Windows Media Center 7

mControl – mPanel software

mControl HTML webpage in Internet Explorer

mControl mobile.aspx webpage

The idea:

My idea started when I was thinking about my Amulet MCE voice remote control, I knew it was possible to create your own custom voice commands to run external programs. My idea was simple wouldn’t it be kinda cool if I could pick up the Amulet voice remote and say “Lights On” and for the side lamps in my living room to turn on!

Being able to send commands from my Windows 7 x64 HTPC to the mControl Web Service on my WHS has also enabled me to turn a regular IR Logitech Harmony remote control in to a remote that can also turn on and off my Z-Wave lamps, not only that I can now create buttons on my Harmony remote to run any mControl automation macros or send on/off commands to devices. So if you haven’t got an Amulet remote but do have a Harmony remote and your an mControl user, you might want to read on…

Obviously being able to control anything via command line opens up a whole wealth of possible things you can do and automate.

The discovery:

So I started digging around a little in the mControl documentation and I found a possible solution, I found this link http://myWHS/mcontrol/mServer.asmx which when you open it on your mControl install it will bring up a page called mControl Web Service and looks like the screen shot below: (Change myWHS to the hostname of your mControl server).

Scrolling down the list I saw two items of interest to me which were:

RunMacro
Send a macro run request to mServer

SendCommand
Sends automation command to a device

Clicking on to these two items revealed some sample code for SOAP, now I am no programmer but I knew I was on the right lines and this might just be possible. I then raised the subject with Eddy Carroll at Amulet Devices and asked him what he thought about it and if it might be possible to have Amulet send these commands to mControl. Eddy who is a programmer unlike myself was able to assist me and as a result we have come up with a working solution which I will demonstrate.

Below are the samples from the mControl Web Service webpage:

RunMacro

Send a macro run request to mServer

SOAP 1.1

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /mcontrol/mServer.asmx HTTP/1.1

Host: whs01
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://embeddedautomation.com/webservices/mControl/RunMacro"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunMacro xmlns="http://embeddedautomation.com/webservices/mControl">
<macroId>int</macroId>
</RunMacro>
</soap:Body>
</soap:Envelope>




HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunMacroResponse xmlns="http://embeddedautomation.com/webservices/mControl">
<RunMacroResult>boolean</RunMacroResult>
</RunMacroResponse>
</soap:Body>
</soap:Envelope>



SOAP 1.2

The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.


HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<RunMacroResponse xmlns="http://embeddedautomation.com/webservices/mControl">
<RunMacroResult>boolean</RunMacroResult>
</RunMacroResponse>
</soap:Body>
</soap:Envelope>


HTTP/1.1 200 OK

Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<RunMacroResponse xmlns="http://embeddedautomation.com/webservices/mControl">
<RunMacroResult>boolean</RunMacroResult>
</RunMacroResponse>
</soap12:Body>
</soap12:Envelope>


SendCommand


Sends automation command to a device

SOAP 1.1

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.


POST /mcontrol/mServer.asmx HTTP/1.1

Host: whs01
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://embeddedautomation.com/webservices/mControl/SendCommand"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendCommand xmlns="http://embeddedautomation.com/webservices/mControl">
<devId>int</devId>
<command>string</command>
</SendCommand>
</soap:Body>
</soap:Envelope>


HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendCommandResponse xmlns="http://embeddedautomation.com/webservices/mControl" />
</soap:Body>
</soap:Envelope>


SOAP 1.2

The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.


POST /mcontrol/mServer.asmx HTTP/1.1

Host: whs01
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendCommand xmlns="http://embeddedautomation.com/webservices/mControl">
<devId>int</devId>
<command>string</command>
</SendCommand>
</soap12:Body>
</soap12:Envelope>


HTTP/1.1 200 OK

Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendCommandResponse xmlns="http://embeddedautomation.com/webservices/mControl" />
</soap12:Body>
</soap12:Envelope>

The plan:
Eddy suggested we might be able to use wGet using the --post-file=filename option, to send the SOAP commands in xml files to the mControl Web Service. 
Getting started:
wGet
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 ;
Creating mControl .cmd and .xml files
Send ON Command to Device
Next we need to create our first .cmd and .xml file, in this first example we will be creating a Send ON Command to a device.
I created a new folder on my Windows Media Center PC called C:\Lights
I then created a .cmd file called Lounge-On-Left.cmd, to do this just use notepad and create a new file change the .txt extension with .cmd
I have two Z-Wave enabled lamps in my living room left and right. 
Below is the contents of the C:\Lights\Lounge-On-Left.cmd file - note you need to change whs01 to the hostname of your own WHS or PC running mControl server. Also you can see the file that wGet is going to post to the mControl Web Service in this case the file is called Lounge-On-Left.xml

wget -Onul --post-file="C:\Lights\Lounge-On-Left.xml" --header="Content-Type: text/xml; charset=utf-8" --header="SOAPAction: http://embeddedautomation.com/webservices/mControl/SendCommand" http://whs01/mcontrol/mServer.asmx

Next we need to create the Lounge-On-Left.xml file, again use notepad to create a file and change the .txt extension to .xml below is the contents of the Lounge-On-Left.xml file.

<?xml version="1.0" encoding="utf-8"?>

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendCommand xmlns="http://embeddedautomation.com/webservices/mControl">
<devId>3</devId>
<command>on</command>
</SendCommand>
</soap12:Body>
</soap12:Envelope>

Two things you need to look at in this xml file <devId> and <command> as we are creating a device ON xml file the command is on. <devId> is the device id of your device in mControl. To find out which of my Z-Wave modules had which devId? I simply opened mControl in Internet Explorer using the address http://whs01/mcontrol/ change the hostname obviously to your own. I then right clicked the page and selected View Source and scrolled down until I saw the device I was looking for in this case Lamp (Left) you can see I have circled the DevId which for this particular device is 3. So I used 3 in the <devID>3</devId> section of the xml file above.


OK so you have now created your first set of files one .cmd and one .xml to test simply double click on the .cmd file you will see the command window pop up and your ON command should be sent to your device in mControl.


Send OFF Command to Device


Next you would want to create two more files for an OFF command, so I created a file called Lounge-Off-Left.cmd and Lounge-Off-Left.xml in to my C:\Lights folder


Lounge-Off-Left.cmd contents:


wget -Onul --post-file="C:\Lights\Lounge-Off-Left.xml" --header="Content-Type: text/xml; charset=utf-8" --header="SOAPAction: http://embeddedautomation.com/webservices/mControl/SendCommand" http://whs01/mcontrol/mServer.asmx


Lounge-Off-Left.xml contents:


<?xml version="1.0" encoding="utf-8"?>

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendCommand xmlns="http://embeddedautomation.com/webservices/mControl">
<devId>3</devId>
<command>off</command>
</SendCommand>
</soap12:Body>
</soap12:Envelope>


To test double click the Lounge-Off-Left.cmd file and your device should now be turned off.


I repeated this process and created two more .cmd files and two more .xml files to turn my right lamp on and off. At this point I was able to manually run the .cmd files to turn on and off both lamps individually.


Run Macro Command


Next I wanted to create some Run Macro commands to turn both lamps on or off at the same time, I previously already created Macros in mControl to turn on or off both living room lamps together. On the below screen shot you can see these existing macros Lounge On and Lounge Off. I just needed to know what the MacroID was for each?



Again I simply opened the mControl webpage in Internet Explorer and Viewed the Source code. Scrolled down and found my marcos called Lounge On and Lounge Off you can see I have circled the MacroID’s.




With this information I was ready to create my first Run Macro .cmd file called Lounge-On.cmd


Lounge-On.cmd Contents:


wget -Onul --post-file=C:\Lights\Lounge-On.xml --header="Content-Type: text/xml; charset=utf-8" --header="SOAPAction: http://embeddedautomation.com/webservices/mControl/RunMacro" http://whs01/mcontrol/mServer.asmx



I then need to create an associated .xml file with the SOAP command in it called Lounge-On.xml


Lounge-On.xml Contents:


<?xml version="1.0" encoding="utf-8"?>

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<RunMacro xmlns="http://embeddedautomation.com/webservices/mControl">
<macroId>8</macroId>
</RunMacro>
</soap12:Body>
</soap12:Envelope>


I created another .cmd and another .xml called Lounge-Off.cmd and Lounge-Off.xml to be able to turn off the lamps, so now using these new Run Macro commands I could run either the Lounge On or Lounge Off macros in mControl to turn both lamps on and off.


The next problem I had to solve was I did not want to see the command prompt windows flashing up on the screen over the top of Media Center, whenever they where run via the Amulet voice remote or the Harmony remote. I wasn’t sure about this so I posted a thread on the Green Button and Richard1980 came to my aid with a suggestion to use a .vbs file to call the .cmd files.

The upshot of this is you can create a file in the C:\Lights folder called Run-CMD.vbs edit the .vbs file in notepad and paste into it the single line of code below, more about this later.


CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False


So now what?


Ok so now we have created a set of .cmd files and associated .xml files to send SOAP requests to the mControl Web Service, but you don’t want to be manually double clicking the .cmd files to make things happen, so we need to get these .cmd files working with our remote control(s).


Custom Commands with Amulet voice remote control


First up is the Amulet MCE Voice remote control, it is pretty easy to add your own custom voice commands in to Amulet and then have it run a .cmd file or any external program for that matter. First you need to locate a file in the C:\ProgramData\Amulet Devices folder called CustomCommands.txt edit this file.


I simply added the following to the end of the file:

Command=Lights On
Response=Turning On Lounge Lights
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On.cmd

Command=Lights Off
Response=Turning Off Lounge Lights
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off.cmd


Command=Left Lamp On
Response=Turning On Left Lamp
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Left.cmd

Command=Left Lamp Off
Response=Turning Off Left Lamp
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Left.cmd

Command=Right Lamp On
Response=Turning On Right Lamp
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Right.cmd

Command=Right Lamp Off
Response=Turning Off Right Lamp
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd

Let me explain a little:


Command=Lights On (You say “Lights On”)
Response=Turning On Lounge Lights (Amulet then says back to you “Turning On Lounge Lights”)
Action=Run C:\Windows\System32\WScript.exe C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On.cmd (Here you specify the .cmd file Amulet should run)


Save the Custom Commands.txt file restart Media Center - that’s it, its as easy as that to get Amulet working with your new mControl commands.


Logitech Harmony remote control


Getting your new mControl .cmd files working with your Harmony remote is more tricky. I imagine there are various ways you can do this, I am using AutoHotKey so that is what I will be recommending. Go to this page and download the Installer for AutoHotkey_L Install AutoHotKey on to your Media Center PC and when you launch it for the first time it asks you if you want to create a sample script file in the Documents folder say yes. I would also recommend you add a shortcut to AutoHotKey in your Windows Startup folder so it starts at every boot.


AutoHotKey will sit in the system tray and is a green icon with a H on it. If you right click this you can select Edit This Script and it will open in notepad.


Below you can see my AutoHotKey script:


Note: I am using a .vbs file called Run-CMD.vbs which calls the .cmd files as an argument and thus suppresses and totally hides the command windows from being visible on screen see here for more details.



Now I am not an AutoHotKey expert but what we want to do here is assign a keyboard shortcut such as Ctrl+Alt+A and when that keyboard shortcut is used we want it to run one of our mControl .cmd files. Don’t ask me why but ^ = Ctrl and ! = Alt so ^!A = Ctrl+Alt+A


Save and close your AutoHotKey script right click the H icon again in the system tray and select Reload This Script - To test press Ctrl+Alt+A using a keyboard connected to your Media Center PC this should run the mControl .cmd file and the device turn on or off or what ever the .cmd file is set to do.


Now I used my MCE IR Keyboard like this one to teach my harmony remote the keyboard shortcuts i.e. Ctrl+Alt+A Ctrl+Alt+B and I then assigned those commands to a custom buttons on my Harmony’s LCD screen.


If your using the Windows Media Center SE device in the Harmony software you could probably use some of the existing keyboard shortcuts like Alt+1 Alt+2 etc so then you wouldn’t need the IR MCE keyboard.


On the below screen shot from the Logitech Harmony software you can see four keyboard shortcut commands I taught the remote



Here you can see against my Media Center PC device and I also did this on some of my Activities I assigned custom buttons.



Conclusion


I think if you are an mControl user you will see the potential of being able to send SOAP commands using wGet to the mControl Web Service. This enables us to use .cmd files with associated xml files to run macros that are in mControl or control devices within your home automation system, I’m sure the possibilities are endless with this and it could be used in a variety of ways.


For me personally I am now able to use my Amulet MCE voice remote and use custom voice commands to turn Z-Wave lamp devices on and off and also to run mControl macros. And yes it is pretty cool picking up the Amulet remote and saying “LIGHTS ON” and having the lamps in the room turn on! Would be even better with the Amulet software for XBOX Kinect you would just have to say the command out loud then.


As an added bonus my regular IR Logitech Harmony remote control can now also be used to send commands to the mControl Web Service via AutoHotKey.


Well I think I covered everything I did to set this all up, I wrote this so I wouldn’t forget how I did it later but hopefully someone else may find it of use, as always please leave your questions comments and feedback.


You can download a copy of my sample mControl .cmd and .xml files plus an example of an Autohotkey script and a sample Amulet CustomCommands.txt file from here



www.phaze1digital.com

Wednesday, 2 December 2009

How to launch a command file from within MCE

I saw a user on the Green Button asking this question the other day and as I had a method of doing this I thought I’d write a post about it.

There may well be different ways to accomplish the same thing, but this is what works for me and the way I get an icon into the Extra’s area of 7MC and when I click on it, it runs a command line in the background. (This also works on Vista)

First you need to download this little add-in here, then extract / save it to the C:\Windows\ehome directory.

This is a single .dll file that was written for me by Andrew Cherry so credit goes to him.

Next you need to create an XML file.

Below is an example of one of my XML files, that when registered in to Media Center, allows me to click on an icon in Media Center and have a VPN connection command run in the background.

<application title="UK VPN-1"
id="{25e1993f-a9d8-4251-871c-0bf84c6d6e29}">
<entrypoint id="{58267566-672b-4b1d-812a-fc46d728d073}"
addin="MissingRemote.AppLauncher.AddIn, MissingRemote.AppLauncher,Culture=Neutral,Version=1.0.0.0,PublicKeyToken=391ca93ec5a00478"
title="UK VPN-1"
description="Connects the UKVPN1"
context="%ProgramFiles%\RasDialPro\UKVPN1.cmd"
imageUrl="C:\Program Files\RasDialPro\Images\Connect-UK.png">
<category category="More Programs"/>
</entrypoint>
</application>

Open notepad and copy the text below in to it:

<application title="The title text that appears below the icon in Media Center"
id="{25e1993f-a9d8-4251-871c-0bf84c6d6e29}">
<entrypoint id="{58267566-672b-4b1d-812a-fc46d728d073}"
addin="MissingRemote.AppLauncher.AddIn, MissingRemote.AppLauncher,Culture=Neutral,Version=1.0.0.0,PublicKeyToken=391ca93ec5a00478"
title="The title text that appears below the icon in Media Center"
description="Description text that appears below the icon in Media Center"
context="%ProgramFiles%\foldername\name of your.cmd"
imageUrl="C:\Program Files\foldername\Images\your icon image.png">
<category category="More Programs"/>
</entrypoint>
</application>

You need to change the items in red to suit your needs, my paths for this point to C:\program files, you can probably change the path to what ever you like and point it to the location of your .cmd file.

The icon images I use are 122 x 122 .png files.

Once you have finished editing your XML file give it an appropriate name and save it in to the C:\windows\ehome directory ensuring it has a .XML extension and not .txt.

Note: If you want to register more than one icon into Media Center by creating a second XML file, you will need to ensure you change the GUID ID’s on the id= and entrypoint id= lines. I normally just change the last two numbers to something else, for example:

id="{25e1993f-a9d8-4251-871c-0bf84c6d6e29}"> change to id="{25e1993f-a9d8-4251-871c-0bf84c6d6e30}">

<entrypoint id="{58267566-672b-4b1d-812a-fc46d728d073}" change to <entrypoint id="{58267566-672b-4b1d-812a-fc46d728d074}"

Now you need to register your XML file in to Media Center, open a command prompt (Run as Administrator), make sure you are in the C:\Windows\ehome directory then type registermceapp /allusers name of your.xml

Where name of your.xml is the filename you gave your xml file that you saved in the ehome directory earlier. Hit enter and you should see Success

image

Open Media Center go to the Extra’s library and your new icon should now be visible, click the icon and test that your command file is run?

To remove the icon you can use the command registermceapp /allusers /u name of your.xml

image

Well I think that’s everything, hopefully it will work for you as well.

Phaze1 Digital