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, 17 August 2011

My Movies for iPhone Pro & iPad Updated v1.60


You can read more about My Movies for iPhone here

- Adds Parental Controls

- Adds Twitter Integration

- Graphical Updates (Splash Screen, Icon, Welcome Page and more)

- Fixes Various Issues




Update: My Movies for iPad has also been updated:

- Adds Barcode Scanning on iPad 2.

- Adds Parental Controls.

- Adds Twitter Integration.

- Adds Dutch, Norwegian and Russian language.

- Graphical Updates (Splash Screen, Icon, Welcome Page and more)

- Fixes various issues.

You can read more about My Movies for iPad here












Thursday, 11 August 2011

My Movies for MAC OS X Pre Release out now

Introduction

My Movies for Mac OS X allows you to catalog your entire movie collection from our high quality online data service containing data for more than 475,000 DVD, Blu-ray and HD DVD titles from various countries. The application supports Mac OS X 10.6 and higher.

Notice! The application is currently in Pre Release, and is freely available to everyone during this Pre Release period. The Pre Release distributions contains a time bomb functionality, allowing to function typically for one month from the release date.

My Movies for Mac OS X requires you to create a user account, or log on to an existing My Movies account to be able to use the program. Your collection will follow your user account through our online servers, allowing you to switch between different clients without ever loosing your data. If you log in to an existing My Movies account, your current collection will automatically be synchronized to My Movies for Mac OS X. Users of My Movies for iPhone, iPad or Android will automatically have their collection synchronized between My Movies for Mac OS X and your movie devices.

Continued here