Announcement

Collapse
No announcement yet.

how to send a http post command by homesser

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

  • #16
    Hello I was able to do the tests only today, I put the script like zwolfpack requested. The following error is appearing.
    Error Running script, script run or compile error in file: C:/Program Files (x86)/HomeSeer HS3/scripts/multroom.txt1006:')' esperado in line 4 More info: ')' esperado

    Comment


    • #17
      ​1) Which of the two scripts did you try?
      2) The script needs to be named with a .vb extension. Looks like you saved it with a '.txt' extension (multroom.txt1006). Save it with name something like "multroom.vb"

      Here is the event for the 1st script. Note the script filename is json_post1.vb

      Last edited by zwolfpack; October 29th, 2018, 10:59 AM.

      Comment


      • #18

        zwolfpack I checked again and it was not like .VB. It worked the second option you posted. I would like to thank everyone who has worked hard to help me solve the problem. If it were not for you I would not be able to. ​​​​​​​Thank you very much.

        Comment


        • #19
          Great! Glad you got it working.

          Comment


          • #20
            I'm trying to do the same thing to control a device on a remote HS instance via myhs... the following works in a browser -
            https://connected2.homeseer.com/JSON...&ref=9&value=0

            however the following immediate script command on an event -
            &hs.GetURL(“https://connected2.homeseer.com/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&va lue=0","",TRUE, 8080)

            Returns the following in the log -
            ov-06 4:22:52 PM Warning JSON controldevicebyvalue caused an error: Input string was not in a correct format.
            Nov-06 4:22:49 PM Event Running script statement immediately: &hs.GetURL(“https://connected2.homeseer.com/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&va lue=0","",TRUE, 8080)

            Any suggestions?

            Comment


            • #21
              Looks like you have an out-of-place space embedded in the word "value" - you have "...&va lue=0".

              Comment


              • #22
                zwolfpack returning to the subject of communication with the lexicon equipment, I'm having difficulties controlling the outputs of the equipment .. for being new and having changed the commands a lot I can not correctly enter the information in the script.
                Can you please help me mount these parameters in that script you set for me?
                Attached Files

                Comment


                • #23
                  zwolfpack you or anyone can help me with the problem quoted above?
                  I tried to get the whole code and replace it in the command line, until it sends the command without error but it does not work.

                  I had to put "" example "" quotes because the homesser was giving syntax error.

                  please can not find what's missing or what I'm doing wrong.

                  follow the code below


                  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 = "{""output_id"":0,""name"": ""OUTPUT 1"",""mute"":0,""dim"":1,""volume"":0.000000,""turn_on_volum e"":0.000000,""max_volume"" :0.000000,""limiter"":0,""output_mix"":[1.000000,0.000000,0.000000,0.000000,0.00 0000,0.000000,0.000000,0.000000]}"
                  ' Create a request using a URL that can receive a post.
                  const server_url = "http://" & server & "/output/OUTPUT_IDX"
                  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

                  Comment


                  • #24
                    I took a look at it last night, I'll try to post something later this evening.

                    One thing, the term OUTPUT_IDX in the manual actually stands for a number 0 - 7. Try changing the line

                    const server_url = "http://" & server & "/output/OUTPUT_IDX"

                    to

                    const server_url = "http://" & server & "/output/0"

                    or 1, 2, etc...

                    Comment


                    • #25
                      zwolfpack I tried to do what you requested it sends the script without error but does not change anything in the equipment.

                      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 = "{""output_id"":1,""name"": ""Piscina-R"",""mute"":1,""dim"":1,""volume"":0.000000,""turn_on_vo lum e"":0.000000,""max_volume"" :0.000000,""limiter"":0,""output_mix"":[1.000000,0.000000,1.000000,0.000000,1.00 0000,0.000000,1.000000,0.000000]}"
                      ' Create a request using a URL that can receive a post.
                      const server_url = "http://" & server & "/output/1"
                      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

                      Comment


                      • #26
                        zwolfpack I would like to thank you again for your commitment to help me, I was able to make it work. I placed examente as it was showing up in google browser and it worked.

                        Thank you and if you have any other way of thanking you that you are within my reach, you can count on me.

                        The world needs more people like you zwolfpack.

                        my only doubt now is how I create a slider in the hstouch that can increase and decrease the volume of these outputs. If you can help with this too I will be very grateful


                        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 = "{""output_id"":0,""name"": ""Piscina-L"",""mute"":1,""dim"":1,""volume"":0.000002,""turn_on_vo lum e"":-30.000002,""max_volume"":0.000000,""limiter"":0,""output_mix "":[1.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.0000 00,1.000000]}"
                        ' Create a request using a URL that can receive a post.
                        const server_url = "http://" & server & "/output/0"
                        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
                        Last edited by Jean carlos; November 8th, 2018, 06:52 PM.

                        Comment


                        • #27
                          Congrats on making it work! Sorry I can't help with the HSTouch Designer, I've never used that. Guessing that you could create a device that's controlled by a slider. Then you could read the value of that device into the script and put that value into the POST message.

                          For help in creating the slider, perhaps ask in one of the HSTouch forums. Once you get the slider that controls a virtual device I can help using that in the POST script.

                          Comment


                          • #28
                            Originally posted by zwolfpack View Post
                            Looks like you have an out-of-place space embedded in the word "value" - you have "...&va lue=0".
                            Not sure why the space is appearing, it's definitely not there until i paste it in here.. In-fact it doesn't appear until I actually post the message. I've rewritten the command multiple times and keep getting the same outcome, any other thoughts?

                            Running script statement immediately:
                            &hs.GetURL("https://connected2.homeseer.com/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&va lue=0","",TRUE,8080)

                            Literally every-time I edit the post and remove the space from the line above and hit save, the space re-appears

                            Comment


                            • #29
                              Originally posted by JoshKitson View Post

                              Not sure why the space is appearing, it's definitely not there until i paste it in here.. In-fact it doesn't appear until I actually post the message. I've rewritten the command multiple times and keep getting the same outcome, any other thoughts?

                              Running script statement immediately:
                              &hs.GetURL("https://connected2.homeseer.com/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&va lue=0","",TRUE,8080)

                              Literally every-time I edit the post and remove the space from the line above and hit save, the space re-appears
                              Looks like a forum thing. Does it for me as well until I put CODE tags around it.

                              Your GetURL call has multiple issues. See http://help.homeseer.com/help/HS3/st...nternet_geturl

                              Try
                              Code:
                              &hs.GetURL("https://connected2.homeseer.com", "/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&value=0", TRUE, 443)
                              Port 443 is https. This may not work though, I don't know if it will get sent out encrypted.

                              Edit: it does work. Recommend checking "do not log this event", otherwise your password will be in the log every time it runs.
                              Last edited by zwolfpack; November 10th, 2018, 03:30 PM.

                              Comment


                              • #30
                                Originally posted by zwolfpack View Post

                                Looks like a forum thing. Does it for me as well until I put CODE tags around it.

                                Your GetURL call has multiple issues. See http://help.homeseer.com/help/HS3/st...nternet_geturl

                                Try
                                Code:
                                &hs.GetURL("https://connected2.homeseer.com", "/JSON?user=***&pass=***&request=controldevicebyvalue&ref=9&value=0", TRUE, 443)
                                Port 443 is https. This may not work though, I don't know if it will get sent out encrypted.

                                Edit: it does work. Recommend checking "do not log this event", otherwise your password will be in the log every time it runs.
                                Perfect, Thank you!

                                Comment

                                Working...
                                X