Skip to content

Kodi Binding ​

Kodi (formerly known as XBMC) is a free and open source (GPL) software media center for playing videos, music, pictures, games, and more. Kodi runs on Linux, OS X, BSD, Windows, iOS, and Android. It allows users to play and view most videos, music, podcasts, and other digital media files from local and network storage media and the internet.

The Kodi Binding integrates Kodi media center support with openHAB, allowing both controlling the player as well as retrieving player status data like the currently played movie title.

The Kodi binding is the successor to the openHAB 1.x xbmc binding.

Preparation ​

In order to allow Kodi to be controlled through this binding, you need to enable the Kodi application remote control feature. Please enable "Allow remote control from applications on this/other systems" in the Kodi settings menu under:

  • Settings ➔ Services ➔ Control ➔
    • Allow remote control from applications on this system
    • Allow remote control from applications on other systems

To make use of the auto-discovery feature, you additionally need to enable "Allow control of Kodi via UPnP" in the Kodi settings menu.

  • Settings ➔ Services ➔ UPnP / DLNA ➔ Allow remote control via UPnP

Supported Things ​

This binding provides only one Thing type: The Kodi media center. Create one Kodi Thing per Kodi instance available in your home automation system.

All Kodi devices are registered as an audio sink in openHAB.

Discovery ​

The binding supports auto-discovery for available and prepared (see above) instances of the Kodi media center on your local network. Auto-discovery is enabled by default. To disable it, you can add the following line to <openHAB-conf>/services/runtime.cfg:

text
discovery.kodi:background=false

Binding Configuration ​

The following configuration options are available for the Kodi binding:

ParameterNameDescriptionRequired
callbackUrlCallback URLURL to use for playing notification sounds, e.g. http://192.168.0.2:8080no

Thing Configuration ​

The Kodi Thing requires the IP address of the device hosting your Kodi media center instance, the TCP port to access it (default: 9090), and the HTTP port to build URLs to the Kodi web interface for downloading thumbnail and fanart images (default: 8080). You can optionally define an httpUser and an httpPassword parameter if the access to your Kodi web interface is protected. The IP address will be found by the auto-discovery feature. You can use the notificationVolume property for setting a default volume (in %) as well as a notificationTimeout (in s) to be used to play notifications.

A manual setup through a things/kodi.things file could look like this:

dsl
Thing kodi:kodi:myKodi "Kodi" @ "Living Room" [ipAddress="192.168.1.100", port=9090, httpPort=8080]

Channels ​

The Kodi Thing supports the following channels:

