Control ZiggoHorizon

From Domoticz
Jump to: navigation, search

Purpose

With this script you can control a Ziggo Horizon mediabox that is connected to your local network. It contains two scripts, one for gettnig the status and one for setting the status.

Getting the status

For this script you need to have installed PHP.

Create a new file. I've put it in my /scripts folder and called it check_upc.php. Copy the contents from the script on this page to the file you just created, and save the file.

#!/usr/bin/php
<?php
ini_set('error_reporting', E_ALL);

$localip = "192.168.192.100"; // IP of your Ziggo mediabox
$localport = "62137"; // Local port

$domoticz_ip = "127.0.0.1"; // IP of domoticz
$domoticz_port = "8084"; // Portnumber of domoticz
$domoticz_sensor_idx = "24"; // Switch-ID for a virtual status switch (on/off)

$data = file_get_contents("http://$localip:$localport/DeviceDescription.xml");
if (!empty($data))
{
    $status = "1&svalue=On";
}
else
{
    $status = "0&svalue=Off";
}

echo file_get_contents("http://$domoticz_ip:$domoticz_port/json.htm?type=command&param=udevice&idx=$domoticz_sensor_idx&switchcmd=$status");
?>

Instructions for usage

Make the script executable (chmod +777) and call this script from a cronjob. I call it every 10 minutes, but that's your own choice. Example: */10 * * * * root /volume1/@appstore/domoticz/var/scripts/check_upc.php

Setting the status

I only use it to toggle the power of the mediabox, but other keys are also possible.

Create a new file. I've put it in my /scripts folder and called it switch_upc.php. Copy the contents from the script on this page to the file you just created, and save the file.

#!/usr/bin/php
<?php
/*
Script (C) KixAss 2016 - [email protected]

Possible keys:
KEY_POWER		= E0 00
KEY_OK 			= E0 01
KEY_BACK 		= E0 02
KEY_CHAN_UP		= E0 06
KEY_CHAN_DWN	= E0 07
KEY_HELP		= E0 09
KEY_MENU		= E0 0a
KEY_GUIDE		= E0 0b
KEY_INFO		= E0 0e
KEY_TEXT		= E0 0f
KEY_MENU1		= E0 11
KEY_MENU2		= E0 15
KEY_DPAD_UP		= E1 00
KEY_DPAD_DOWN	= E1 01
KEY_DPAD_LEFT	= E1 02
KEY_DPAD_RIGHT	= E1 03
KEY_NUM_0		= E3 00
KEY_NUM_1		= E3 01
KEY_NUM_2		= E3 02
KEY_NUM_3		= E3 03
KEY_NUM_4		= E3 04
KEY_NUM_5		= E3 05
KEY_NUM_6		= E3 06
KEY_NUM_7		= E3 07
KEY_NUM_8		= E3 08
KEY_NUM_9		= E3 09
KEY_PAUSE		= E4 00
KEY_STOP		= E4 02
KEY_RECORD		= E4 03
KEY_FWD			= E4 05
KEY_RWD			= E4 07
KEY_MENU3		= Ef 00
KEY_UNKNOWN_0 	= Ef 06;	// TIMESHIFT INF
KEY_UNKNOWN_1	= Ef 15;	// POWE
KEY_UNKNOWN_2	= Ef 16;	// N
KEY_UNKNOWN_3	= Ef 17;	// RC PAIRIN
KEY_UNKNOWN_4	= Ef 19;	// TIMIN
KEY_ONDEMAND	= Ef 28
KEY_DVR 		= Ef 29
KEY_TV = Ef 2a;
*/

function makeBuffer($data)
{
    $data = str_replace(" ", "", $data);
    return hex2bin($data);
}


$localip = "192.168.192.100"; // IP of mediabox
$localport = 5900; // Controlport of mediabox
$key = "E0 00"; // Power toggle

if ($sock = fsockopen($localip, $localport))
{
    $data = fgets($sock); // readVersionMsg
    echo "recv version: " . $data . "<br>";

    echo "-----------------------------<br>";

    fwrite($sock, $data); // Send the same version back

    $data = fgets($sock, 2); // Get OKE
    echo "recv: " . $data . "<br>";

    echo "-----------------------------<br>";

    fwrite($sock, makeBuffer("01")); // Send Authorization type (none)

    $data = fgets($sock, 4); // Get OKE
    echo "recv: " . $data . "<br>";

    echo "-----------------------------<br>";

    $data = fgets($sock, 24); // Get init data
    echo "recv: " . $data . "<br>";
	
    fwrite($sock, makeBuffer("04 01 00 00 00 00 " . $key)); // Turn key on
    usleep(400);
    fwrite($sock, makeBuffer("04 00 00 00 00 00 " . $key)); // Turn key off

    fclose($sock);
}
?>

Instructions for usage

In the virtual switch, add the script to the on and off action:

script:///volume1/@appstore/domoticz/var/scripts/switch_upc.php