
Imports HomeSeerAPI   ' @DONOTEXPORT
Public Class EnterFrontDoor
    Public Sub Main(ByVal Parms As Object)
        Dim ParmArray(10) As String
        '' Extract script parameters into ParmArray()
        ParmArray(0) = ""
        If Parms.ToString.Contains("|") Then
            ParmArray = Parms.ToString.Split(Convert.ToChar("|"))
        Else
            ParmArray(0) = Parms.ToString
        End If

        hs.WriteLog("EnterFrontDoor", "ScriptRunning")

        '' Check if Armed Away and Front Door Violated
        If hs.DeviceValueEx(hs.GetDeviceRefByName("Elk M1 Area UltraM1G3 Plugin Area 01 [Tenholders]")) = 1 Then
            If hs.DeviceValueEx(hs.GetDeviceRefByName("Elk M1 Zone UltraM1G3 Plugin Zone 017 [Front Door]")) = 3 Then
                hs.CAPIControlHandler(hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Dining Room Ceiling"), True, "Activate", False, False))
            End If
        End If
    End Sub
End Class

Public Class MyTest
    Public Sub Main(ByVal Parms As Object)
        Dim ParmArray(10) As String
        '' Extract script parameters into ParmArray()
        ParmArray(0) = ""
        If Parms.ToString.Contains("|") Then
            ParmArray = Parms.ToString.Split(Convert.ToChar("|"))
        Else
            ParmArray(0) = Parms.ToString
        End If

        Dim s As String
        s = hs.DeviceVSP_GetStatus(1121, hs.DeviceValue(1121), ePairStatusControl.Status)
        MsgBox(s)
    End Sub
End Class


Class videoToggleDevice
    Public Sub Main(ByVal Parms As String)
        ''
        '' Toggle the Specified Device ON/OFF
        ''   Anything but OFF is considered ON
        ''
        '' Specify the Device Name, including Locations, as a Parm
        ''
        Dim theDevice As String
        Dim ccOFF As CAPIControl
        Dim ccON As CAPIControl
        Dim theOffLabel As String
        Dim devStatus As String
        Dim ccResponse As CAPIControlResponse
        '' Get Device from the Parms
        theDevice = Parms.ToString
        '' Get the CAPI ControlUse value for OFF
        ccOFF = hs.CAPIGetSingleControlByUse(hs.GetDeviceRefByName(theDevice), ePairControlUse._Off)
        If IsNothing(ccOFF) Then
            hs.WriteLog("ToggleDevice", "ControlUse not define for device: " & theDevice)
            Exit Sub
        End If
        theOffLabel = ccOFF.Label
        '' Get the Device CAPIStatus
        devStatus = hs.CAPIGetStatus(hs.GetDeviceRefByName(theDevice)).Status
        '' Determine Current Status, and toggle it
        If theOffLabel.ToUpper.Trim = devStatus.ToUpper.Trim Then
            '' Currently OFF, turn it ON
            ccON = hs.CAPIGetSingleControlByUse(hs.GetDeviceRefByName(theDevice), ePairControlUse._On)
            ccResponse = hs.CAPIControlHandler(ccON)
            If ccResponse <> CAPIControlResponse.All_Success Then
                hs.WriteLog("ToggleDevice", "CapiControlHandler Failed, ccResponse: " & ccResponse.ToString)
            End If
        Else
            '' NOT OFF, turn it OFF
            ccResponse = hs.CAPIControlHandler(ccOFF)
            If ccResponse <> CAPIControlResponse.All_Success Then
                hs.WriteLog("ToggleDevice", "CapiControlHandler Failed, ccResponse: " & ccResponse.ToString)
            End If
        End If
    End Sub
End Class
