[OBSOLETE] Kodi for SmartThings BETA

Kodi for SmartThings [BETA]

Control and react to event changes from Kodi (formerly XBMC), your favorite media center software.

Note: This is a BETA and there may be some issues – particularly with the eventing as it is dependent upon the SmartThings scheduler to ensure the event subscriptions stay fresh. Please review the IDE Live Logs when reporting issues as it’s helpful to have a copy of the logs/errors when reporting issues.

Unlike other Kodi implementations seen on the SmartThings platform, this solution works completely within SmartThings and does not require any additional plugins or middleware tools.

SmartThings Installation

There are two components needed for the Kodi integration to work.

  1. SmartApp - used for discovery of the Kodi instances on your network and creation of the Kodi devices in SmartThings
  2. Device Type - the actual code used to control and react to changes from your Kodi devices

You must publish both the SmartApp and Device Type in the SmartThings IDE for everything to work properly.

Option 1: GitHub Integration

The best way to get updates for Kodi for SmartThings is to enable GitHub integration and add my repository. If you don’t know what GitHub is, see the Manual Install method below:

  1. Open the IDE and navigate to My SmartApps or My Device Handlers
  2. Select Settings
  3. Select Add new repository`
  4. Enter the following details:
    Owner: joshualyon
    Name: ST-Kodi
    Branch: master

Now whenever you need to update to the latest version, you can choose ↓ Update from Repo, select ST-Kodi and get your updates.

Option 2: Manual Install

While using the GitHub integration is the recommended method for installing the Kodi SmartApp, you can also install the SmartApp and Device type manually.

Follow the instructions from the ThingsThatAreSmart.wiki on how to install a custom device type and SmartApp.

How to Use

Configure Kodi

Enable the Web Server and UPnP in Kodi.

  1. In Kodi, open System (Settings)
  2. Navigate down to Services
  3. From the UPnP tab, select Allow remote control via UPnP
  4. From the Web server tab, select Allow remote control via HTTP

Install the SmartApp

From the SmartThings mobile app:

  1. Select Marketplace from the bottom navigation
  2. Select the SmartApps tab
  3. Scoll down and select the My Apps category
  4. Select the Kodi (formerly XBMC) SmartApp
  5. Wait for the discovery to complete, then select your Kodi instances and tap Done
  6. Tap Done again to complete the setup and beging using your devices

Note: If you have a username and password set for your Kodi instance, open the device from the My HomeThings screen in SmartThings, selected Edit Device from the menu and ensure you have entered a username and password.

25 Likes

Frequently Asked Questions

Events aren’t working, what should I do?

Make sure you are running the latest version of the Device Type and SmartApp. (See How do I updated to the newest version? below).

Then, in the SmartThings IDE, navigate to My LocationsList SmartAppsKodi (formerly XBMC) and review the Next Run Time and Prev Run Time fields for checkHandler under Scheduled Jobs. You should expect the Prev Run Time to have occurred in the last 20 minutes and the Next Run Time to be scheduled sometime within 20 minutes into the future.

If either of the Run Time values are not within 20 minutes of the current time, you can try manually updating the SmartApp to kickoff the scheduler per How do I manually update the scheduler? below.

Note: If you leave your media center off, you can manually kick-off the event subscription checks by tapping the Refresh button in the device after you have turned on your media center and Kodi has started.

How do I update to the newest version?

If you are using the GitHub integration noted in the installation instructions above, navigate to your SmartApp and Device Handler pages and select the ↓ Update from Repo then ST-Kodi repository. When the list of options comes up, check the box next to the Kodi SmartApp/Device and select Execute Update

If you performed a manual installation, you will need manually edit your SmartApp and paste in the updated SmartApp code, then manually edit your Device Type and paste in the updated Device Type code.

How do I manually update the scheduler?

From the SmartThings IDE, navigate to My LocationsList SmartApps and tap the Update link on the Kodi (formerly XBMC) row.

I leave my media center off, how I can refresh the event subscription without waiting 20 minutes for the next schedule?

You can manually kick off the Event Subscription check by tapping the Refresh button in your device. This will get the latest status and metadata from Kodi as well as clean up the event subscriptions.

Note: if you leave Kodi on all the time and are having event issues, try the steps listed in Events aren't working, what should I do?

I’m getting an ‘Unexpected Error’. What do I do?

Open the SmartThings IDE and watch the Live Logs to see what error messages are shown. Share the relevant logs here with any additional details.

Device type ‘Kodi Media Center’ in namespace ‘boshdirect’ not found.

Make sure you have installed and published both the SmartApp and the Device Type Handler.

3 Likes

Hey, just installing now.

The github name has to be iamcanadian2222 not boshdirect, couldn’t find a repo at boshdirect

EDIT: my bad, forgot to enter username and password

Hey, installed, getting lots of errors in the logs

4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:52 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:53 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:52 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug running todos
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug Current state is: Stopped
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace UPnP Response
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [nts:upnp:propchange, nt:upnp:event, content-length:1243, sid:uuid:ee72ff75-e649-08ee-5e71-3d2636d4ab11, host:192.168.1.24:39500, seq:0, user-agent:Neptune/1.1.3, content-type:text/xml; charset="utf-8", notify /notify http/1.1:null]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:52 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug running todos
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug Current state is: Stopped
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace UPnP Response
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [nts:upnp:propchange, nt:upnp:event, content-length:1243, sid:uuid:d62aca4c-f321-e7db-557e-69d6b08becf4, host:192.168.1.24:39500, seq:0, user-agent:Neptune/1.1.3, content-type:text/xml; charset="utf-8", notify /notify http/1.1:null]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:53 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:52 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: error groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. @ line 328
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug HEADER: [content-length:2832, http/1.1 200 ok:null, content-type:text/xml; charset="utf-8", server:UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1, date:Sat, 06 Feb 2016 16:42:53 GMT]
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: trace Response Received (with Headers and Body)
4079d778-f00f-45de-a7ad-d08605d27ef0  16:42:51 GMT: debug running todos

Would you prefer to raise the issues here or in github?

1 Like

Thanks for the clarification on the GitHub name. I’ll update the docs! Yes, please post the issue on GitHub including details of your Kodi setup (eg. OS and Kodi version).

After correcting username and password it all seems pretty good, will test more later. looks awesome

1 Like

I really wanted to use this, but I’m getting the error that my hub isn’t up to date so I can’t.
Hopefully in a few weeks if support gets back to me, maybe.

Same problem here. One of the version check calls is broken - rather annoying as I can’t install any apps I want to test out.

@diehllane and @jjslegacy can you guys open the SmartThings IDE and let me know what firmware version number your hub is reporting?

In the meantime, you can try changing if(canInstallLabs()) on around line 137 of the SmartApp to if(true) to override the check and see if the device discovery process works as expected for you.

I have the latest hub version - it’s a known issue and my support ticket says they hope for a fix in the next 1-2 weeks - ugh (specificially this is broken: hasAllHubsOver - seems maybe it’s not broken for everyone)

I did the following to get around it:

private Boolean canInstallLabs()
{
//return hasAllHubsOver(“000.011.00603”)
return true
}

2 Likes

My firmware version is 000.014.00026

I tried your suggestion but now I just get the red banner for “You are not authorized to perform this operation”

A quick bit of playing the pause/play toggle doesn’t seem to work quite right. If I pause it shows pause for a second and goes back to play but the video remains paused so the concept works just not the button

Awesome! This worked for me, too. I hadn’t gotten to the bottom of the code so I hadn’t seen that in there.

Not that there’s anything wrong with multiple ways to do the same thing, but you could already use Kodi as a DLNA speaker, with this pair of app/device type:

I’ve been using that combo with Kodi for quite a while now.

This is an app to control Kodi not play sound through it

1 Like

And to be able to react to events in Kodi. So you could use this with Rule Machine Advanced to start your favorite playlist triggered by something occurring in SmartThings. Or you could have SmartThings automatically dim on your lights when the movie is paused or change your hue bulbs to your favorite color to match the theme of your movie or music.

Hi Joshua

I’m installing and getting this error with the smartapp…Is it something I’m doing?

Thanks

No signature of method: script1454802474987978170545.metadata() is applicable for argument types: (script1454802474987978170545$_run_closure1) values: [script1454802474987978170545$_run_closure1@39d9bb92] Possible solutions: getMetadata(), getState(), setState(java.lang.Object), metaClass(groovy.lang.Closure)

[quote=“jjslegacy, post:15, topic:38305, full:true”]
This is an app to control Kodi not play sound through it
[/quote]Ok - similar but not identical. My bad. The DLNA device supports some controls (volume, pause/play/stop) and events, but not playlists.

I tried out the DLNA device type tonight and it is very impressive! @Kristopher pointed me to the DLNA player when I was looking for the Media Transport Control icons (Sonos Play/Forward/Pause), but I never thought to try it out with Kodi! Looking through the DLNA code, I am using a lot of the same concepts as the DLNA player for discovery and eventing, but I’m using the built-in JSON-RPC end points from Kodi for more nuanced control and exposing additional attributes.

I’m still working on building out the capabilities, but here’s some documentation on what I have done so far:

https://github.com/iamcanadian2222/ST-Kodi/blob/master/CAPABILITIES.md

Having all the extra commands and attributes available in the device type is particularly useful for advanced integrations like Tasker/Widgets on Android or Rule Machine Expert Features where you could use some of the custom attributes or methods to achieve some really cool things.

2 Likes

My bad! I had the links to the SmartApp and Device Type code backwards! I have corrected the first post - try it now!

PS. I guess that’s what I get for writing documentation at 1 AM!

I pushed an update tonight which includes:

  • Fix for the Play/Pause button reported by @jjslegacy
  • Added play/pause state to the tile in the main Things list
  • Cleaned up the message parsing section so it won’t react to non-JSON responses
  • Changed to schedule() which should be more stable than the recursive runIn() calls (and moved to SmartApp)

For the last bullet item around scheduling, which is a big one, after you update the Device and SmartApp code, if you have any existing Kodi devices, you will need to open the Kodi SmartApp in your My HomeSmartApps view and tap Done to kickoff the new scheduler.