This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.
Closed Solved

Control Horizon Ziggo

2

Comments

  • mauricebmauriceb Member
    edited September 2016
    jorden said:
    That OpenHab thing looks useful, although I'm not familiar with OpenHab and it might be hard to get the code out of that massive package.

    I'm not currently at home, but can someone turn on their Horizon, find it's IP-address in the network and then try to open this?
    http://<IP>:62137/DeviceDescription.xml

    Just wondering if that still works...
    @jorden This works for perfectly at least with one of the two address my Horizon Box has.

    See the attachment for the result.

    Looks like the dlna control settings. I also see these for my TV. Wouldn't it be simple if someone made a dlna app? Then every dlna device would become controllable by Homey without the need for having an app fore very dlna device.
  • msmitsmsmits Member
    edited September 2016
    mauriceb said:
    jorden said:
    That OpenHab thing looks useful, although I'm not familiar with OpenHab and it might be hard to get the code out of that massive package.

    I'm not currently at home, but can someone turn on their Horizon, find it's IP-address in the network and then try to open this?
    http://<IP>:62137/DeviceDescription.xml

    Just wondering if that still works...
    @jorden This works for perfectly at least with one of the two address my Horizon Box has.

    See the attachment for the result.

    Looks like the dlna control settings. I also see these for my TV. Wouldn't it be simple if someone made a dlna app? Then every dlna device would become controllable by Homey without the need for having an app fore very dlna device.
    How did you get this? Just bij typing in the webbrowser? I think i have a other model since this isn't working on mine.
    Did you used the IPV4 address of the gateway address?

    wget --server-response --spider http://192.168.1.27:62137/DeviceDescription.xml
    Spider mode enabled. Check if remote file exists.
    Connecting to 192.168.1.27:62137... failed: Connection refused.


    EDIT:

    Script is finished, need to finetune the adb commands a little bit more.

    This weekend i will post a video of how its working! :smile: 



  • msmitsmsmits Member
    edited September 2016
    Hi guys,

    First test today, i've been able to script it on a emulator, so you dont need a phone anymore to run this.

    Here is a short video of it



    For now its not very fast with turning it on and off but its the first version! :smiley: 

    Ps sorry of the sound, its because of the wind.
  • Great work!!!
    Looking forward to all the possibilities!

  • msmits said:
    mauriceb said:
    jorden said:
    That OpenHab thing looks useful, although I'm not familiar with OpenHab and it might be hard to get the code out of that massive package.

    I'm not currently at home, but can someone turn on their Horizon, find it's IP-address in the network and then try to open this?
    http://<IP>:62137/DeviceDescription.xml

    Just wondering if that still works...
    @jorden This works for perfectly at least with one of the two address my Horizon Box has.

    See the attachment for the result.

    Looks like the dlna control settings. I also see these for my TV. Wouldn't it be simple if someone made a dlna app? Then every dlna device would become controllable by Homey without the need for having an app fore very dlna device.
    How did you get this? Just bij typing in the webbrowser? I think i have a other model since this isn't working on mine.
    Did you used the IPV4 address of the gateway address?

    wget --server-response --spider http://192.168.1.27:62137/DeviceDescription.xml
    Spider mode enabled. Check if remote file exists.
    Connecting to 192.168.1.27:62137... failed: Connection refused.


    EDIT:

    Script is finished, need to finetune the adb commands a little bit more.

    This weekend i will post a video of how its working! :smile: 



    @msmits I used the non gateway IP-address. The gateway address is none responsive.
  • mauricebmauriceb Member
    edited September 2016
    msmits said:
    Hi guys,

    First ... wind.
    @msmits Nice work!
  • @msmits Quite nice!
  • Are there plans to create an Homey app for this?
  • You can control the box directly via this script:

    <?php
    /*
    Script (C) KixAss 2016 - horizon@kixass.net

    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";
    $localport = 5900;
    $key = "E0 00"; // Power toggle


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

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

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

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

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

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

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

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

    $data = fgets($sock, 24); // Get init data
    echo "recv: " . $data . "<br>";
    echo "recv: " . makeBuffer2($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);
    }
    ?>



  • jordenjorden Member
    edited November 2016
    @KixAss wow, that actually works! Even though your script uses a function makeBuffer and makes calls to both makeBuffer2 and makeBuffer... but there is no function makeBuffer2. But I found that that function is doing the opposite (bin2hex instead of hex2bin) so made it work.

    But I will try to convert this into an app!
  • Does this also work for the mediabox? 
  • jorden said:
    @KixAss wow, that actually works! Even though your script uses a function makeBuffer and makes calls to both makeBuffer2 and makeBuffer... but there is no function makeBuffer2. But I found that that function is doing the opposite (bin2hex instead of hex2bin) so made it work.

    But I will try to convert this into an app!
    That would be great!!
  • I am currently experimenting with using Homey to send commands to the box and the correct order of it. The PHP example of @KixAss really helps a lot for this. However, I am having a little trouble to convert the output of the box to correct data.

    Just a little trouble though, I have no doubt that I can make this work and will even release a simple app shortly :)
  • would love that!
  • I placed my work so far at https://github.com/jordenc/tv.horizon.ziggo

    It is not working yet. This is mostly because I am not fully sure what I'm doing (no "official" documentation, and the file itself is barely documented ;)) and it's kinda hard to find out if I'm doing exactly the same as the PHP file (Which I guess I'm not, since it's not working).

    The process seems to be the following:
    1- Open a connection
    2- Receive first data from the box, containing its version info (buffer = [82,70,66,32,48,48,51,46,48,48,56,10])
    3- Send the version info to the box.
    4- Receive an OK message from the box (buffer = [1,1])
    5- Return hex2bin 01, meaning "Authorisation type: none"
    6- Receive an OK message from the box (buffer = [0,0,0,0] ????)
    7- Receive INIT data (buffer = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ????)

    So far it seems to be okay, but I'm not 100% sure.
    8- Send the "key on" button
    9- Send the "key off" button
    10- Close the connection.

    8 and 9 are not doing anything for me, sadly.

    I must be doing something wrong, possibly in steps 5, 7, or 8. I checked with the PHP script and the same "à" in ISO-8859-1 appears as in Homey when I send the INFO key in step 8.
    I am not so experienced with the Buffers that NodeJS generates here so it's all a big test for me.
  • It's some kind of strange VNC-protocol adaption. I've got this script since 2013 but it didn't work for a while. After changing some small timing-things it works again. 
  • jordenjorden Member
    edited November 2016
    I encourage everybody with javascript skills to try out the script on github and see if they can fix what I did wrong...

    @KixAss is there a function makeBuffer2 that you can post as well? Not sure if it helps any but at least then the PHP script is complete :)
  • It's just the other way around ;-)


    function makeBuffer2($data)
    {
    return bin2hex($data);
    }

  • OK, I thought so, already did that so no secrets in there :)
  • jorden said:
    I encourage everybody with javascript skills to try out the script on github and see if they can fix what I did wrong...

    @KixAss is there a function makeBuffer2 that you can post as well? Not sure if it helps any but at least then the PHP script is complete :)
    Do you get any errors? I see some code styling issues in driver.js but no real problems.

    In the hex2bin function you miss some ; chars after lines of code.

    And it would be nice to have 1 type of defining functions. With:

    var varname = function()
    Or
    function varname()

    But you are using them both.

    I have no experience creating apps for homey, and do not own the ziggo box.

    Good luck, hope you'll find the issue. If i can help you let me know.
  • Is data available in the next function?

    function sendCommand (cmd, hostIP, callback, substring) {
    It seems the callback isnt used bit maybe this is the way the system works?
    
    
  • The following is what I get, I get a socket closed error ?

    Horizon app - sending E100 to x.x.x.209
    buffer = [82,70,66,32,48,48,51,46,48,48,56,10]
    Received version message, returning it.
    buffer = [1,1]
    received OK message, returning it.
    buffer = [0,0,0,0]
    received AUTH OK message
    buffer = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    Received init data
    sending: 040100000000E100
    sending: ♦☺    á
    Error: read ECONNRESET
    Connection closed
    turn key off
    Error: This socket is closed.

    ... 
    any ideas?
  • @NPeters the problem is not the javascript I think. It's the problem that the connection closes halfway. Which might be due to something I do wrong in communicating with the Horizon box... something that happens differently from what happens in PHP.
    I'm not done with the complete app yet, just got the basics up, so callbacks and such are not yet used.

    @MarcoWijk that's also what I get.

    There must be some error in that hex2bin function I guess, although it seems to be output the correct chars compared to PHP...
  • jorden said:
    @NPeters the problem is not the javascript I think. It's the problem that the connection closes halfway. Which might be due to something I do wrong in communicating with the Horizon box... something that happens differently from what happens in PHP.
    I'm not done with the complete app yet, just got the basics up, so callbacks and such are not yet used.

    @MarcoWijk that's also what I get.

    There must be some error in that hex2bin function I guess, although it seems to be output the correct chars compared to PHP...
    I cannot test it, but is the following correct?

    String.fromCharCode.apply(String, ret)}
    
    "String" is not set in that function?
  • No wonder it doesn't work. It doesn't connect. The first response/data I get from 'client.connect(5900, hostIP);' Is a RFB 003.008 error, all the buffers after that are 'empty' responses. Because the 'expected' responses are as defined in the driver.js it looks like it's doing something, yet it doesn't because it isn't connecting in the first place. 

    Configuring my router didn't help. I'm not sure if it's a Horizon problem or a Homey problem, or even a firewall Horizon-problem. 

    The Horizon-app in playstore does have a remote integrated, perhaps there is a workaround inthere? It's a remote via a network connection, probably via a cloud, but still a remote using a available network.
  • Maybe projects like this will help...

     https://github.com/rogro82/HorizonRemote
    As the author of this app i can confirm you can ( or atleast could ) control the Horizon using headless/windowless vnc.. I no longer use my Horizon box else I would be able to test some stuff, but it shouldnt be too hard for someone else to write a simple app as long as the keycodes are still the same ( scanning those was the most work back then ).
  • FloodnlFloodnl Member
    @Jorden  Would it be possible to put an Alpha on the App store of homey  so the stable version ppl could turn the box on and off? the key pressing is nice for letting homey switch to an important program you don't want to miss but doub that i will use it a lot but awsone job guys so far.    

    PS   i would buy you some beers for the hassle to put it up the store. 
  • jordenjorden Member
    @Floodnl I would first have to get it working so that the Horizon box reacts, which it doesn't at the moment (not from NodeJS, that Homey is based on, only reacts to the PHP script that I tried to convert to Javascript). So I am still doing something wrong. Will have to look at it at a later time.
  • FloodnlFloodnl Member
    edited May 2017
    jorden said:
    @Floodnl I would first have to get it working so that the Horizon box reacts, which it doesn't at the moment (not from NodeJS, that Homey is based on, only reacts to the PHP script that I tried to convert to Javascript). So I am still doing something wrong. Will have to look at it at a later time.
    Understandable ofcourse, i hope you manage to find the issue good luck :) 
    And thanks for all your efforst already spend
This discussion has been closed.