Announcement

Collapse
No announcement yet.

how to send a http post command by homesser

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to send a http post command by homesser

    Please, I need your help. I'm from Brazil

    I have a multroom device that I can only control via httip, I just need to post some commands, I do not need answers. I've been trying for days and I can not post the command.

    the lexicon multroom device manual provides this example to communicate with the machine, but I do not know and can not structure a script in homesser.


    Example POST to set setting “auto-powerdown” on the DD8P: (Note: the DD8P IP address is 192.168.0.175)
    POST /settings HTTP/1.1\r\n
    HOST: 192.168.0.175\r\n
    Content-Type: application/json\r\n
    Content-Length: 20\r\n \
    r\n
    {“auto_powerdown”:1}


    I tried to use the commands below, but it does not work, I do not know if I wrote it the right way.

    hs.GetURL("192.168.0.175","POST /settings HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 20\r\n \Content-Length: 20\r\n \{auto_powerdown:1}",FALSE,8080)

    Can someone help me structure this command above in a way that I can send from the homeseer or tell me if I'm using the right command?
    Attached Files

  • #2
    GetURL is used for getting 'information' from an internet server. You are looking to send data to the server.
    I have not done this, but maybe you should be looking at URLAction

    https://help.homeseer.com/help/HS3/s...rnet_urlaction

    Comment


    • #3
      spike5884 please can not you help using the above device code with this urlaction command? I do not understand much of the structure, I tried to make more of the error. I do not understand much of script.

      Comment


      • #4
        Controlling HS3 devices via http commands can be tricky. I use many HS3 events to control my security cameras. It took me a long time and a lot of “trial and error” approach to get them working.

        My suggestion is to start with a browser like chrome and see if you are able to control your device. If you cannot control your device via chrome or edge, you will not be able to control it via HS3.

        When you are able to control your device via a web browser, then you will know the proper format/syntax for HS3. If the web browser works with:

        http://192.168.1.127:8127/decoder_co...user=XX&pwd=XX

        then HS3 can use

        &hs.geturl("http://192.168.1.127:8127/decoder_control.cgi?command=37&user=XX&pwd=XX","",TRUE,80)

        Here are a few of the HS3 event actions I am using everyday.
        HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
        2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

        Comment


        • #5

          Steve Q can you help me structure an event just like yours with the example code that is in the above device manual?

          I do not understand much of http programming, not how should I use the above information in homesser
          Sorry, I'm new to the subject.

          Does the spike5884 above say that you do not use geturl to send commands?

          Comment


          • #6
            It would be something like:

            &hs.geturl("http://192.168.1.50.4/JSON/Command/auto_powerdown","",TRUE,80)

            But you will have to try multiple combinations until you find one that works. Search the web for the device you are trying to control. Try to find some examples of html code to control the device.


            HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
            2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

            Comment


            • #7
              problem that I did not find any information for this lexicon dd8 + device besides those I put up.

              Thank you very much for your help.

              Comment


              • #8
                Ok, the lexicon dd8 is an audio amplifier. Although it may be possible to control it via http over a CAT5 connection, I would recommend using an IR emitter. IR is much more flexible and it will also allow you to control your other Home Theater equipment.

                I use The USBUIRT to send IR codes from HS3 to all of my Home Theater components (Sony TV, Sony Surround Sound, Cable Box, and DVD). This works great. Your total investment would be about $100 not including shipping.
                HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
                2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

                Comment


                • #9
                  Steve Q unfortunately this model I have does not receive infrared signals, the only connection I have with it is via http. I have other equipment that commands via infrared. but this one I won and in his manual he says it's only via http. if you can help me to structure the command I will be very grateful. and thank you

                  Comment


                  • #10
                    I found the manuals for the unit (https://www.lexicon.com/productdetai...dd-8-plus.html). Looked at the IP Control one. The hard part is that they do not tell you what software they use to send those HTTP requests.

                    Hard to say how this would work because I have never used it, maybe something like this:
                    Code:
                    dim s
                    const server_url = "192.168.0.175"
                    const headers = "Content-Length: 20"
                    const data = '{“auto_powerdown”:1}'
                    
                    s = hs.URLAction(server_url, "POST", data, headers)

                    Comment


                    • #11
                      so they have no software, the only way to control is via http, just like this command in the manual.
                      I will test here the structure that you did and return what happened.

                      Once again I wanted to thank you so much for caring and helping me find a solution.

                      I am very grateful to you, spike5884 and Steve Q

                      Comment


                      • #12
                        spike5884
                        ​​​​​​​I put the event to run as the example.


                        dim s
                        const server_url ="192.168.0.175"
                        const headers="Content-Length: 20"
                        const data ="{“auto_powerdown”:1}"



                        Sub Main()




                        s = hs.URLAction(server_url, "POST", data, headers)


                        End Sub



                        the following error is appearing:

                        out-26 09:23:35 Error In URLAction POST: Invalid URI: Invalid URI schema.

                        Comment


                        • #13
                          Take a look at this line in your code -
                          Code:
                          const data ="{“auto_powerdown”:1}"
                          it should be:

                          Code:
                          const data = '{“auto_powerdown”:1}'
                          Bob

                          Comment


                          • #14
                            Bob_Linux_User
                            I put it exactly as suggested and it gives syntax error.
                            Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/multroom.txt1002:Erro de sintaxe in line 4 More info: Erro de sintaxe

                            Comment


                            • #15
                              Try this:
                              Code:
                              Sub Main(parm as object)
                              dim debug = false
                              const server_url = "http://192.168.0.175/settings"
                              const headers = "Content-Type: application/json"
                              const data = "{""auto_powerdown"":1}"
                              dim s = hs.URLAction(server_url, "POST", data, headers)
                              If debug Then hs.writelog("POST response", s)
                              End Sub
                              However it appears that the hs.URLAction encodes the content; this is what the server receives:
                              Code:
                              POST /settings HTTP/1.1
                              Connection: Keep-Alive
                              Expect: 100-continue
                              Host: 192.168.1.118:8000
                              Content-Length: 30
                              Content-Type: application/json
                              
                              %7b%22auto_powerdown%22%3a1%7d
                              Note on the last line the "punctuation" characters are being URL encoded.

                              If this doesn't work, you'll want to ditch the HS convenience function. Adapting example from Microsoft, https://docs.microsoft.com/en-us/dot...brequest-class

                              Code:
                              Imports System.IO  
                              Imports System.Net  
                              Imports System.Text  
                              Sub Main(parm as object)
                                  const debug = false
                                  const server = "192.168.0.175"
                                  const postData = "{""auto_powerdown"":1}"
                                  ' Create a request using a URL that can receive a post.  
                                  const server_url = "http://" & server & "/settings"
                                  Dim request As WebRequest = WebRequest.Create(server_url)  
                                  ' Set the Method property of the request to POST.  
                                  request.Method = "POST"  
                                  ' Create POST data and convert it to a byte array.  
                                  Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)  
                                  ' Set the ContentType property of the WebRequest.  
                                  request.ContentType = "application/json"  
                                  ' Set the ContentLength property of the WebRequest.  
                                  request.ContentLength = byteArray.Length  
                                  ' Get the request stream.  
                                  Dim dataStream As Stream = request.GetRequestStream()  
                                  ' Write the data to the request stream.  
                                  dataStream.Write(byteArray, 0, byteArray.Length)  
                                  ' Close the Stream object.  
                                  dataStream.Close()  
                                  ' Get the response.  
                                  Dim response As WebResponse = request.GetResponse()  
                                  ' Display the status.  
                                  If debug Then hs.writelog("POST request", CType(response, HttpWebResponse).StatusDescription)  
                                  ' Get the stream containing content returned by the server.  
                                  dataStream = response.GetResponseStream()  
                                  ' Open the stream using a StreamReader for easy access.  
                                  Dim reader As New StreamReader(dataStream)  
                                  ' Read the content.  
                                  Dim responseFromServer As String = reader.ReadToEnd()  
                                  ' Display the content.  
                                  If debug Then hs.writelog("POST response", responseFromServer)  
                                  ' Clean up the streams.  
                                  reader.Close()  
                                  dataStream.Close()  
                                  response.Close()  
                              End Sub
                              With this the server receives non-encoded content:
                              Code:
                              POST /settings HTTP/1.1
                              Connection: Keep-Alive
                              Expect: 100-continue
                              Host: 192.168.1.118:8000
                              Content-Length: 20
                              Content-Type: application/json
                              
                              {"auto_powerdown":1}

                              Comment

                              Working...
                              X