Kodi/XBMC light control - a (relatively) simple how-to

Hi All,
I am new to working on SmartThings, but wanted to get Kodi integration up and running and started with this tutorial. Unfortunately it seems like some of this is out of date or not overly clear, so I figured I would post my findings.

I was running into issues with the PHP REST interface and getting correct URLs to use, particularly for dimming. Turns out that the PHP file is only really a way to get the URLs you need more easily (when it works). Here is how I have direct dimming working from Kodi on both Windows and FireTv (Android).

First you need to get your URLs for light control, for this I used a modified version of the smartapp @kevintierney provided. His version will work fine to start from (as long as you have the level command). Make sure you create the smartapp with oauth enabled, save it, publish and start the simulator. Select the switches you want access to in the simulator and scroll to the bottom, you should see an API Endpoint and API Token. First we will use these to get the IDs of your switches:

https://graph.api.smartthings.com/api/smartapps/installations/<YOUR ENDPOINT ID>/switches?access_token=<YOUR ACCESS TOKEN>

Put that in your favorite browser’s address bar and it should return something like this:

[{"id":"xxx-xxx-xxxxxx","label":"switches[0]","type":"switch"},{"id":"xxx-xxxx-xxxxxxx","label":"Master Light Dimmer","type":"switch"}]

Each set of brackets has values for a particular switch, make note of the id values for the switches you wish to control. Now put together a new URL with that data like so:

  https://graph.api.smartthings.com/api/smartapps/installations/<YOUR ENDPOINT ID>/switches/<YOUR SWITCH ID>/level/<DIM LEVEL %(ex: 45)>?access_token=<YOUR ACCESS TOKEN>

Pasting this URL into a browser should set your light level, if so the hard part is over. Create a URL like this for each switch you wish to control.

Now in KODI add the callbacks2 plugin as listed above. You can either set the plugin events to directly call your new URLs, or have it call a script that then calls your URLs. Personally I like using a python script as it works across platforms for KODI. Mine looks something like this:

import requests
requests.get('https://graph.api.smartthings.com/api/smartapps/installations/<YOUR ENDPOINT ID>/switches/<YOUR SWITCH ID>/level/<DIM LEVEL %(ex: 45)>?access_token=<YOUR ACCESS TOKEN>')

You can add additional lines to that script for controlling multiple lights. If you want to get fancy you can even play around with multi-threading the requests in python to get the commands to fire at roughly the same time (instead of in sequence).

Hopefully this helps anyone else that was getting stuck with this!

1 Like