Announcement

Collapse
No announcement yet.

Struggling with Example script

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Struggling with Example script

    Hi guys,

    I am new to scripting and struggling with the example script provided in the Sage documentation below.

    Public Sub mcShowDoorbell(ByVal host As String)
    Dim mcc As Object
    Try
    mcc = hs.Plugin("Sage MC Control")
    Catch Ex As Exception
    mcc = Nothing
    End Try
    If mcc Is Nothing Then
    hs.WriteLog("Error", "ERROR - could not get a reference to the “ & _
    “Media Center Controll Plug-In.")
    Exit Sub
    End If
    Dim respStr As String = mcc.richMsg(host, "HomeSeer", _
    "There is someone at the door", 30, "Done;Unlock", "modal", _
    "\\basement\netcam\Front Door_latest.jpg")
    If respStr = "Unlock" Then
    ' Code to unlock the door
    End If
    End Sub

    Now the first thing that is wrong or I think with this is that the example mcc = hs.Plugin("Sage MC Control") needs to be mcc = hs.Plugin("SageMCControl").

    My media centre name is IWYN. Do I change the mcShowDoorbell to IWYN? Do I need to create this script in VB.net or can I copy and paste it in the new event Advanced option for scripts? Do I need to save it as .vb or .txt?

    For testing and learning purposes I only want my kitchen light to come on when choosing the unlock on Media Centre, it's a X10 light and on number A5.

    Any help will be much appreciated!

    thanks

    #2
    You are correct about the plugin name needing to be changed. It was renamed after the example code had been created. What you'll want to do is save this function in a script file in your script folder. For example, save it to mc_util.vb. Then in your actions for your event, run a script action. Select mc_tuil.vb from the existing script drop-down. Then, in the optional parameters, put in ("mcShowDoorbell","IWYN"). Save the action. Now the action will call your script. To turn your light on you can do something like...

    Transmit("A5", "on")
    - Tom

    HSPro/Insteon
    Web Site
    YouTube Channel

    Comment


      #3
      thank you very much Tom!

      this is working perfectly now!

      Comment


        #4
        Hi Tom,

        If I want to pass an extra parameter say to not have the static message "There is someone at the door" in script below:

        Dim respStr As String = mcc.richMsg(host, "HomeSeer", _
        "There is someone at the door", 30, "Done;Unlock", "modal", _
        "\\homeauto\images\electricity.jpg")


        but to make these optional parameters dynamic ("mcShowDoorbell","IWYN").

        How would I go about it?

        thank you very much!

        Comment


          #5
          I don't think that the script action will allow you to pass multiple parameters. (I may be incorrect as I haven't tried this) However, there is a pretty easy work-around. Just pass in a single string separated by some character, say '|'. (I.e. "IWYN|My Message") Now inside your function you can get the values for each of these by using the split VB function. This will split a string into an array based on a separator character. Now use the first element in the array for your host parameter and the second for your message. Does that make sense?
          - Tom

          HSPro/Insteon
          Web Site
          YouTube Channel

          Comment

          Working...
          X