Select Page
This entry has been published on 2016-05-23 and may be out of date.

Last Updated on 2016-05-23.

[:en]In a smart home environment, you may want to send various notifications to every active OE / Kodi station, e.g. a “garage door is open” information at night.

This information might come from any source like KNX server or similar.

To open a popup window in Kodi, you can e.g. use a Ubuntu Server with PHP and Apache in your LAN, with the following code:

<?
//Send Notifications to Kodi

$title=$_GET['title'];
$message=$_GET['message'];

$openelecStations = array(
    '10.1.0.90',
    '10.1.0.91',
    '10.1.0.92',
    '10.1.0.93',
    '10.1.0.94',
    '10.1.0.95' 
);

function curl_request($url)
{
    $ch = curl_init($url);
    curl_setopt($ch ,CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
    curl_exec($ch);
    curl_close($ch);
}

$jsonParams = array(
    'title' => utf8_encode($title),
    'message' => utf8_encode($message),
    'displaytime' => 30000    
);

$jsonData = array(
    'jsonrpc' => '2.0',
    'method' => 'GUI.ShowNotification',
    'params' => $jsonParams,
    'id' => 1
);

 
$jsonStr = urlencode(json_encode($jsonData));

foreach($openelecStations as $oe)
{
    curl_request("http://".$oe."/jsonrpc?request=".$jsonStr);
}

?>

The script accepts title and message parameters with special characters, e.g. German Umlaute.

Call it e.g. from your KNX server like:

$title='meow';
$message='close your garage door';

file_get_contents("http://toolsserver/notify_kodi.php?title=".rawurlencode($title)."&message=".rawurlencode($text));

Note the example is written in PHP again but of course, it depends on what your source server supports. Always make sure title and text values are encoded in common URL format when using special characters.[:]