Channel Type IDItem TypeDescription
muteSwitchMute/unmute your playback
volumeDimmerRead or control the volume of your playback
controlPlayerControl the Kodi player, e.g. PLAY, PAUSE, NEXT, PREVIOUS, FASTFORWARD, REWIND
stopSwitchWrite ON to this channel: Stops the Kodi player. If this channel is ON, the player is stopped, otherwise Kodi is in another state (see control channel)
titleStringTitle of the currently played song/movie/tv episode
originaltitleStringTitle of the currently played song/movie/tv episode in local language
showtitleStringTitle of the currently played tv-show; empty for other types
albumStringAlbum name of the currently played song
artistStringArtist name of the currently played song or director of the currently played movie
playuriStringPlays the file with the provided URI. The URI can be amended by #timestamp=<s> where s is position in seconds at which the video should be started.
playfavoriteStringPlays or opens the favorite with the provided title (channel's state options contains available favorites)
pvr-open-tvStringOpens the PVR TV channel with the provided name (channel's state options contains available PVR TV channels)
pvr-open-radioStringOpens the PVR Radio channel with the provided name (channel's state options contains available PVR Radio channels)
pvr-channelStringTitle of the currently played PVR channel
shownotificationStringShows the provided notification message on the screen
inputStringSends a key stroke to Kodi to navigate in the UI. Valid commands are: Back, ContextMenu, Down, Home, Info, Left, Right, Select, ShowCodec, ShowOSD, ShowPlayerProcessInfo and Up. ExecuteAction and SendText should be used with the dedicated channels inputaction and inputtext.
inputtextStringSends a generic input (unicode) text to Kodi.
inputactionStringSends a predefined action to Kodi to control the UI and/or perform other tasks. Valid commands are: left, right, up, down, pageup, pagedown, select, highlight, parentdir, parentfolder, back, menu, previousmenu, info, pause, stop, skipnext, skipprevious, fullscreen, aspectratio, stepforward, stepback, bigstepforward, bigstepback, chapterorbigstepforward, chapterorbigstepback, osd, showsubtitles, nextsubtitle, cyclesubtitle, playerdebug, codecinfo, playerprocessinfo, nextpicture, previouspicture, zoomout, zoomin, playlist, queue, zoomnormal, zoomlevel1, zoomlevel2, zoomlevel3, zoomlevel4, zoomlevel5, zoomlevel6, zoomlevel7, zoomlevel8, zoomlevel9, nextcalibration, resetcalibration, analogmove, analogmovex, analogmovey, rotate, rotateccw, close, subtitledelayminus, subtitledelay, subtitledelayplus, audiodelayminus, audiodelay, audiodelayplus, subtitleshiftup, subtitleshiftdown, subtitlealign, audionextlanguage, verticalshiftup, verticalshiftdown, nextresolution, audiotoggledigital, number0, number1, number2, number3, number4, number5, number6, number7, number8, number9, smallstepback, fastforward, rewind, play, playpause, switchplayer, delete, copy, move, screenshot, rename, togglewatched, scanitem, reloadkeymaps, volumeup, volumedown, mute, backspace, scrollup, scrolldown, analogfastforward, analogrewind, moveitemup, moveitemdown, contextmenu, shift, symbols, cursorleft, cursorright, showtime, analogseekforward, analogseekback, showpreset, nextpreset, previouspreset, lockpreset, randompreset, increasevisrating, decreasevisrating, showvideomenu, enter, increaserating, decreaserating, setrating, togglefullscreen, nextscene, previousscene, nextletter, prevletter, jumpsms2, jumpsms3, jumpsms4, jumpsms5, jumpsms6, jumpsms7, jumpsms8, jumpsms9, filter, filterclear, filtersms2, filtersms3, filtersms4, filtersms5, filtersms6, filtersms7, filtersms8, filtersms9, firstpage, lastpage, guiprofile, red, green, yellow, blue, increasepar, decreasepar, volampup, volampdown, volumeamplification, createbookmark, createepisodebookmark, settingsreset, settingslevelchange, stereomode, nextstereomode, previousstereomode, togglestereomode, stereomodetomono, channelup, channeldown, previouschannelgroup, nextchannelgroup, playpvr, playpvrtv, playpvrradio, record, togglecommskip, showtimerrule, leftclick, rightclick, middleclick, doubleclick, longclick, wheelup, wheeldown, mousedrag, mousemove, tap, longpress, pangesture, zoomgesture, rotategesture, swipeleft, swiperight, swipeup, swipedown, error, noop.
inputbuttoneventStringSend a button press event. The parameter can have the format "<button>", "<button>;<keymap>" or "<button>;<keymap>;<holdtime>". For details see https://kodi.wiki/view/JSON-RPC_API/v12#Input.ButtonEvent
inputrequestedSwitchIndicates whether Kodi is currently asking the user for input
screensaverSwitchCurrent state of the Screensaver
systemcommandStringThis channel allows to send system commands to Shutdown, Suspend, Hibernate, Reboot or Quit Kodi (channel's state options contains available system commands)
mediatypeStringThe media type of the current file. Valid return values are: unknown, channel, episode, movie, musicvideo, picture, radio, song, video
mediaidNumberThe media_id in database of Kodi
mediafileStringFull path and file name of the current file
uniqueid-imdbStringIMDB link ID of currently playing media (Advanced)
uniqueid-tmdbStringTheMovieDB link ID of currently playing media (Advanced)
uniqueid-doubanStringDouban link ID of currently playing media (Advanced)
uniqueid-imdbtvshowStringIMDB link ID of the season of currently playing tv episode (Advanced)
uniqueid-tmdbtvshowStringIMDB link ID of the season of currently playing tv episode (Advanced)
uniqueid-tmdbepisodeStringIMDB link ID of single episode of currently playing tv episode (Advanced)
seasonNumberSeason number if currently playing tv episode
episodeNumberEpisode number if currently playing tv episode
genreListStringA comma-separated list of genres of the current file
thumbnailImageThe URL to the thumbnail of the current file
fanartImageThe URL to the fanart of the current file
playnotificationStringPlays the notification sound by a given URI
subtitle-enabledSwitchDisplay/hide subtitle
subtitle-indexNumberSet or get subtitle index of currently playing media
subtitle-languageStringDisplay subtitle language of currently playing media
subtitle-nameStringDisplay subtitle title of currently playing media
audio-indexNumberAudio stream index of currently playing media
audio-codecStringAudio codec of currently playing media (Advanced)
audio-languageStringDisplay language of currently playing audio stream (Advanced)
audio-nameStringDisplay title of currently playing audio stream (Advanced)
audio-channelsNumberDisplay channels of currently playing audio stream (Advanced)
video-codecStringVideo codec of currently playing media (Advanced)
video-indexNumberIndex of currently playing multi stream video (Advanced)
video-heightNumberHeight of currently playing video (Advanced)
video-weightNumberWidth of currently playing video (Advanced)
currenttimeNumber:TimeCurrent time of currently playing media
currenttimepercentageNumber:DimensionlessCurrent time of currently playing media
durationNumber:TimeLength of currently playing media
ratingNumberrating of currently playing media (Advanced)
mpaaStringMPAA rating of currently playing media (Advanced)
userratingNumberpersonal rating of currently playing media (Advanced)
profileStringCurrent profile (Advanced)

Kodi things are extensible by channels of type shownotification, so that different notification pop-ups can be configured for different use cases.

Channel Configuration ​

group The PVR channels can be put into user-defined PVR channel groups. There are two default PVR channel groups. One for PVR TV channels and one for PVR radio channels. The default labels are "All channels" (in German systems "Alle Kanäle"). You have to adjust this configuration to use the pvr-open-tv and pvr-open-radio channels properly. You can optionally configure an user-defined PVR channel group. The PVR channels from Kodi will be populated during runtime into the state options of the pvr-open-tv and pvr-open-radio channels.

shownotification The shownotification channel type has three configuration parameters through which it can be customized:

ParameterTypeDefaultDescription
titleTextopenHABTitle of the notification
displayTimeInteger5000Time the notification is shown (in ms)
iconTextIcon to use (e.g. "alarm"). One of the openHAB icons (as listed in the openHAB Classic iconset documentation).

Audio Support ​

All Kodi instances are registered as an audio sink in the framework. Audio streams are sent to the playnotification channel and will change the volume of the audio sink using the notificationVolume defined in the properties for the Thing, not the volume.

URL audio streams (e.g. an Internet radio stream) are an exception and do not get sent to the playnotification channel. Instead, these will be sent to the playuri channel.

Full Example ​

A manual setup through a things/kodi.things file could look like this:

dsl
Thing kodi:kodi:myKodi "Kodi" @ "Living Room" [ipAddress="192.168.1.100", port=9090] {
    Channels:
        Type pvr-open-tv : pvr-open-tv [
            group="All channels"
        ]
        Type shownotification : error-notification [
            title="openHAB - Error",
            icon="error"
        ]
        Type shownotification : weather-notification [
            title="openHAB - Weather",
            icon="sun_clouds"
        ]
}

Item Configuration ​

demo.items

dsl
Switch myKodi_mute                  "Mute"                      { channel="kodi:kodi:myKodi:mute" }
Dimmer myKodi_volume                "Volume [%d]"               { channel="kodi:kodi:myKodi:volume" }
Player myKodi_control               "Control"                   { channel="kodi:kodi:myKodi:control" }
Switch myKodi_stop                  "Stop"                      { channel="kodi:kodi:myKodi:stop" }
String myKodi_title                 "Title [%s]"                { channel="kodi:kodi:myKodi:title" }
String myKodi_showtitle             "Show title [%s]"           { channel="kodi:kodi:myKodi:showtitle" }
String myKodi_album                 "Album [%s]"                { channel="kodi:kodi:myKodi:album" }
String myKodi_artist                "Artist [%s]"               { channel="kodi:kodi:myKodi:artist" }
String myKodi_playuri               "Play URI"                  { channel="kodi:kodi:myKodi:playuri" }
String myKodi_playfavorite          "Play favorite"             { channel="kodi:kodi:myKodi:playfavorite" }
String myKodi_pvropentv             "Play PVR TV channel"       { channel="kodi:kodi:myKodi:pvr-open-tv" }
String myKodi_pvropenradio          "Play PVR Radio channel"    { channel="kodi:kodi:myKodi:pvr-open-radio" }
String myKodi_pvrchannel            "PVR channel [%s]"          { channel="kodi:kodi:myKodi:pvr-channel" }
String myKodi_notification          "Notification"              { channel="kodi:kodi:myKodi:shownotification" }
String myKodi_error-notification    "Error Notification"        { channel="kodi:kodi:myKodi:error-notification" }
String myKodi_weather-notification  "Weather Notification"      { channel="kodi:kodi:myKodi:weather-notification" }
String myKodi_input                 "Input"                     { channel="kodi:kodi:myKodi:input" }
String myKodi_inputtext             "Inputtext"                 { channel="kodi:kodi:myKodi:inputtext" }
String myKodi_systemcommand         "Systemcommand"             { channel="kodi:kodi:myKodi:systemcommand" }
String myKodi_mediatype             "Mediatype [%s]"            { channel="kodi:kodi:myKodi:mediatype" }
String myKodi_genrelist             "Genres [%s]"               { channel="kodi:kodi:myKodi:genreList" }
Image  myKodi_thumbnail                                         { channel="kodi:kodi:myKodi:thumbnail" }
Image  myKodi_fanart                                            { channel="kodi:kodi:myKodi:fanart" }
Number:Time myKodi_currenttime      "Current Time [%d %unit%]"  { channel="kodi:kodi:myKodi:currenttime" }
Number:Dimensionless myKodi_ctp     "Current Time [%d %unit%]"  { channel="kodi:kodi:myKodi:currenttimepercentage" }
Number:Time myKodi_duration         "Duration [%d %unit%]"      { channel="kodi:kodi:myKodi:duration" }
String myKodi_playnotification      "Play notification URI"     { channel="kodi:kodi:myKodi:playnotification" }

Sitemap Configuration ​

demo.sitemap

dsl
sitemap demo label="myKodi"
{
    Frame label="myKodi" {
        Switch    item=myKodi_mute
        Slider    item=myKodi_volume
        Selection item=myKodi_control mappings=[PLAY='Play', PAUSE='Pause', NEXT='Next', PREVIOUS='Previous', FASTFORWARD='Fastforward', REWIND='Rewind']
        Default   item=myKodi_control
        Switch    item=myKodi_stop
        Text      item=myKodi_title
        Text      item=myKodi_showtitle
        Text      item=myKodi_album
        Text      item=myKodi_artist
        Selection item=myKodi_pvropentv
        Selection item=myKodi_pvropenchannel
        Text      item=myKodi_pvrchannel
        Selection item=myKodi_input mappings=[Up='Up', Down='Down', Left='Left', Right='Right', Select='Select', Back='Back', Home='Home', ContextMenu='ContextMenu', Info='Info']
        Selection item=myKodi_systemcommand
        Text      item=myKodi_mediatype
        Text      item=myKodi_genrelist
        Image     item=myKodi_thumbnail
        Image     item=myKodi_fanart
        Text      item=myKodi_currenttime
        Text      item=myKodi_ctp
        Text      item=myKodi_duration
    }
}