Announcement

Collapse
No announcement yet.

Identify a script

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

  • Identify a script

    I am trying to write a snipplet that I can apply to a bunch of different scripts. It would be helpful is there was a call that would identify a script within the script itself. Is this possible?

    Thanks
    Don

  • #2
    Can you rephrase your question? I don't understand what you mean by "identify a script within the script itself". Do you mean identify the script that called a function? What do you intend to do with the identification? You could pass a parameter to a function that has a unique value, thereby identifying which script called the function. Is that what you are aiming for?
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.500

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

    Comment


    • #3
      Yeah, that wasn't very clear.

      This is my method that I use in all my scripts. I like the log entry to list the name of the script, to aid in troubleshooting. As of now, whenever I include
      this method, I need to declare ID as the name of the script.

      Hope this is a little clearer.

      PHP Code:
      Public Sub Main(ByVal scriptName As StringByVal Message As StringSeverity As Integer)
                      
          
      Dim ID As String =scriptName
                              
          
      If Severity 0 Then hs.WriteLogEx(ID,Message,"#80800")        
          If 
      Severity 1 Then hs.WriteLogEx(ID,Message,"#0000FF")    
          If 
      Severity 2 Then hs.WriteLogEx(ID,Message,"#ADD8E6")    
          If 
      Severity 3 Then hs.WriteLogEx(ID,Message,"#FF0000")    
          If 
      Severity 4 Then hs.WriteLogEx(ID,Message,"#FFA500")
                          
      End Sub 
      Don

      Comment


      • #4
        If I am understanding you correctly, you could pass parameters to the subscript to define these. See this old post on Passing Parameters to VB Script.

        Karl S

        Comment


        • #5
          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


          • #6
            You could use a global variable. In each of your scripts, set the var to your scriptname at the beginning. The sub script could use it.

            tenholde
            tenholde

            Comment


            • #7
              I guess I was looking for a hs.scriptName that would identify the script that it was invoked from. Will stay with making a global ID for each script.

              Thanks for all the suggestions.
              Don

              Comment


              • #8
                Low tech suggestion. When HS runs a script, a log entry should identify the script, like this:
                May-03 3:05:00 PM Event Running script in background: C:/Program Files/HomeSeer HS3/scripts/DataHourly.vb
                Unless you run your function VERY often and in quick succession from multiple scripts, I would think that log entry may be adequate identification.
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.500

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

                Comment


                • #9
                  Good idea. I'll try that.
                  Don

                  Comment


                  • #10
                    Originally posted by donstephens View Post
                    Good idea. I'll try that.
                    Don, I do something like this....

                    For scripts with only one entry point... I set constants variables that can be used to put entries in the HomeSeer log including the script name. I am in the process of adding the ability to turn on logging for some scripts using a device. The examples below do not have the IF statements in them to grab the logging variable.

                    Code:
                    Const v_script_name                  = "bjd_hstouch_chart.vb"        ' Script name.
                    Const v_logging_name                 = "BJD HTouch"                  ' Logging name.
                    
                    '**********************************************************************************************
                    '* Main Entry Point                                                                           *
                    '**********************************************************************************************
                    Sub Main(ByVal Parms As Object)
                    
                      '============================================================================================
                      ' Variable declarations.
                      '============================================================================================
                    
                      '============================================================================================
                      ' Begin program.
                    
                    '============================================================================================
                      hs.WriteLog(v_logging_name, "Begin " & v_script_name & " script.")
                    
                      ' Do some work here  '============================================================================================
                      ' End   program.
                      '============================================================================================
                    
                      '============================================================================================
                      ' Destroy variables.
                      '============================================================================================
                    
                    End Sub

                    For scripts with multiple entry points, a Main section other subs...


                    Code:
                    '==============================================================================================
                    'Constant declarations.
                    '==============================================================================================
                    Const v_script_name                = "bjd_set_insteon.vb"            ' Script name.
                    
                    '**********************************************************************************************
                    '* Main Entry Point                                                                           *
                    '**********************************************************************************************
                    Sub Main(ByVal param As Object)
                    
                      '============================================================================================
                      ' Variable declarations.
                      '============================================================================================
                    
                      '============================================================================================
                      ' Begin program.
                      '============================================================================================
                    
                      '============================================================================================
                      ' End   program.
                      '============================================================================================
                    
                      '============================================================================================
                      ' Destroy variables.
                      '============================================================================================
                    
                    End Sub
                    
                    '**********************************************************************************************
                    '* BJD_Set_Insteon_Log_OFF                                                                    *
                    '**********************************************************************************************
                    Sub logging_off(ByVal Parm As Object)
                    
                      Dim v_logging_name               = "BJD_Utility"
                      Dim v_sub_name                   = "logging_off"
                      Dim v_dv
                      Dim v_en                         = hs.GetDeviceEnumerator
                    
                      '============================================================================================
                      ' Begin program.
                      '============================================================================================
                      hs.WriteLog(v_logging_name, "Begin " & v_script_name & " Sub: " & v_sub_name & " script.")
                    
                        Try
                            'Run through the enumerator
                    
                            If v_en Is Nothing Then 
                               hs.WriteLog(v_logging_name, "Error in " & v_script_name & " script " & v_sub_name & " subroutine." & "Error getting Enumerator")
                               Exit Sub
                            End If
                    
                            Do
                                v_dv = v_en.GetNext
                                If v_dv Is Nothing Then Continue Do
                                   If v_dv.Interface(Nothing).ToLower = "insteon" Then
                                      hs.writelog(v_logging_name, "Set Log Device OFF for => " & " " & v_dv.device_type_string(hs) & " Device name:" & " " & v_dv.location2(hs) & " " & v_dv.location(hs) & " " & v_dv.name(hs))
                                      v_dv.MISC_Set(hs, Enums.dvMISC.NO_LOG)
                                      hs.SaveEventsDevices()
                                   End If
                            Loop Until v_en.Finished
                    
                        Catch ex As Exception : hs.writelog(v_logging_name, "Device Clear => Exception: " & ex.message)
                        End Try
                    
                      hs.WriteLog(v_logging_name, "End "  & v_script_name & " Sub: " & v_sub_name & " script.")
                    
                      '============================================================================================
                      ' Destroy variables.
                      '============================================================================================
                      v_logging_name                   = Nothing
                      v_sub_name                       = Nothing
                      v_dv                             = Nothing
                      v_en                             = Nothing
                    
                    End Sub
                    Billy Draper

                    Comment

                    Working...
                    X