Announcement

Collapse
No announcement yet.

Need scripting help

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

    Need scripting help

    in this thread I talk about a "wattbox" that came with my house. Basically a switched outlet that I can control state via IP. You need to be a dealer to get a cloud account and access to the app, but you can control it from a web interface. Thought it might be handy to be able to reboot my modem, etc.

    I tried the following script in HS# to turn the outlet off, but got authorization denied in the log. Figures, since I don't have that in the scipt.

    &hs.urlaction("http://xxx.xxx.x.x/control.cgi?outlet=3&command=0", "GET", "", "")

    The following is the API doc. can someone give me a quick tutorial on how to interpret this and what the script should look like? thanks. (PS, I have no idea what CRLF means).
    https://www.snapav.com/wcsstore/Exte...API%20v2.0.pdf

    #2
    In a general sense, CRLF mean carriage return, line feed. In a scripting sense you would invoke a newline with \n and a carriage return with \r. In this case taking a quick look, I'm not sure if it should be quoted or not.

    Robert
    HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

    Comment


      #3
      Been playing with this but can't get it.... this is the script I put together:

      &hs.urlaction("GET control.cgi?outlet=3&command=0 HTTP/1.1", "Host: 192.168.1.21”, "Keep-Alive: 300", "Connection: keep-alive", "Authorization: d2F0dGJveDp3YXR0Ym94”, "User-Agent: APP”, “”,””)

      Based on these instructions, including turning the user/pass into a base64 encoded auth.

      Your complete packet request consists of the request as shown:

      "GET control.cgi?outlet=<#>&command=<#> HTTP/1.1"CRLF
      "Host:" <your WattBox’s ip>CRLF
      "Keep-Alive: 300"CRLF
      "Connection: keep-alive"CRLF
      "Authorization: Basic" <authorization>CRLF
      "User-Agent: APP"CRLFCRLF

      Command Number: • 0: power off • 1: power on • 3: power reset (available only when outlet is already on) • 4: auto reboot on • 5: auto reboot off

      Example, to reset outlet 1, use the command:
      control.cgi?outlet=1&command=3

      To create the authorization code, concatenate the account name, a colon, and the account password, then use base64 encoding to create a string. For example, if the account is admin and the password is 1234, then take the string admin:1234 and encode it with base64. This gets you the string YWRtaW46MTIzNA==, which is your authorization

      Comment


        #4
        Documentation for hs.urlaction is sparse to say the least. I've not stumbled across the syntax necessary to coax it to send more than a single header.

        This might get you started, if you're lucky it'll work with only the Authoriziation header.

        Code:
        hs.URLAction("http://192.168.1.29/control.cgi?outlet=3&command=0", "GET", "", "Authorization: d2F0dGJveDp3YXR0Ym94")
        Here is what is received by the remote server

        Code:
        GET /control.cgi?outlet=3&command=0 HTTP/1.1
        Connection: Keep-Alive
        Authorization: d2F0dGJveDp3YXR0Ym94
        Host: 192.168.1.29
        Content-Type: application/x-www-form-urlencoded
        If that doesn't work you might have to forgo the buggy hs.urlaction wrapper and implement directly using .NET stuff.

        [Note that it seems that hs.urlaction always tosses in that Content-Type header, even though that's only applicable for POST method -- and then only when sending form data]

        Comment


          #5
          funny... I tried just the actual command yesterday per the doc, and it didn't work. reached out to their support, and he gave me this, which is what I thought I tried. Works great now from a browser.
          http://192.168.1.21/control.cgi?outlet=3&command=0

          So I tried this as an immediate script in my event, and I get the error code below.

          Oct-31 10:20:17 AM Error In URLAction GET: The remote server returned an error: (401) Unauthorized.
          Oct-31 10:20:17 AM Event Running script statement immediately: &hs.URLAction("http://192.168.1.21/control.cgi?outlet=3&command=0", "GET", "", "")
          Oct-31 10:20:17 AM Event Event Trigger "Test Wattbox test"

          @zwolfpack, tried yours as well... same issue:
          Oct-31 10:23:48 AM Error In URLAction GET: The remote server returned an error: (401) Unauthorized.
          Oct-31 10:23:48 AM Event Running script statement immediately: &hs.URLAction("http://192.168.1.21/control.cgi?outlet=3&command=0", "GET", "", "Authorization: d2F0dGJveDp3YXR0Ym94")
          Oct-31 10:23:48 AM Event Event Trigger "Test Wattbox test"
          Oct-31 10:23:48 AM Event Event Test Wattbox test triggered by the event page 'Run' button.

          Comment


            #6
            Is there a username/password for the device? If so, try something like:

            Code:
            http://username:password@192.168.1.21/control.cgi?outlet=3&command=0
            HS 3.0.0.548: 1990 Devices 1172 Events
            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

            Comment


              #7
              The browser caches the authorization, so you only get prompted the first time. Shut down the browser and next time you try you'll get the authorization popup.

              You have to provide at least the Authorization header, as I showed (usename/password = wattbox/wattbox). If that doesn't work, you'll need to use a different method than hs.urlaction because it's broken. I have an example that may work that I can post later.

              Comment


                #8
                Originally posted by sparkman View Post
                Is there a username/password for the device? If so, try something like:

                Code:
                http://username:password@192.168.1.21/control.cgi?outlet=3&command=0
                That also worked from the browser, but not from the event. do I have this syntax right? does it have to be a vb script, or can I run as immediate?

                hs.URLAction("http://wattbox:wattbox@192.168.1.21/control.cgi?outlet=3&command=0", "GET", "", "")

                Comment


                  #9
                  Just noticed an omission in my earlier posting...

                  try this:
                  Code:
                  hs.URLAction("http://192.168.1.29/control.cgi?outlet=3&command=0", "GET", "", "Authorization: Basic d2F0dGJveDp3YXR0Ym94")

                  Comment


                    #10
                    Looks to be correct. I would run it as a script so that you can trap the server response and write it to the log.
                    Code:
                    Dim s As String = hs.URLAction("http://wattbox:wattbox@192.168.1.21/control.cgi?outlet=3&command=0", "GET", "", "")
                    hs.writelog("URL Response",s)
                    HS 3.0.0.548: 1990 Devices 1172 Events
                    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                    Comment


                      #11
                      I think the browser handles the translation from the http://username@password@location syntax to the appropriate headers. I'm not optimistic it'll work in this case.

                      Comment


                        #12
                        Originally posted by zwolfpack View Post
                        I think the browser handles the translation from the http://username@password@location syntax to the appropriate headers. I'm not optimistic it'll work in this case.
                        Good point. Maybe hs.geturlie will work in this case, but otherwise as you suggested above, using direct .net calls may be the best way to go.
                        HS 3.0.0.548: 1990 Devices 1172 Events
                        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                        Comment


                          #13
                          Ran first as usernameassword@location, followed by the base64 version. here's what I get

                          first one is auth error, second can't connect.
                          zwolfpack , are you saying that HS3 won't be able to handle the translation?
                          Oct-31 11:00:12 AM URL Response Unable to connect to the remote server
                          Oct-31 11:00:12 AM Error In URLAction GET: Unable to connect to the remote server
                          Oct-31 11:00:11 AM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/Znet-Reboot.vb
                          Oct-31 11:00:11 AM Event Event Trigger "Test Wattbox test"
                          Oct-31 11:00:11 AM Event Event Test Wattbox test triggered by the event page 'Run' button.
                          Oct-31 10:59:22 AM URL Response The remote server returned an error: (401) Unauthorized.
                          Oct-31 10:59:22 AM Error In URLAction GET: The remote server returned an error: (401) Unauthorized.
                          Oct-31 10:59:22 AM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/Znet-Reboot.vb
                          Oct-31 10:59:22 AM Event Event Trigger "Test Wattbox test"
                          Oct-31 10:59:22 AM Event Event Test Wattbox test triggered by the event page 'Run' button.

                          Comment


                            #14
                            Here's an example with .net calls: https://forums.homeseer.com/forum/de...598#post340598
                            HS 3.0.0.548: 1990 Devices 1172 Events
                            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                            Comment


                              #15
                              Originally posted by sparkman View Post
                              Eeeh… wow. that is way over my head. i'm still trying to grock simple scripting.

                              Comment

                              Working...
                              X