Google Search

Custom Search

Powered by...

Find us on Facebook

Friday 5 February 2016

Kodi keyboard shortcuts to run Vera scenes (Windows)

This question came up on the Vera forums, how to use Kodi media center keyboard shortcuts to run scenes in the Vera home automation controller. This is for Kodi Windows users only.

If you wish to do this in Kodi / OpenElec (Linux) then read this article here instead.

Here is a brief overview of the steps required:

Step 1: Create or Edit the Kodi keyboard.xml file to create your desired keyboard shortcuts.

Step 2: Create a pyhton .py script file that Kodi calls when you press your keyboard shortcut in Kodi. In turn the python script calls a Windows .vbs script.

Step 3. Ceate the .vbs script which sends the HTTP command to the Vera controller to run the scene.

The main reason why we use a .vbs script is so we don’t have pop up command windows appearing over the top of the Kodi user interface and the HTTP request will be sent to Vera invisibly in the background.

Step 1: Create or Edit the Kodi keyboard.xml file to create your desired keyboard shortcuts.

The keyboard.xml file should be located in this folder:

C:\Users\Stuart\AppData\Roaming\Kodi\userdata\keymaps

Obviously browse to your own “username” folder what ever that is called, mine is called “Stuart”

If you have an existing keyboard.xml file in this folder then great we can just edit this in a text editor program. I use EditPade Lite7 as my text editor.

If you do not have a keyboard.xml file in this folder, you can download the master keyboard.xml file, to do this right click on this link here and select “Save Link As” (Chrome browser) and save the file Keyboard.xml in to the correct folder.

C:\Users\Username\AppData\Roaming\Kodi\userdata\keymaps

Now open the Keyboard.xml file in with your preferred text editor application.

The file looks like this:

image

Scroll down to the <keyboard> section

image

Hit enter to make a new line

Now this is where we enter our new keyboard shortcut and specify the python script file it should run. In my example here I want my keyboard shortcut to be Ctrl+Alt+A and I want this to run a python script called lounge-on.py

<A mod="ctrl,alt">RunScript(C:\Users\Stuart\AppData\Roaming\Kodi\userdata\Scripts\lounge-on.py)</A>

So now the Keyboard.xml file looks like this, save and close the file.

image

Note: Anytime you edit the keyboard.xml file you need to close and reopen Kodi for the changes to take affect.

Step 2: Create a pyhton .py script file that Kodi calls when you press your keyboard shortcut

Before you start this step ensure you can see file extensions in Windows Explorer.

Now the path I specified in the keyboard.xml file for my python script was:

C:\Users\Stuart\AppData\Roaming\Kodi\userdata\Scripts\lounge-on.py

So in Windows Explorer I need to navigate to the Kodi\Userdata folder and I need to create a new sub-folder called “Scripts”

In here I now need to create a new python .py script file. To do this right click in Windows Explorer and on the menu select New –> Text Document.

image

Then rename the text file in this example I am calling my python script file lounge-on.py

Ensure you have removed the .txt extension and that it now has a .py extension instead.

image

Now right click the new .py file and select to edit it in your text editor.

Paste in this code and change the path as required:

import subprocess
child = subprocess.Popen("wscript C:\Users\Stuart\AppData\Roaming\Kodi\userdata\Scripts\lounge-on.vbs")

So my lounge-on.py file now looks like this:

image

Save and close the python .py script file.

In the python .py script file, we call another .vbs file. I am going to call my lounge-on.vbs.

Step 3. Ceate the .vbs script which sends the HTTP command to the Vera controller to run the scene.

In Windows Explorer in the same folder

C:\Users\Stuart\AppData\Roaming\Kodi\userdata\Scripts\

Right click and from the menu select New –> Text Document

image

Rename the file including the .txt extension to lounge-on.vbs in this example.

image

Now right click the lounge-on.vbs file and edit it in your text editor.

Enter this code:

Dim oXmlHttp
Dim sWebPage

set oXmlHttp = CreateObject("MSXML2.XMLHTTP")

oXmlHttp.open "GET", "http://192.168.1.10:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=14", false
oXmlHttp.send ""
sWebPage = oXmlHttp.responseText

image

You need to change the IP address to the IP address of your Vera controller and the SceneNum needs to be changed to the scene number you want to run.

Save and close the .vbs file.

Testing

That’s it the setup is completed, now open Kodi and enter your keyboard shortcut, in this example it was Ctrl+Alt+A and your Vera scene should then be run and you should see no command windows popping up over the top of the Kodi user interface.

Running  more scenes

Repeat the process to be able to run more scenes. So for example add a new line in to the keyboard.xml file like:

<B mod="ctrl,alt">RunScript(C:\Users\Stuart\AppData\Roaming\Kodi\userdata\Scripts\lounge-off.py)</B>

image

In this example pressing Ctrl+Alt+B would run a python script file called lounge-off.py

So you would then create the lounge-off.py file and the lounge-off.vbs file etc.

Controlling Vera Devices

You can also use HTTP commands to turn on or off Vera devices, rather than running scenes. For exmaple this HTTP command turns ON my FAN device.

http://192.168.1.10:3480/data_request?id=lu_action&output_format=xml&DeviceNum=50&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1

You need to specifiy the correct IP address of your Vera controller and specify the correct device number in DeviceNum=

ON is - SetTarget&newTargetValue=1

OFF is - SetTarget&newTargetValue=0

Summary

This is a fairly easy way to be able to use Kodi keyboard shortcuts to run scenes in Vera and also to be able to control devices in Vera.

In addition you could then go on to program your universal remote control to send these keyboard shortcuts to your Kodi HTPC and you could then run scenes or control devices from your remote control handset via the Kodi HTPC etc.