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

I’m really not sure then. I just double checked and it worked for me. Make sure you are using the new installation id and access token. From what I can tell that not found error you are getting usually refers to the app id

Did you ever get the dimmer to work? I’m having the same issue with the not found. The on/off works just fine but once I put /level/25 in there then it fails.

@TheFuzz4 I was having the same problem. So I submitted a support ticket. The response is that level is not working and this is a known problem. They believe they have a fix for it and it will be going out in the next firmware release.

Also @Synthesis I may have a simpler solution for this setup. Instead of having to have a text file and a command file. I have installed curl for Windows and I am executing curl commands directly in the command file.

So my command file just has
Curl -h

Can you provide a sanitized copy of your command file and an example of how your config is set up?

My primary HTPC Kodi install went wonky a while back and I have yet to revisit this, though I have my config backed up.
If I can simplify things, then that would be awesome.

So I was able to accomplish what I wanted it to do be it a little messy. Per the other thread I created 3 virtual switches named like Kodi Living Room Play, Pause, Stop. Then I also per the other thread set them up with the smart lights app so that when this switch is called it will adjust the actual light that I want. I also told the app to not turn off.

So then on the Kodi backend I was having issues with calling the python scripts so I just wrote some bash scripts that basically look like this (I tried to use curl but was not getting anywhere with it)

wget http://graph.api.smartthings.com/api/smartapps/installations/(installation ID)/switches/(switch ID)/off?access_token=(access token) && wget http://graph.api.smartthings.com/api/smartapps/installations/(installation ID)/switches/(switch ID)/on?access_token=(access token) 

Ok so now I’m sure that you’re wondering why do I call two wget’s? Well the problem was that once the switch was on it never turned off so if I paused it the lights wouldn’t come up to the pause level. So in each of my scripts I make a call to ensure that the other kodi virtual switch is actually off before turning on the next one.

So in my play script I first make sure that the pause is off

My pause script makes sure that the play is off

My stop script makes sure that my play and pause are off it then turns itself on to bring the lights back to 100% then I have one last wget in there that then turns the stop off as well.

Let me know if this doesn’t make sense :). Basically just make sure that you copy and paste the right URL from each of the virtual switches states that you want it to use into the script.

Here is what the file looks like:

curl https://api.particle.io/v1/devices/your device id here/led \ -d access_token=yuor access token\ -d params=1
curl https://api.particle.io/v1/devices/your device id here/led \ -d access_token=your access token \ -d params=1
curl https://api.particle.io/v1/devices/your device id here/led \ -d access_token=your access token\ -d params=1

Right now I am using it to control home theater sconces and platform lights that are all run off of Particle Photons as documented here:

I will setup the curl commands for smartthings when I get confirmation that the set level command is working properly.

Curl for windows can be picked up here:

Let me know if you have any other questions.


I have refined this a little more as I didn’t like the waterfall effect of lights turning on/off/dimming.

Here is how I set this up:
I have 3 commands that I call from callbacks moviestart.cmd (for start/resume) moviestop.cmd and moviepause.cmd.

For moviestart.cmd now contains the following:

Start /B “moviestartHTPlatform” "C:\Batch\moviestartHTPlatform.cmd"
Start /B “moviestartHTSconce” "C:\Batch\moviestartHTSconce.cmd"
Start /B “moviestartHTSconce2” “C:\Batch\movestartHTSconce2.cmd”

The moviestart.cmd will kick off in the background in parallel the three commands
Within C:\Batch\moviestartHTPlatform.cmd I have placed the curl command from above:
curl https://api.particle.io/v1/devices/your device id here/led \ -d access_token=yuor access token\ -d params=1
One curl command in each .cmd that you want to kick off (for each device).

Thanks for the information.

I’ll likely pick your brain in-depth once setLevel is working, as I’m really hoping to get things moving with this in the near future.

Right now my Kodi install crashes on launch, and I’m not 100% sure why, but haven’t had much desire to investigate either.

