Announcement

Collapse
No announcement yet.

Extremely weird HS4 native command execution failure

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

    Extremely weird HS4 native command execution failure

    I have 14 identical events that each issues HS4 command like this one. This is the only thing they do. Nothing else.

    Code:
    &nhs.GetURL("http://192.168.1.111/cm?" , "cmnd=Power%20on", True, 80)
    they control 7 Tasmota light dimmers. 7 commands are for "on" and 7 are for "off"
    they go to 7 different IP addresses (.111 in the example above ) as each dimmer has it's own IP address.

    13 out of 14 work reliably all the time. One only is stubborn and refuses to work no matter what. I checked the syntax many times for typos. I actually copied and pasted the command from a working one to make sure there are no typos. I deleted and re-created the event. I changed the name of the event. No luck, no matter what I try. The one not working is

    Code:
    &nhs.GetURL("http://192.168.1.120/cm?" , "cmnd=Power%20on", True, 80)
    only for address .120 and only for "on" command. The "off" command does work for the same address.

    The dimmer itself is not to blame as it responds properly if the URL is entered manually in a browser http://192.168.1.120/cm?cmnd=Power%20on

    It also works if I use Big5 plug-in to issue the HTTP GET command. The problem with Big5 though is that I need to create HTTP profile for each and every dimmer, which means 7 HTTP profiles. Not impossible but the native HS4 solution looked simpler to me. For now I have .120 dimmer on Big5 and the rest on HS4 commands but hate when weird things happen that can't be explained.

    #2
    How is the event triggered?
    Have you tried to trigger the event manually?
    What happens if you put the IP of the switch that is not working into an event that is working?
    Is it possible you have that one event disabled?

    Comment


      #3
      drhtmal
      Events are triggered by value change of respective HS4 devices or called by other HS4 events, however for testing purposes I do trigger them manually one by one. Everything that I reported above is a result of manual triggering of the events. Furthermore, I check HS4 log where I do see a confirmation that the event was triggered, and yet no effect on the device.

      Let me ask additional question. Is it possible to setup more detailed log to show what exactly is happening in the bowels of HS4 when executing the GetURL command? Maybe there will be a clue there.

      Comment


        #4
        Embed GetURL in a script. Start with something like this
        Code:
        Sub Main(parm As String)
        
            Dim logName As String = "test"
            Dim host As String = "http://192.168.1.120"
            Dim page As String = "/cm?cmnd=Power%20on"
            Dim strip_tags As Boolean = True
            Dim port As Integer = 80
        
            Try
                Dim resp As String = hs.GetURL(host, page, strip_tags, port)
                hs.WriteLog(logName, resp)
        
            Catch ex As Exception
                'Error trapping
                hs.WriteLogEx(logName, ex.Message, "#ff0000")
        
            End Try
        
        End Sub

        Comment


          #5
          zwolfpack

          Thanks for the cooperation. Copied the proposed script literally, as I'm not a programmer. Getting this error when trying to run it

          Running script: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex-> at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType) at System.String.IndexOf(String value, Int32 startIndex) at Scheduler.Trigger.TriggerRunScript(String scr, Boolean single_instance, Int32 phone_line, String host, Boolean wait_here, String CalledFrom, String UName, Int32 URights, String passedfunc, Object passedparam, Int32 evref, Boolean DoSetEvent)

          Comment


            #6
            The HS4 scripting interface ... sucks.

            Here I've created an event and pasted the file into it. (Twice ... the first time it kindly erased what I'd pasted so I tried again).

            The name of the script is GetURL.vb. It needs to have the ".vb" extension.

            Click image for larger version

Name:	GetURL event.PNG
Views:	48
Size:	424.4 KB
ID:	1457093
            Clicking on EDIT SCRIPT should reveal this

            Click image for larger version

