[OBSOLETE] Kodi Manager - playing status and control

Update: github repo changed.

This is a SmartApp which allows you to control Kodi, where HTTP control has been enabled.

Controlling Kodi through SmartThings has the additional benefit that you are also be to trigger events in SmartThings based on events in Kodi, or visa versa. Such as ‘Someone is at the door, pause playback’, or ‘Kodi is playing, dim the living room lights’.

Install the ‘Kodi Manager’ SmartApp from your mobile device, specify your Kodi IP and Kodi login details.
This will then create a device for that kodi device.

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 xbmc.callbacks2 plugin

You will need to install http://kodi.wiki/view/Add-on:Kodi_Callbacks into Kodi
GitHub - KenV99/script.service.kodi.callbacks: Callbacks for Kodi Helix or later

Updates
No longer polls kodi directly. receives updated from a kodi plugin

Known Issues

Instructions

Add the Kodi device type to SmartThings

  1. For UK go to: https://graph-eu01-euwest1.api.smartthings.com35
  2. For US go to: https://graph.api.smartthings.com17
  3. Click ‘My Device Handlers’
  4. Click ‘New Device Handler’ in the top right
  5. Click the ‘From Code’ tab
  6. Paste in the code from: SmartThings-KodiControl-Callback/kodi-client.groovy at master · Toliver182/SmartThings-KodiControl-Callback · GitHub
  7. Click ‘Create’
  8. Click ‘Publish → For Me’

Add the ‘Kodi Manager’ SmartApp to SmartThings

  1. For UK go to: https://graph-eu01-euwest1.api.smartthings.com35
  2. For US go to: https://graph.api.smartthings.com17
  3. Click ‘My SmartApps’
  4. Click the ‘From Code’ tab
  5. Paste in the code from: SmartThings-KodiControl-Callback/kodi-manager-callbacks.groovy at master · Toliver182/SmartThings-KodiControl-Callback · GitHub
  6. Click ‘Create’

Install the Kodi Manager SmartApp

  1. Goto your mobile device and open SmartThings
  2. Got the Marketplace tab at the bottom
  3. Tap SmartApps’
  4. Scroll to the bottom and tap My Apps’
  5. Tap ‘Kodi Manager’
  6. Fill in the details that have been requested and click ‘Done’
  7. Go back to ‘Things’ and you will see your Kodi device there
  8. Go to app settings and enable OAuth
  9. Click ‘Publish → For Me’
  10. Install the device
  11. Select desired switches to control along with desired light levels for each event type (value of 101 will restore to last known level)
  12. Optionally name this instance of the app,assign icon, and modes to operate in
  13. Scroll down and click the View URLs link
  14. On following page the app should display 4 URLs, one for each event type. Copy these down and click done.
  15. Install the xbmc.callbacks2 plugin for Kodi/XBMC
  16. Open the settings for the callbacks2 plugin to the playback menu
  17. Set events to the corresponding URL you copied from the app

If you are having any problems, please uninstall the SmartApp, goto the IDE (where you installed the devicetype and SmartApp code) and click the ‘Logs’ button. Reinstall the SmartApp via your mobile phone and post the logs here for me. Please ensure you check the logs for your username and password before posting!

Massive credit to @iBeech as this is heavily based on his Plex Manager
Also massive credit to @thildemar for hit callback controls.

Let me know if you have any issues.

7 Likes

Glad I could help this community. Great work on making it compatible with Kodi!

1 Like

awesome. I want to test this.

Had a quick minute to test but getting an error on setting up first kodi device:

