Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

VD programming question


Fodder1
 Share

Question

Hi Everyone.

 

So, firstly a bit of background.

 

I am playing with improving the current SONY TV control.

Currently there is only one working control and that is the current VD, but there is a PLUGIN that doesn't work for the newer Android tv's

 

So after a lot of head scratching and googling i have figured that the Sony TV has a REST API that can be connected to with a HTTP request.

The Sony actually has three ways to control it IRCC (IR codes over IP), Serial and REST API. the current VD uses IRCC and cant go directly to say HDMI3 or an app you have installed.

 

This is where the REST API is far better. I have figured out the syntax for the HTTP call to get it work with the help of a program called POSTMAN and i can do all sorts of control.

 

End background.....

 

But here is where i am falling short, the trick with the HTTP string is in the header  (it must be in the header AFAIK) it needs to have, at least:

Header

KEY = x-auth-psk

Value = 0000

KEY = host

Value = 192.168.1.12 (IP of the originating unit)

in the body you send (no quotes)

"{"method":"setPowerStatus","version":"1.0","id":1,"params":[{"status":true}]}"

 

That will turn the TV on.

 

So playing with a few other Virtual Drivers for other integration I somewhat understand the GET command.

(this is from the "control by web" web relay driver)

GET /state.xml?relay1State=1&noReply=1 HTTP/1.1 0x0D0x0A0x0D0x0A

 

So i understand the GET part of the statement, but then i run into the HTTP/1.1 part.

I cant find anything that explains the HTTP/1.1 and what it needs what options it has and how I need to use it.

For instance, why does it need a HEX string that says (no quotes) 'Carriage return 'newline' 'carriage return 'new line' 

 

So can anyone point me at the correct learning section or help me out with a command that can integrate

x-auth-psk as the key and 000 as the value  into the header of a HTTP request?

 

That command will just turn the TV on, but you can string them together.

Why? Imagine this: while sitting on you couch watching TV, your CCTV/IPC NVR closes one of its alarm contacts on say motion detection.

I would like to know that there is motion on my security cameras while i am at home......

 

So a scene could be run in combination with the Virtual Driver to:

 

Test if the TV power is on.

Test if the PLEX or NETFLICK app is running

Record current state

Pause current state ( ie pause video or movie)

Change the input to HDMI3 (to view the cameras directly from the NVR output.)

wait till alarm is cleared (lets say motion)

return to Plex or netflicks

 

All of that would very VERY hard to do with IR codes.

 

 

Fodder.

 

 

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Ok,

    No takers on the way to get the items into the header.

     

    Can anyone point me to information on the GET command?

     

    Fod.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @AutoFrank & @Sankotronic

    I have just been reading and installing a few of your VD's and wondered if you could point me in the right direction?

    i just cant figure out how to add the those options to the header. Do you know where i can find out about the HTTP/1.1 umm options? i dont know what else to call it.

    (since writing the first post i am fairly sure that " 0x0D0x0A0x0D0x0A  " is BASE64 encoded password.)

     

     

    fodder.

     

    Link to comment
    Share on other sites

    • 0
    On 10/4/2019 at 7:51 AM, Fodder1 said:

    @AutoFrank & @Sankotronic

    I have just been reading and installing a few of your VD's and wondered if you could point me in the right direction?

    i just cant figure out how to add the those options to the header. Do you know where i can find out about the HTTP/1.1 umm options? i dont know what else to call it.

    (since writing the first post i am fairly sure that " 0x0D0x0A0x0D0x0A  " is BASE64 encoded password.)

     

     

    fodder.

     

    Hey Fodder! Have you solved it? Another here with Bravia Oled TV (Android TV). I am interested to help and test your works. Thanks!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi @dimae

    actually I think I might have. I am still in the testing phase unfortunately. I have had a few setbacks like a divorce and a broken lan port on my testing TV. 
    that has arrived back from repair and I will be testing again soon.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Please login or register to see this image.

    Hi All,

     

     

    Sorry its been a while, but I life got in the way.

    I think i have the answer but i cant make it work!

     

    So after a lot a searching I think I have found the answer. Now being that  am very NOOB programmer I need a little bit of help here.

    After downloading eversearching through every VD in the market place i found one that gave me an "a ha" moment.

     

     

    No, not the VD its self but how he programmed it.

    In the VD he uses the following code section

    -------

    local http = net.HTTPClient()
      http:request(url, {
        options = {
          headers = headers,
          data = data,
          method = 'POST',

    -------

     

    The key to me was the "headers" section as this is what I need to do to get API control of the SONY.

    A couple of things you need to know before I post my code that does not work, yet.

     

    I used a program called POSTMAN that intercepted the packets/POST from the little HTML program SONY supplies to show you the API calls work. During that I found that the POST needs at least
            ['x-auth-psk']='0000',     -- the 0000 is set in the TV
            ['host']='192.168.1.11',  -- this being the computer that calls the API
    To work, but the program added a lot more.
            

             ['accept']='*/*',
             ['accept-encoding']='gzip,deflate',
             ['accept-language']='en-US,en;q=0.9',
             ['Content-Type']='text/plain;charset=UTF-8'};

     

    So I tried to write a simple LUA code that would prove that the "headers" options are what I need.
    But I cant get it to work as I am NOT a programmers little pinky.

    Wondering if one of you fine folks could correct my code?

     

     

     

    --[[
    %% properties
    %% events
    %% globals
    --]]

    -- Have to have your SONY TV Pre shared Key set to access all levels of the API.
    -- ------------------------------------------------------------
    -- The SONY is expecting to see ' x-auth-psk = 0000';
    -- ------------------------------------------------------------
    -- This is a simple volume up command, so the API section need to be audio
    -- IP of the tv is 1.200 hard coded for the moment.
    -- ------------------------------------------------------------


     url = 'http://192.168.1.200/sony/audio';
        
    -- I know I need "x-auth-psk" and "host" in the header, as POSTMAN will not work with out them

    headers ={
                     ['x-auth-psk']='0000',
             ['host']='192.168.1.11',  -- needs the host it was sent from             

    -- Might not need these below, POSTMAN will work with out them
             ['accept']='*/*',
             ['accept-encoding']='gzip,deflate',
             ['accept-language']='en-US,en;q=0.9',
             ['Content-Type']='text/plain;charset=UTF-8'};
                
    -- I believe this is the "body" of the HTML request.
    data='{"method":"setAudioVolume","version":"1.0","id":1,"params":[{"target":"speaker","volume":"+1"}]}';

    local http = net.HTTPClient();
    http:request(url,{
        options = {headers = headers, data = data, method = 'POST'}});
     
     };

    -- end code.


    Thanks for your time!

    Link to comment
    Share on other sites

    • 0
    On 11/23/2019 at 11:46 PM, Fodder1 said:

    Hi @dimae

    actually I think I might have. I am still in the testing phase unfortunately. I have had a few setbacks like a divorce and a broken lan port on my testing TV. 
    that has arrived back from repair and I will be testing again soon.

     

    Thanks for trying to help me. I have found a solution and following another guides and I have made a full VD working perfectly fine. I will share it very soon. I hope everything is fine with you as well. Br

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

     Share

    ×
    ×
    • Create New...