Announcement

Collapse
No announcement yet.

Device ID returning -1

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

  • Device ID returning -1

    I'm tinkering with an example from the HS documentation... getting the ID of a device by device name is turning out to be problematic for some reason. I'm populating a variable with the device name and when the code executes the device ID value is -1 but when I replace the variable with the actual device name text that is populating the variable I get the device ID.

    Code:
    Dim objCAPIControl As CAPIControl
    Dim dvRef As Integer
    dvRef = hs.GetDeviceRefByName("" & room & device & "")
    hs.WriteLog("BuildRequest()", "deviceID: " & dvRef)
    hs.WriteLog("BuildRequest()", "devicename: " & room & device)
    objCAPIControl = hs.CAPIGetSingleControlByUse(dvRef, ePairControlUse._On)
    If objCAPIControl IsNot Nothing Then
       hs.CAPIControlHandler(objCAPIControl)
    End If
    From the log using the variables

    deviceID: -1
    devicename: kitchen light

    From the log using entered text

    deviceID: 81
    devicename: kitchen light

    I'm at a loss why I'm getting a -1 value when I'm populating with valid device values

  • #2
    Quickly looking at this it appears your are passing the string KitchenLight vs Kitchen Light. Change the GetDevice to room & " " & device....

    Comment


    • #3
      bsobel - When I use the two variables together I made sure there was a space incorporated with one of them... but I manually added a space as you suggested and didn't get a different result.... still returning -1

      Comment


      • #4
        Finally discovered the cause. Going line by line, I found a Trim() function was being applied to the variables in a parsing routine that gets called. Removing that resolved the issue.

        Comment

        Working...
        X