Eh, I’ll get it sorted.

I can’t wait till the set level is working. I just added in smart switches over the weekend to my basement so I can dim out the ceiling lights and then drop the level of the wall lights. Sadly the switch app lowest setting is only 10% and well I want to go down to 2% like I do with plex.
I’d also like the the set limit because it will really simplify my setup. Instead of having Kodi make a call to my virtual switch which then calls the smart light app to lower the level, I can just set it with one api call. Would be nice if I could also set a mood with an api call as well.

Has anyone did anything integrating Kodi (running on ras PI) with ST?

Honestly as a non-programmer, since my living room bulbs are Philips Hue and I have the Hue Bridge connected, it was just far easier to use the Kodi plugin to control my Hue bulbs directly rather than go through SmartThings for that.

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

Thank you @thildemar for the excellent write up. Now can someone tell me what the preferred method would be to do this along with only having the lights fire off only during a certain mode. For example I have this working in 2 rooms of my house. 1 is the basement which having the lights come on down there is no biggie since well its usually dark down there.
2. Is in my living room and the problem here is I don’t want the lights coming on in the middle of the day because I’m watching TV here. So I have in my ST a night mode that fires off at sunset and with my current setup with the smart light app and virtual switches to control the dimmers in the living room I can tell the app to only fire off during night mode. I wonder if with rule machine I can specify something but I’d rather not have the lights turn on then immediately off. Thank you all for your awesome work and dedication to this.

For quick and dirty just wrap the contents of the update function in an if statement:

if (location.currentMode == "Night"){
    //@kevintierney update code here

That way the updates will only occur if night mode is on.

I am also working on a better SmartApp specifically for Kodi. Personally I want light controls only to work from existing levels. So, if the theater lights are at 60% when the movie starts it will turn them off on playback and restore to 60% when stopped. If lights are off when playback starts they will simply stay off. Either way I want a SmartApp that contains the logic for each event in Kodi, that way I can just make changes to the SmartApp code when i want different effects. I’ll post when i have something workable.

1 Like

Which update section should this go into. Also after I save the code into the IDE the first time its fine. Everytime I try and click save there after I get

groovy.lang.MissingPropertyException: No such property: id for class: java.lang.String

which then won’t let me save it so I can’t test the update function if its actually working.

Something like this:

private void update(devices) {
log.debug "update, request: params: ${params}, devices: $devices.id"
if (location.currentMode == "Night"){

//def command = request.JSON?.command
def command = params.command
def level = params.level
//let's create a toggle option here
if (command) 
	def device = devices.find { it.id == params.id }
	if (!device) {
		httpError(404, "Device not found")
	} else {
    	if(command == "toggle")
        	if(device.currentValue('switch') == "on")
   		}else if (command == "level"){

Would have to look at what line number that error was referencing to know for sure what was going on.

You could also have Kodi point to a simulated switch and then use something like Rule machine to automate your other lights based on that. Basically Kodi turns on and off simulated switch (follow instructions above), then rule machine used the status of that simulated switch to change real ones and apply conditions (such as only at night). That may be easier if you are not familiar with code.

Yeah I was originally doing it with 3 virtual switches and then the smart lighting app but I wasn’t satisfied with the app since the lowest setting I could go was only 10% and I’d like to go down to 5%. I just got rule machine installed the other day so I think that I might go that route. Thanks for the tip :slight_smile:

Making my own Kodi endpoint code available HERE

It will hopefully make this easier for anyone else trying to set this up: no more PHP endpoint and fully supports dimming!

Check out the smartapp @thildemar wrote. I have it working how I want it to work for my living room TV with a little help from Rule Machine to only fire during specific modes (aka not during the day).

@thildemar Thank you so much for this! I followed your instructions to get the necessary URLs to dim my lights. From there I created action files for the Kodi CinemaVision add-on and couldn’t be happier with the results. I would recommend CinemaVision to anyone who has been running Cinema Experience by the way. It picks up where that long abandoned add-on left off.