SmartThings Community

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

(Justin Wurth) #18


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 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).

(The Viking AKA "Holy Crap You're a Giant!") #19

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.

(Jason Hamilton) #20

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.

(JP) #21

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

(jhoff80) #22

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.

(Adam E) #23

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:<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:<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('<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!

(Jason Hamilton) #24

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.

(Adam E) #25

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.

(Jason Hamilton) #26

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.

(Adam E) #27

Something like this:

private void update(devices) {
log.debug "update, request: params: ${params}, devices: $"
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 { == }
	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.

(Jason Hamilton) #28

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:

(Adam E) #29

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!

(JP) #30

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).

(Ken Nalbone) #31

@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.

(The Viking AKA "Holy Crap You're a Giant!") #32

Thanks to your post @knalbone, I replaced my outdated and malfunctioning installation of Kodi 14/Cinema Experience with Kodi 15 and CinemaVision and got my Home Theater PC operational again for the first time in many moons.

I was unaware that CinemaVision had released a full addon, though I was familiar with their site from quite a while back.
Now I just need to fix the volume differences between compressed audio and bitstreaming audio to my receiver…
It goes from really quiet to REALLY LOUD when the mode changes.

(Toliver182) #33

hey all, FYI, i have created a polling based kodi manager:

(s) #34

What app from @kevintierney was used to make the URL’s? sorry if it’s obvious somewhere in this thread, but a lot of this is still new to me…

(Adam E) #35

Check the first post in thread if you really want to do this manually. Otherwise I would look at my other thread Here. I published an app specifically for this purpose that is a lot easier to setup. Instructions are in that thread.

(kojak) #36

Question I am using the kodi callbacks addon and I am having trouble getting the lights to dim when I start playing a movie. A little background here, I am using kodi on a GBOX which is an android box. I am not sure if I setup the callbacks addon correctly. I created http commands using the urls from the kodi endpoints smart app in ST. I set each task with the http url to corresponding events play/pause/resume/stop in the addon. However it does not seem to work when I playback a movie or use any commands. I did notice that when I used the test command in the addon it did dim the lights on play task but then it also seemed to freeze kodi. I would really appreciate your help , I am fairly new at this and have only had ST for a week and I have no programing skills. I am really surprised I got this far.

(kojak) #37

Ok I re-tested the urls in callbacks and they are all working when I use the test command in the addon. However when I playback a movie that is saved to my networked hard drive and linked to kodi thorugh windows SMB it will not work. Also when I try to stream from another addon in kodi it also will not work. I don’t know what I am missing here. I know it is not a problem with the ST smart app or with the urls in the kodi addon because they test fine. So is it because the file is being streamed either from my networked HDD or from addon… does the file have to be played back locally only?