Announcement

Collapse
No announcement yet.

Turning on/changing HS-WD200 leds in a script

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

    Turning on/changing HS-WD200 leds in a script

    Hi all,
    Does anyone know how to turn on or change the status of the Homeseer Dimmer status LEDs from a script? I can do it with events but my goal is to link the color of several of the LEDs on this dimmer to the status of various doors, locks, garage doors etc in my house. I have come to the conclusion that using events to keep these leds synced with the status of the other devices in unwieldy. I just started experimenting with Tenscript and it seems amazing but doesn't seem to see the dimmer LED "devices". Any ideas?
    Thanks in advance.

    #2
    Originally posted by Marty_B View Post
    Hi all,
    Does anyone know how to turn on or change the status of the Homeseer Dimmer status LEDs from a script?
    Here is the code I use (hope I included everything relevant):

    Code:
    Imports System.Text
    Public Sub SetZParam(parms As String)
    ' Call SetZParam with: NodeID,ParameterNum,Value
    Dim param as String() = parms.Split(",")
    Dim HomeID as String = "EE51E66A" ' ZWave Network ID, found in ZWave Plugin setup
    Dim NodeID as String = param(0) ' ZWave NodeID (Not HS ref)
    Dim ParamNumber as String = param(1)
    Dim Value as String = param(2)
    Dim ConfigResult As Integer = 0
    Dim ConfigResultVal() As String = {" is Unknown"," is Successful"," has been Queued"," has Failed"}
    Try
    ConfigResult = hs.PluginFunction("Z-Wave", "", "Configuration_Set", New Object(){HomeID, Convert.ToByte(NodeID), Convert.ToByte(ParamNumber), Convert.ToByte(1), Convert.ToInt32(Value)})
    hs.WriteLog("Zwave Param", "Result of Parameter " + ParamNumber + " change to " + Value + " on Node " + NodeID + ConfigResultVal(ConfigResult))
    Catch ex As Exception
    hs.writelog("error", "ZWave Param: " & ex.Message.ToString)
    ' hs.WriteLog("error", "Result of Parameter " + ParamNumber + " change to " + Value + " on Node " + NodeID + ConfigResultVal(ConfigResult))
    End Try
    End Sub
    Public Sub WD200Led(parms As Object)
    ' Used to change the seven LED colors of the WD200 dimmer
    ' Input such as: Hall.7.Green or Garage.1.Red or All.All.Off or All.3.Red.X
    Dim params As String = ""
    if parms IsNot Nothing then params = LCase(parms.ToString)
    If Trim(params) = "" Then Exit Sub
    Dim parm As String() = params.Split(".")
    Dim sSwitch() As String = {"all", "car", "hall", "master", "patio"} ' My Names of the Switches
    Dim sNodes() As String = {"0", "34", "35", "53", "57"} ' The switches corresponding Zwave node id
    Dim sColors() As String = {"off", "red", "green", "blue", "magenta", "yellow", "cyan", "white"}
    Dim I As Integer = 0, J As Integer = 0, K As Integer = 0, L As Integer, iBlink As Integer = -1
    Do While I < sSwitch.Length
    If sSwitch(I) = parm(0) Then Exit Do
    I = I + 1
    Loop
    If I >= sSwitch.Length Then
    hs.WriteLog("error", "WD200 switch not found: " + parm(0))
    Exit Sub
    End If
    Do While J < sColors.Length
    if sColors(J) = parm(2) Then Exit Do
    J = J + 1
    Loop
    If J >= sColors.Length Then
    hs.WriteLog("error", "WD200 Invalid Color: " + parm(2))
    Exit Sub
    End If
    If parm(1) = "all" Then parm(1) = 0 ' All LEDs
    K = CInt(parm(1))
    If K < 0 Or K > 7 Then ' 1-7, or 0 (all)
    hs.WriteLog("error", "WD200 Invalid LED: " + parm(1))
    Exit Sub
    End If
    If parm.Length > 3 Then ' Fourth parameter exists, indicates blink
    If IsNumeric(parm(3)) Then ' Specifies blink rate (times 100ms)
    iBlink = CInt(parm(3))
    If iBlink > 0 And iBlink < 256 Then
    SetZParam(sNodes(I) + ",30," + CStr(iBlink))
    iBlink = SetBlink(K, True)
    Else
    iBlink = SetBlink(K, False)
    End If
    Else ' Something like "X", indicates to use previous blink rate
    iBlink = SetBlink(K, True)
    End If
    End If
    ' If hs.DeviceStringByName("Occupied") = "Vacation" Then J = 0
    If I = 0 Then ' All Switches
    I = 1
    Do While I < sNodes.Length
    If K = 0 Then ' All switches, all LEDs
    For L = 21 To 27
    SetZParam(sNodes(I) + "," + CStr(L) + "," + CStr(J))
    Next L
    Else ' All switches, specific LED
    If iBlink >= 0 Then SetZParam(sNodes(I) + ",31," + CStr(iBlink)) ' Turn on/off blinking
    SetZParam(sNodes(I) + "," + CStr(K + 20) + "," + CStr(J))
    End If
    I = I + 1
    Loop
    Else ' Specific Switch
    If K = 0 Then ' Specific Switch, All LEDs
    For L = 21 To 27
    SetZParam(sNodes(I) + "," + CStr(L) + "," + CStr(J))
    Next L
    Else ' Specific Switch, Specific LED
    SetZParam(sNodes(I) + "," + CStr(K + 20) + "," + CStr(J))
    End If
    End If
    End Sub

    Comment


      #3
      My apologies BTW, when I pasted the source in, the web site deleted my indentation.

      Comment


        #4
        Thank you very much. This is exactly what I was looking for. I am traveling today but I cant wait to get home to try this. No worries about the indentation.
        Thanks again.

        Comment


          #5
          Forgot the function "SetBlink":

          Code:
          Private Function SetBlink(ByVal iWho As Integer, ByVal bOn As Boolean) As Integer
          ' Sets the blink zwave parameter value for WD200 switches (byte 31), i.e with led's to blink
          ' iWho is 1-7, with 1 being the bottom LED.
          Dim d() As Integer = {0, 1, 2, 4, 8, 16, 32, 64}
          Dim buff As String = hs.GetVar("wd200blink")
          If buff = "" Then
          hs.CreateVar("wd200blink")
          buff = "0"
          End If
          Dim iBlink As Integer = CInt(buff)
          If bOn Then
          If (iBlink And d(iWho)) = 0 Then iBlink = iBlink + d(iWho)
          Else
          If (iBlink And d(iWho)) <> 0 Then iBlink = iBlink - d(iWho)
          End If
          hs.SaveVar("wd200blink", CStr(iBlink))
          Return iBlink
          End Function

          Comment


            #6
            Thanks again. When envoking this script from homeseer, I get the following log entries:
            Compiling script MartyTest.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.
            I also get multiple entries that say
            Compiling script MartyTest.vb: Reference to a non-shared member requires an object reference.
            I assume the latter is due to the former.
            Is there a file or something missing on my Homeseer machine?
            I will keep looking into it. Thanks again for your help.

            Comment


              #7
              You did not mention if this is on HS4 or HS3. I am still on HS3 (though it should still work on HS4).

              Do you have a "Sub Main" declared? When debugging scripts, I usually start with something small, then add stuff. When the compile stops working, I then have a limited area to look at.

              Maybe start with this:

              Code:
              Sub Main(parms As Object)
                hs.WriteLog("Testing","Main Called")
              End Sub
              Then add SetBlink,then SetZParam, etc.

              Comment


                #8
                I am using HS4. I have successfully run other simple scripts in the process of learning as I am not a programmer. I did not have a Sub Main declared. I will try your suggestions.
                Thanks again for your help.

                Comment


                  #9
                  aa6vh, I found an errant "Class" statement in my script. I removed it and all is well. Thanks very much again for your help.

                  Comment

                  Working...
                  X