error java.lang.IllegalArgumentException: The JSON input text should neither be null nor empty. @ line 101
debug No Devices found, adding device
debug getChildDevices(false), children=0
debug Checking to see if the client has been added
debug Installed with settings: [clientName:Kodi, kodiIp:192.168.1.40, kodiPort:8080, kodiUsername:Kodi,    kodiPassword:kodi, theHub:physicalgraph.app.HubWrapper@5dc40efb]
error java.lang.IllegalArgumentException: The JSON input text should neither be null nor empty. @ line 101
debug Received Response: devicetype:04, mac:0024BEF7E20F, networkAddress:0A0A0A0C, deviceAddress:C351, stringCount:04, ssdpPath:/Ircc.xml, ssdpUSN:uuid:00000000-0000-1010-8000-0024bef7e20f, ssdpTerm:, ssdpNTS:ssdp:alive
debug Received Response: devicetype:04, mac:0024BEF7E20F, networkAddress:0A0A0A0C, deviceAddress:C351, stringCount:04, ssdpPath:/Ircc.xml, ssdpUSN:uuid:00000000-0000-1010-8000-0024bef7e20f, ssdpTerm:, ssdpNTS:ssdp:alive 

Are there any version requirements? I run nightly builds of Kodi (17)

I’m getting the same, but with the current stable version. I’d also like to suggest that user/pass not be required since it’s not unusual for folks to run without those…

@jjslegacy @TheMattS

Thanks guys, i have replicated the issues and believe i have solved them.

Please update both the app and device from github, let me know.

Progress…new error! :smile:

error groovy.lang.MissingMethodException: No signature of  method: script14544303185621739234675.setPlaybackState() is applicable for argument types: (java.lang.String) values: [stopped] @ line 51

debug Querying playback state of 192.168.1.40

Same for me, a bit more debug logging:

11:38:24 AM: debug no player id
11:38:24 AM: debug Setting playback state to: stopped
11:38:24 AM: debug raw body: [{“id”:1,“jsonrpc”:“2.0”,“result”:},{“id”:1,“jsonrpc”:“2.0”,“result”:{“speed”:1}},{“id”:“VideoGetItem”,“jsonrpc”:“2.0”,“result”:{“item”:{“album”:“”,“artist”:,“episode”:-1,“fanart”:“”,“file”:“”,“label”:“”,“season”:-1,“showtitle”:“”,“streamdetails”:{“audio”:,“subtitle”:,“video”:},“thumbnail”:“”,“title”:“”,“tvshowid”:-1,“type”:“unknown”}}}]

@jjslegacy @TheMattS

ahh… stupid error sorry.

I’ve updated github again.

I’ve also removed the ability to change volume for now, will be working on getting this working.

Hey Matt, are you experiencing any errors? they log you have posted are all intentional outputs… that i really should clean up.

No errors now but not sure it’s querying the status correctly.

It says nothing is playing although something is playing. if I press nothing playing it shows playing which actually pauses Kodi so it’s out of sync.

Also any plans to be able to add multiple Kodi devices?

Is it supposed to show me the currently playing item in the title field?

Yup, looks good now. Not at home so I can’t actually test functionality, but no errors and the device looks okay.

Very odd, can you post the full log of the kodi device?

It should support multiple kodi, just by adding the smart app again. However this is untested. What version of kodi and on what os are you running?

Thanks

Yes it should do.
May not work for audio,

If it’s not can you post the full log for the kodi device?

I will have to grab a log later.

I am running nightly builds of openelec so version 17 with latest fixes on a few different devices (intel & pi2)

Thank you for this. I just got it installed. Now to use rule machine to make things happen.

Edit: Ok so I got it working to pause if my door bell rings. What are you using to adjust the light level based on play/pause/stop?

i coded this whilst not at home.

its working for myself, i think i may have overlooked some variables that may change between kodi installations.

if i have some full logs i can see if there is a difference.

however since i’ve got home it seems that my home smartthings setup has got slower. eg lights taking longer to come on after motion.
this may be due to the constant polling of kodi…

going to run it for a few days and see. let me know if you see that same issues.

@TheFuzz4 i’m using a kodi plugin to control the hues outside of smart things.
I use rule builder to control the lights via motion sensor, it then checks to see if kodi is playing or pause. if it is is does nothing. if kodi is not playing/pause it turns them on.

@toliver182 is rule builder another smart app similar to rule machine? Off to the search.

Edit: Ok found this thing https://www.simplerulebuilder.com/ simple enough now to see if it works tonight. Might have to hit up @bravenel and see if the kodi device type can be integrated into rule machine.

@TheFuzz4 sorry i actually meant rule machine.