Announcement

Collapse
No announcement yet.

Dynamic name in function?

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

    Dynamic name in function?

    Okay I am having a bit of difficulty here. Trying to make a loop through all my lighting devices and having an issue not being able to reference the light names from an array. Hoping someone can tell me what I am doing wrong. This is obviously only a section of the code, but if i can get this part to work the rest is already working. I tried doing the double quotes in the array name already """Dallas Server Rack""" that didn't work either. Can anyone see what I am doing wrong?

    ***This code works***

    hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, "Dallas Server Rack", 255, "0,255,0", Nothing})

    ****************************
    However if i put the name in an array and try and run this nothing happens

    Dim Lind As Integer = 0

    Dim device() As String = {"Dallas Underbed", "Dallas Front", "Dallas Frontdoor", "Dallas Backdoor", "Front1", "Front2", "Front4", "Front3", "LR TV", "Gameroom TV", "Adams Office TV", "Master bedroom TV", "Under Bed", "Server Rack", "Fish Tank", "Media room accent light 1", "Dallas living room lamp", "Dallas living room 2", "Dallas living room 3", "Dallas living room 1", "Dallas Office 3", "Dallas Office 1", "Dallas Office 2", "Dallas Master Bathroom Shelf", "Dallas Master Bath", "Dallas Server Rack"}

    Lind = 25

    hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, "0,255,0", Nothing})

    *******************************

    Thanks in advance.


    #2
    Please use [Code] tags to make it easier to read.

    Comment


      #3
      Maybe try:

      Code:
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, " & device(Lind) & ", 255, "0,255,0", Nothing})
      Jon

      Comment


        #4
        Originally posted by jon00 View Post
        Maybe try:

        Code:
         hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, " & device(Lind) & ", 255, "0,255,0", Nothing})
        That did it, thank you

        Comment


          #5
          Originally posted by jon00 View Post
          Maybe try:

          Code:
           hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, " & device(Lind) & ", 255, "0,255,0", Nothing})
          Any Ideas how to do the same for the RGB settings? I have tried every possible combination with the " & method

          Comment


            #6
            Please give examples of what you have tried.
            Jon

            Comment


              #7
              Okay I was going to run through them all once again to ensure I was posting accurate information and the entire thing stopping to working then randomly working or not working with minor changes here and there. I finally found the root of all these problems one of my device names was the name of the room not the device in the room. Everything is working now without any "" Below is my code if anyone is trying to do the same sets light colors based on the date for some holiday themed lighting. I am not a software engineer and I know this could be done much more efficiently and cleanly several variables don't even do anything, this went through many variations to get to this point and honestly its working so not going to mess with it anymore. Thank you jon00 for your help on this!

              Code:
              Public Sub Main(ByVal Parms As Object)
              
              
              Dim ParmArray(25) As String
              Dim MyDate As Date
              Dim today As String
              Dim mtoday As Integer
              Dim dtoday As Integer
              Dim device() As String = {"Dallas Underbed", "Dallas Front", "Dallas Frontdoor", "Dallas Backdoor", "Front1", "Front2", "Front3", "Front4", "LR TV", "Gameroom TV", "Adams Office TV", "Master bedroom TV", "Under Bed", "Server Rack", "Fish Tank", "Media room accent light 1", "Dallas living room lamp", "Dallas living room 2", "Dallas living room 3", "Dallas living room 1", "Dallas Office 3", "Dallas Office 2", "Dallas Office 1", "Dallas Master Bathroom Shelf", "Dallas Master Bathroom Shelf", "Dallas Server Rack"}
              Dim deviceStat() As String = {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"}
              Dim deviceNew() As Double = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
              Dim deviceref() As Integer = {38, 45, 52, 59, 371, 378, 392, 385, 445, 452, 459, 466, 473, 485, 496, 508, 1688, 1703, 1710, 1717, 1724, 1738, 1731, 2056, 2056, 2070}
              Dim numofdevices As Integer = 25
              Dim x As Integer = 0
              'Dim y As Integer = 0
              'Dim rc As Integer = 0
              Dim Lind As Integer = 0
              Dim C1 As String = "255,0,0"
              Dim C2 As String = "0,255,0"
              Dim CNorm As String = "239,235,216"
              Dim Normalday As Integer = 1
              
              MyDate = Date.Now
              today = MyDate.ToShortDateString
              mtoday = MyDate.Month
              dtoday = MyDate.Day
              For x = 0 To numofdevices
              deviceStat(x) = hs.DeviceVSP_GetStatus(deviceref(x), hs.DeviceValue(deviceref(x)), HomeSeerAPI.ePairStatusControl.Status)
              
              If deviceStat(x) = "Off" Then
              deviceNew(x) = 0
              Else
              deviceNew(x) = 1
              End If
              Next
              
              '-------------------------------------------Christmas-------------------------------------------------------------
              
              If mtoday = 12 Then
              C1 = "255,0,0"
              C2 = "0,255,0"
              Normalday = 0
              'hs.WriteLog("test", "Christmas")
              '-------------------------------------------Hallowean-----------------------------------------------------
              ElseIf mtoday = 10 And dtoday >= 17 Then
              C1 = "255,110,19"
              C2 = "255,110,19"
              Normalday = 0
              'hs.WriteLog("test", "Halloween")
              '--------------------------------------------------------------------------------------patriot holidays----------------------------------------------------------------------------
              
              ElseIf mtoday = 5 And dtoday >= 27 And dtoday <= 31 Or mtoday = 7 And dtoday >= 1 And dtoday <= 4 Or mtoday = 11 And dtoday >= 9 And dtoday <= 11 Then
              C1 = "255,0,0"
              C2 = "0,0,255"
              Normalday = 0
              'hs.WriteLog("test", "PAT Holiday")
              '----------------------------------------------------------------------------St patricks day -------------------------------------------------------------
              ElseIf mtoday = 3 And dtoday >= 15 And dtoday <= 17 Then
              C1 = "0,255,0"
              C2 = "0,255,0"
              Normalday = 0
              'hs.WriteLog("test", "STP day")
              '----------------------------------------------------------------------------Normal Day -------------------------------------------------------------
              Else
              C1 = "0,0,255"
              C2 = "0,255,0"
              Normalday = 1
              'hs.WriteLog("test", "Normal day")
              
              End If
              
              
              If Normalday = 0 Then
              For Lind = 0 To numofdevices
              If x Mod 2 = 0 Then
              If deviceNew(Lind) = 0 Then
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), Nothing, C1, Nothing})
              hs.PluginFunction("JowiHue", "", "SetLightsOff", {False, device(Lind)})
              Else
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, C1, Nothing})
              End If
              Else
              If deviceNew(Lind) = 0 Then
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), Nothing, C2, Nothing})
              hs.PluginFunction("JowiHue", "", "SetLightsOff", {False, device(Lind)})
              Else
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, C2, Nothing})
              End If
              End If
              
              Next
              Else
              
              For Lind = 0 To numofdevices
              If Lind = 4 Or Lind = 5 Or Lind = 6 Or Lind = 7 Then
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, CNorm, Nothing})
              'hs.WriteLog("test", CStr(Lind))
              Else
              If x Mod 2 = 0 Then
              If deviceNew(Lind) = 0 Then
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), Nothing, C1, Nothing})
              hs.PluginFunction("JowiHue", "", "SetLightsOff", {False, device(Lind)})
              'hs.WriteLog("test", CStr(Lind))
              Else
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, C1, Nothing})
              'hs.WriteLog("test", CStr(Lind))
              End If
              Else
              If deviceNew(Lind) = 0 Then
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), Nothing, C2, Nothing})
              hs.PluginFunction("JowiHue", "", "SetLightsOff", {False, device(Lind)})
              'hs.WriteLog("test", CStr(Lind))
              Else
              hs.PluginFunction("JowiHue", "", "SetLightsRGB", {False, device(Lind), 255, C2, Nothing})
              'hs.WriteLog("test", CStr(Lind))
              End If
              End If
              End If
              
              Next
              
              
              
              End If
              
              
              
              
              
              
              End Sub​

              Comment

              Working...
              X