Name:	GetURL script.PNG
Views:	44
Size:	168.7 KB
ID:	1457094

            To test, I set up a webserver at 192.168.1.118:8000 and configured it such that it would return a file with contents "Hello there!" when queried for URI "cm". Result from running the event is displayed in log (bottom to top):

            Code:
            2/17/2021 21:41:33 Script test hello there!
            2/17/2021 21:41:33 HomeSeer Event Running script in background (GetURL): GetURL.vb
            2/17/2021 21:41:33 HomeSeer Event Event Trigger "Sandbox GetURL"
            HS4 log presentation to this forum also sucks, but hopefully this make some sense.

            I run HS4 only in a test instance, and when I do I'm reminded why I don't run it for real.

            Comment


              #7
              zwolfpack

              Thanks again. Adding .vb to the name solved the problem. Now the script works and reports to the log and guess what it does operate the dimmer. Still a mystery why direct HS4 command wouldn't.

              Here is the log

              2/17/2021 10:29:13 PM

              Script
              test
              {"POWER":"ON"}

              2/17/2021 10:29:13 PM

              HomeSeer
              Event
              Running script and waiting (GET by script): gethttp.vb

              2/17/2021 10:29:13 PM

              HomeSeer
              Event
              Event Trigger "Test GET by script"

              2/17/2021 10:29:13 PM

              HomeSeer
              Event
              Event Test GET by script triggered by the event page 'Run' button.

              Comment


                #8
                zwolfpack

                As far as your script works more solidly and reliably than the HS4 command, can you please help with two things

                1. Advise how to call the script with "host" and "page" as parameters.

                2. Advise how to modify "page" to include HS4 device value and again call the script with device value as parameter. Ultimately the URL needs to look like that to achieve dimmer functionality in addition to on/off.
                Code:
                &nhs.GetURL("http://192.168.1.241" , "/cm?cmnd=Dimmer%20" & hs.DeviceValue(3130), True, 80)

                Comment


                  #9
                  I think I understand what you're asking; try this.

                  On the event page, what you put in the Parameters field is parsed into host, command, and optional device reference. If a device reference is specified, a space and the value of that device is appended to the end of the command.

                  Examples
                  192.168.1.120,Power On
                  192.168.1.118,Dimmer,123


                  Code:
                  Imports System.Net
                  
                  Sub Main(p As String)
                  
                      ' Parse optional parameters
                      Dim pa As String() = Split(p, ",")
                  
                      ' 1st parameter: host
                      Dim host As String
                      If pa.Length > 0 Then host = pa(0)
                  
                      ' 2nd parameter: command
                      Dim cmd As String
                      If pa.Length > 1 Then cmd = pa(1)
                  
                      ' 3rd parameter: optional dvRef
                      Dim dvRef, dvVal As Integer
                      If pa.Length > 2 AndAlso IsNumeric(pa(2)) Then
                          dvRef= CInt(pa(2))
                          dvVal = hs.DeviceValue(dvRef)
                          cmd &= " " & dvVal
                      End If
                  
                      Dim logName As String = "getURL"
                      Dim page As String = "/cm?cmnd=" & WebUtility.HtmlEncode(cmd)
                      Dim strip_tags As Boolean = True
                      Dim port As Integer = 80
                  
                      Try
                          Dim resp As String = hs.GetURL(host, page, strip_tags, port)
                          hs.WriteLog(logName, resp)
                  
                      Catch ex As Exception
                          'Error trapping
                          hs.WriteLogEx(logName, ex.Message, "#ff0000")
                  
                      End Try
                  
                  End Sub

                  Comment


                    #10
                    zwolfpack

                    Thanks a lot. Copied the code literally, named the script gosunddimmer.vb and getting these errors now

                    Compiling script gosunddimmer.vb: 'HttpUtility' is not declared. It may be inaccessible due to its protection level

                    Compiling script gosunddimmer.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                    Comment


                      #11
                      P.S. The field "Sub or func" is blank in the HS4 event and the filed "Parameters" has this

                      Code:
                      192.168.1.120,Dimmer,3138

                      Comment


                        #12
                        You're right, on Windows (HS3) I get that same error.

                        I edited the script and changed two lines: line 1 changed from 'System.Web' to 'System.Net' and line 26 from 'HttpUtility' to 'WebUtility'.

                        I originally ran it it on Linux (HS4) where the other way worked. This new way runs on both.

                        I don't know it if Google don't know it!

                        Comment


                          #13
                          zwolfpack

                          Works like a charm. Thanks a lot.

                          Comment

                          Working...
                          X