Announcement

Collapse
No announcement yet.

Script error writing to log:

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

    Script error writing to log:

    I am running the following script and receiving this error:

    HomeSeer Error 1 Running script ATMCDown_50.vb: Exception has been thrown by the target of an invocation.

    Sub Main(ByVal Parm As String)
    Dim NetworkFullPath As String = "C:\Program Files (x86)\HomeSeer HS3\Logs\Network Loss.log"
    My.Computer.FileSystem.WriteAllText(NetworkFullPath, "Gateway Packet Loss above 49%: " & Now() & vbCrLf, True)
    End Sub


    The oddity is that it still works fine! Does anybody know what I'm doing wrong?
    HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
    Home Assistant 2024.3
    Operating System: Microsoft Windows 11 Pro - Desktop
    Z-Wave Devices via two Z-Net G3s
    Zigbee Devices via RaspBee on RPi 3b+
    WiFi Devices via Internal Router.

    Enabled Plug-Ins
    AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

    #2
    Originally posted by ewkearns View Post
    I am running the following script and receiving this error:

    HomeSeer Error 1 Running script ATMCDown_50.vb: Exception has been thrown by the target of an invocation.

    Sub Main(ByVal Parm As String)
    Dim NetworkFullPath As String = "C:\Program Files (x86)\HomeSeer HS3\Logs\Network Loss.log"
    My.Computer.FileSystem.WriteAllText(NetworkFullPath, "Gateway Packet Loss above 49%: " & Now() & vbCrLf, True)
    End Sub


    The oddity is that it still works fine! Does anybody know what I'm doing wrong?
    Don't the parameters for Main in a HomSeer VB.Net script have to be an object, i.e. not a string? Certainly I always define them as an object which is normally passed an array of objects, or nothing.
    ​​​​​​
    Steve

    Comment


      #3
      Thanks, Steve! That was it! This was not an original composition and I may have screwed it up. I don't truly understand this "parameter" stuff, especially when I am not passing a parameter.
      HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
      Home Assistant 2024.3
      Operating System: Microsoft Windows 11 Pro - Desktop
      Z-Wave Devices via two Z-Net G3s
      Zigbee Devices via RaspBee on RPi 3b+
      WiFi Devices via Internal Router.

      Enabled Plug-Ins
      AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

      Comment


        #4
        Script calls from an Homeseer event will pass a single string. Script calls from an HS Touch will pass an array of strings. Declaring the input parameters for one way will earn that error message if called from the other side. However, an Object can contain either a string or an array of strings, so declaring the parameter as an object will make it work without the parameter mismatch error when called from either side.

        Programming can be needlessly complicated sometimes.

        Comment


          #5
          Originally posted by ewkearns View Post
          Thanks, Steve! That was it! This was not an original composition and I may have screwed it up. I don't truly understand this "parameter" stuff, especially when I am not passing a parameter.
          Glad you are sorted😊

          I haven't tested whether HS complains if you leave the parameter field blank, i.e. Main(). I always use Main(ByVal Parm as object) in HS scripts, whether I am passing any parameters or not. Strictly speaking you could use ByRef rather than ByVal because, for an object, a pointer is passed to the object so there is nothing to be gained using ByVal. However, the performance difference is probably insignificant.

          Steve

          Comment


            #6
            Originally posted by SteveMSJ View Post
            I haven't tested whether HS complains if you leave the parameter field blank, i.e. Main().
            Leaving the parameter field blank will just earn you another error. A parameter will always be passed by the system, even if that parameter is blank (or null in programming terms)


            Comment


              #7
              Originally posted by aa6vh View Post

              Leaving the parameter field blank will just earn you another error. A parameter will always be passed by the system, even if that parameter is blank (or null in programming terms)

              Thanks for the confirmation.
              That's probably why I always define a parameter even when I'm not using one. I probably ran into the issue many years ago, but my memory is not so good now🙁

              Steve

              Comment


                #8
                I forgot to add that an empty string (actually a null string) is an even different type of variable from string or an array of strings, which fortunately can also be held in an Object. Therefore you cannot go wrong declaring it an object. The ByVal is not necessary here, as it is assumed.

                Comment


                  #9
                  I understand more about that now than from reading several books. Thanks, folks!
                  HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
                  Home Assistant 2024.3
                  Operating System: Microsoft Windows 11 Pro - Desktop
                  Z-Wave Devices via two Z-Net G3s
                  Zigbee Devices via RaspBee on RPi 3b+
                  WiFi Devices via Internal Router.

                  Enabled Plug-Ins
                  AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

                  Comment

                  Working...
                  X