Kodi
Documentation for Kodi Media Player.
Introduction
Kodi™ (formerly known as XBMC™) is an award-winning free and open source (GPL) software media center for playing videos, music, pictures, games, and more. Kodi runs on Linux, OS X, Windows, iOS, and Android, featuring a 10-foot user interface for use with televisions and remote controls. 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.
For more details go to the Kodi site here - http://kodi.tv/about/
On Screen Notifications
Domoticz can display notification messages on screens linked to Kodi Media Players. Notifications will work even if Kodi has not been added as a hardware type and no Kodi devices have been defined.
Your Kodi media Player must be configured to allow control by remote programs. To see where to do this using the default Confluence skin see: Allow Remote Control.
This is configured via the Notifications tab on the Settings page as shown here:
The default setting should work for almost everyone on a home network. 224.0.0.1 is a multicast address so the message will be sent to the whole local network. Port 9777 is a special port on Kodi Media Players to listen for these broadcasts so always try these settings first. If the messages don't appear, bump the number of 'hops' to any number less than 20.
For Kodis that still don't get messages, or are not on your local network, semicolon delimited IP addresses can be specified.
If you want to send notifications to Kodi outside of the formal Domoticz stream you can do something along the lines of this in bash:
#! /bin/bash
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Domoticz","message":"Hall PIR detected motion !"},"id":1}' http://192.168.178.5:80/jsonrpc
or from perl using
#!/usr/bin/perl
use LWP::UserAgent;
use Net::Ping;
no warnings 'uninitialized';
$kodi_url = '192.168.178.5';
$ua=LWP::UserAgent->new; $ua->timeout(5);
$p = Net::Ping->new();
$alive = ($p->ping($kodi_url, 2));
if ($alive) {
$title='Garage Door';
$message='Open for > 10 mins !';
$res=$ua->get("http://$kodi_url/jsonrpc?request={\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"GUI.ShowNotification\",\"params\":{\"title\":\"$title\",\"message\":\"$message\"}}");
unless ($res->is_success) { warn $res->status_line };
}
Kodi in Domoticz
Kodi Settings
Your Kodi media Player must be configured to allow control by remote programs to work with Domoticz. To see where to do this using the default Confluence skin see: Allow Remote Control.
By default Kodi exposes an asynchronous interface on port 9090 in addition to the web server it runs on 80 or 8080. If required, it can be changed by updating the underlying XML configuration, details are here Override Default Port but this should not be required.
Do not change any of these web server settings in an attempt to make this plugin work. It does not use the Kodi Webserver so it will make no difference.
Adding Hardware
Add the Kodi Media Player via the Hardware page under Settings:
Domoticz Settings
Click 'Setup' and the add individual devices.
- Poll interval controls how often Domoticz will attempt to reconnect to a Kodi that it has lost contact with.
- Ping timeout controls how many missed pings (sent once per Poll Interval) can be missed before a Kodi is consider 'Off'. For backwards compatibility, if the number specified is greater than 1000 it will be divided by 1000. Recommended value is 2 or 3.
The port specified needs to match the port confingured on the Kodi itself, see below for detail
Unless you have explicitly made port changes to your Kodi as described below, just use the default 9090 port number. Once you have saved your changes check the log and you should see something similar to this:
2015-09-25 09:44:44.962 Kodi: (Lounge) Connected. |
Note that this message will be shown if Domoticz attaches to any valid port! To check it is functioning correctly, play some media as you normally would and you should see somthing similar to this if you play then stop some music:
2015-09-25 10:01:11.699 Kodi: (Lounge) Event: 'Audio - Coldplay (A Rush Of Blood To The Head), The Scientist (2002)'. |
2015-09-25 10:01:18.483 Kodi: (Lounge) Event: 'On'. |
if you see the connection message but no activity you have connected to the wrong port.
If you want to use custom Kodi icons there is a set here: Custom Icons. Just upload them via the Custom Icon page under settings then Edit the devices from the 'Switches' tab select the icons from the list.
Troubleshooting
If you are having issues, go back to the device set up page (under Hardware) and make the port number negative for your kodi, this will turn on debug mode for the device. e.g if using the default port 9090, make the port -9090 and your log will be spammed with messages.
Connection to the correct port will show results similar to:
2015-10-03 13:03:02.429 Kodi: (Lounge) Connected to '192.168.37.127:-9090'. |
2015-10-03 13:03:02.430 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"System.GetProperties","params":{"properties":["canhibernate","cansuspend","canshutdown"]},"id":7}' |
2015-10-03 13:03:02.565 Kodi: (Lounge) Parsing data: '{"id":7,"jsonrpc":"2.0","result":{"canhibernate":false,"canshutdown":false,"cansuspend":false}}'. |
2015-10-03 13:03:02.567 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":5}' |
2015-10-03 13:03:02.570 Kodi: (Lounge) Parsing data: '{"id":5,"jsonrpc":"2.0","result":[]}'. |
2015-10-03 13:03:03.459 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"JSONRPC.Ping","id":1}' |
2015-10-03 13:03:03.463 Kodi: (Lounge) Parsing data: '{"id":1,"jsonrpc":"2.0","result":"pong"}'. |
Connecting to an incorrect (but active) port will show:
2015-10-03 13:07:10.882 Kodi: (Lounge) Connected to '192.168.0.246:-8080'. |
2015-10-03 13:07:10.883 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"System.GetProperties","params":{"properties":["canhibernate","cansuspend","canshutdown"]},"id":7}' |
2015-10-03 13:07:11.919 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"JSONRPC.Ping","id":1}' |
2015-10-03 13:07:22.420 Kodi: (Lounge) Sending data: '{"jsonrpc":"2.0","method":"JSONRPC.Ping","id":1}' |
2015-10-03 13:07:32.920 Kodi: (Lounge) Missed 1 pings, assumed off. |
2015-10-03 13:07:32.956 Kodi: (Lounge) Event: 'Off'. |
2015-10-03 13:07:32.985 Kodi: (Lounge) Disonnected. |
Always post this log output into forum requests for assistance.
Events and Notifications
Domoticz device events work for Kodi using both Blockly and lua.
Events and notifications are triggered for:
On | When the device is turned on (network connection established) or returns to an idle state. |
Off | When the device is turned off or network connectivity is lost. |
Video | When the device starts streaming Live TV, TV Shows or Movies. |
Audio | When the device starts streaming Music. |
Photo | When the device starts showing an image. |
Pause | When the device is streaming media and is paused. |
The following actions can be performed by using 'Set' on a Kodi.
Off or Group Off | Will turn the device off if this is supported in settings on the device. |
Stop | Will send a Stop command, only effective if the device is streaming. |
Play | Will send a Play command, only effective if the device was streaming and has been paused. |
Pause | Will send a Pause command, only effective if the device is streaming. |
Set Volume <0-100> | Will set the volume of the player-output. |
Play Playlist <name> <position> | Will play a music or video Smart Playlist with name <name> optionally starting at position <position>. Playlist positions start from 0 which is the default. |
Play Favorites <position> | Will play an item from the Kodi's Favorites list optionally starting at position <position>. Favorite positions start from 0 which is the default. |
Execute <addonid> | Will send an Execute Addon command sending no parameters. Addon IDs are embedded in the addon configuration and are not to be confused with the Addon Name. For example: http://forums.homeseer.com/showthread.php?p=1213403 |
Lua example:
commandArray['Lounge']='Off'
commandArray['Lounge']='Off AFTER 30'
commandArray['Lounge']='Pause'
commandArray['Lounge']='Set Volume 30'
commandArray['Lounge']='Play Playlist Indierock'
commandArray['Lounge']='Play Playlist ActionMovies 15'
commandArray['Lounge']='Play Favorites'
commandArray['Lounge']='Play Favorites 3'
commandArray['Lounge']='Execute script.securitycam'
JSON
Kodi has support for JSON
This can be used in many fun things, for example my television can not do audio passthrough but my receiver can. So detecting that using a CEC script, or an alive ping on both devices (red. reference here) and setting the audio passthrough in Kodi. Makes that switching inputs from my receiver to my TV also enables audio (instead of silence)!
Philips HUE (No Longer Maintained)
Kodi has Philips HUE support
The latest version can be downloaded at this location [1], remember to exclude that lamp from your scences (like group all off).
CEC
CEC can be used to switch your input, set your volume or even get your TV out of standby. Kodi has a build in support for CEC with more infomation in CEC and the Kodi Wiki
OpenElec/LibreElec
Remote control is disabled by default (for security reasons) so Domoticz won't be able to connect until it is enabled in Control Settings on the Kodi :
On OpenElec or LibreElec, you MAY need to add a few lines to your advanced settings xml file...try it first and only do this if it does not work
If you dont know how to do that, check this out : http://kodi.wiki/view/advancedsettings.xml
Once you have your head around that, you need to add these lines :
<jsonrpc>
<tcpport>9090</tcpport>
</jsonrpc>