Ever since discovering SmartThings during the initial Kickstarter event, I’ve been following along as SmartThings has grown from an idea into a robust product.
I bought my first Z-Wave devices two months ago to replace my existing X-10 home automation network and I’ve never looked back.
My biggest issue to date has been trying to find a way to integrate Kodi/XBMC with ST in order to control the lights during media playback.
As a hardware guy with absolutely no development skills, I struggled with this for quite a while before finally figuring it out. While my way may give a true developer the heebiest of jeebies, this is meant to provide an easy method for non-developers to add scripted lighting control to their home theater systems.
My wife has never really seen the value of home automation, and it has always been a struggle for me to justify my various purchases and modifications to the home to her.
We are massive media consumers, so when I got the lights to interface with the movies, she suddenly LOVED the system.
On with the show!
I run Kodi on several Windows systems at home with a centralized shared database. These instructions should work for you even if you are on one of the various linux or embedded distros such as RPi, etc.
You will need the following:
KenV99’s xbmc.callbacks2 service plugin for Kodi/XBMC (based on pilluli’s original callbacks)
wget for Windows (this is included in linux distros for both PC and embedded solutions)
REST Endpoint and the PHP file created by @Ben
Follow the REST Endpoint tutorial, being sure to enable OAuth.
I have discovered that using the hosted PHP file in the tutorial works just fine in order to get the URLs needed to trigger the on/off functionality so you should not need to roll your own. I highly recommend that you do though as you never know when or if the hosted one will suffer from link-rot.
Once you have the REST endpoint created and visiting your PHP shows you the on/off/toggle buttons for the various devices you have authorized, you can move on to the next step.
Install wget for Windows from the link above.
You will need to create a folder on your hard drive to store your scripts.
I placed mine at C:\Batch and all of my files go into this.
Open Notepad (or your favorite editor).
Go back to the PHP site from the REST Tutorial showing all of your devices.
For the devices you would like to turn off when media playback begins, find the device in the PHP site, right click on the Off button, and select Copy Link Address (Chrome) or Copy Shortcut (IE), or the equivalent in any browser you are using.
This will give you a link with the following format: http://graph.api.smartthings.com/api/smartapps/installations/(installation-ID)/switches/(switch-ID)/off?access_token=(access-token)
Note the word Off in the URL. This is the actual command being sent to the device.
Paste the URL into the new text document you have opened in Notepad.
Do the same for any other devices you want to shut off when you hit Play or Resume in Kodi/XBMC, placing each new URL on a separate line.
When you have everything you want in here, save the file to the Scripts folder you created, and name it something like Off.txt.
I have all of my interior lights turn off in this file.
Create a new txt file using the same process, but use the On command buttons to get your links, and label the file as On.txt.
I have only my living room lamps turn on in this file.
Finally, using Notepad or other text editor, create a new file with the following line in it:
“C:\program files (x86)\gnuwin32\bin\wget.exe” --no-check-certificate -i c:\batch\off.txt
What this does: The first part in quotes is the path to the wget executable. This may vary on your system. If you have a Windows 32 bit system, it will be under “C:\Program Files”. The quotes are needed due to spaces in the path.
Linux distributions will not need to use the absolute path, and Windows systems can add this path to the system path variables if desired.
The second part ignores any certificate inconsistencies when requesting the URL in the txt file. I have found this is needed even with http requests.
The third item, -i, tells wget to process a file for commands, and the last is the path to the text file we just created for shutting lights off.
Save this file as moviestart.cmd, being sure that the file does not save as a text file named moviestart.cmd.txt.
Perform the same above steps with the same line of text, only change the path to the txt file to C:\batch\On.txt and save the file as moviestop.cmd
These above steps can be repeated for various control functions, as the next process can control more than just two discreet lighting modes.
Download the xbmc.callbacks2 plugin from the link above. Save the zip file to your hard drive in a location you can find it.
Open Kodi/XBMC, and go to the Settings menu and select the Add-Ons option.
Choose Install from Zip File, and then browse to the downloaded zip file you saved.
When the installation is finished, go back to Add-Ons and select Enabled Add-ons from the list.
Browse to the Services menu item, and look for xbmc.callbacks2 to confirm it is installed.
Select the xbmc.callbacks2 plugin, and select Configure.
Under the Playback menu you’ll see multiple options.
Set the options as follows:
On Playback Started (And the On Playback Resumed option)
Type = Script
Script Executable = C:\Batch\moviestart.cmd (or your path where your files are)
Parameters = blank
Requires Shell? = On
On Playback Stopped (And the On Playback Paused option)
Type = Script
Script Executable = C:\Batch\moviestop.cmd (or your path where your files are)
Parameters = blank
Requires Shell? = On
Click OK at the bottom to save these settings.
If you click the Test Command option after saving the settings, you will see a diagnostic feedback of the script you created running.
Your lights should react as you commanded them to. Click OK on the diagnostics, and go watch a movie.
Note: The .txt and .cmd file creation process will work for a variety of different things… You can make this work however you see fit.
One thing I am trying to figure out, not having development skills, is how to dim lights down and back up rather than perform a hard on/off command. I have yet to figure that out.