I am very new to the Smartthings community. One of my first objectives with my new toys was to integrate light controls to my Kodi media centers. Thanks to the community I got up and running, but none of the solutions I could find were very full-featured or easy to set up. I decided to code myself a better SmartApp for my own use and figured I would share it with all of you.
This app is designed to control lighting based on four main events in Kodi: play, pause, resume, and stop. Currently it allows you to select which lights you would like to control and set a lighting (dim) level for each event. It also supports restoring the lights to their last known level set outside of this app.
In order to accomplish this the app exposes URL endpoints including a security token for each event type and provides them to the user in a easy to copy/paste format (no more messing with REST endpoint examples and php files). Those endpoints need to be called by Kodi when the events occur. For this we use the kodi.callbacks plugin .
A few things have changed since initial release. This app is now actually two apps, a parent and a child app. The “main” app provides URLs and receives callbacks. The child app represents a grouping of lights. This allows you to have multiple groups of lights set at different levels from one event in Kodi. KenV99 has also created a new Kodi callbacks plugin that adds some features and works better in the newer builds of Kodi. He has been very active in replying to any issues on the plugin’s forum thread and I recommend everyone switch from the old xbmc callbacks2 plugin to this new one.
Install should go like this:
- Install both SmartApp’s code under My SmartApps (New SmartApp>From Code)
2.For the main application (not required for the light group application): App Settings>oAuth, make sure oAuth is enabled and you see client secret and such. You don’t need these values, but must make sure oAuth is enabled for your app.
- For the main application (not required for the light group application): Publish>For Me
- On smartthings mobile app go to marketplace>SmartApps>My Apps
- Add Kodi Callback Endpoint
- Add groups of desired switches to control along with desired light levels for each event type (value of 101 will restore to last known level)
- Optionally name this instance of the app, and modes to operate in (for example don’t run in “night” mode)
- Scroll down and click the View URLs link
- On following page the app should display 6 URLs, one for each main event type, plus 2 custom. Copy these down and click done.
- Install the Kodi Callbacks plugin for Kodi
- Open the settings for the callbacks plugin
- On the Tasks page create a http task for each URL you wish to use using the URLs you copied above
- On the events tab create events for play/stop/pause/resume and assign them to the appropriate task you just created.
This is a first version and I had to use some trickery to restore light values as there does not seem to be an officially documented way to do that normally. Because of this expect some bugs. I am happy to help answer questions as I am able. You may also want to check out some of the previous tutorials on setting up Kodi integration to get an idea of the process this was based on.
That said, here is the code:
(Make sure you install BOTH files)
Please make sure to read the Kodi Wiki for the callbacks addon, it is quite useful for detailed setup instructions. If you are like me and want to fiddle a bit more I pointed my callbacks tasks to python files and passed the %mt (mediatype argument). This way events only trigger for movie or TV playback (avoiding light changes when playing music files). This is the code I used in the python files:
import urllib2 def run(arg): if arg == 'movie' or arg == 'episode': urllib2.urlopen('Http://URLHERE').read()
@toliver182 is also working on a Kodi device type that uses some of this code and will allow control of Kodi from SmartThings. If you need bi-directional control check it out: [OBSOLETE] Kodi Manager - playing status and control - #32 by toliver182
Please let me know if you have issues or would like a feature added.