Anyway, they were not necessary.
Hopefully you can work with this:
Code:
Function Main(ByVal Parm As String) As String hs.WaitSecs(3) ' Wait 3 seconds to allow the event to trigger and set the virtual device 'AlarmStatus' If hs.DeviceValueByName("AlarmStatus") = 0 Then Return "Goodnight" ' The alarm conditions are not true ' ' these are the virtual devices to be updated by the script '5281 Windows '8829 Doors 'Use the reference ID of the door or window sensor devices in the arrays below Dim array_windows() As String = {"4557", "4548", "4550", "4543", "4556", "4549", "4564", "4553", "4555", "4554", "4551", "4545", "4544", "4559", "4560", "4561", "4562", "4563"} Dim array_doors() As String = {"4565", "4542", "4558", "4566", "4532", "4531", "4552", "4523", "4522", "4528", "4527"} Dim windows_count As Integer = 0 Dim window_name As String = "" Dim wstr As String = "" Dim doors_count As Integer = 0 Dim door_name As String = "" Dim dstr As String = "" Dim dv As Object 'WINDOWS Try windows_count = 0 window_name = "" wstr = "" For Each devw As String In array_windows 'hs.writelog("Array", "Window " & window_name & " | Value " & hs.DeviceValue(devw)) If hs.DeviceValue(devw) = 1 Then windows_count = windows_count + 1 dv = hs.GetDeviceByRef(devw) window_name = dv.Name(hs) wstr = wstr & window_name & ", <br>" hs.WriteLog("DoorWindow", window_name & " Open") 'hs.writelog("DoorWindow", array_windows) End If Next If windows_count > 0 Then hs.SetDeviceValueByRef(5281, 100, True) hs.SetDeviceString(5281, wstr, True) Else hs.SetDeviceValueByRef(5281, 0, True) hs.SetDeviceString(5281, "All Windows Closed", True) End If hs.WriteLog("DoorWindow", "Window Count: " & windows_count) Catch ex As Exception hs.WriteLog("DoorWindow", "Error: " & ex.Message) End Try 'DOORS Try doors_count = 0 door_name = "" dstr = "" For Each devd As String In array_doors 'hs.writelog("Array", "Door " & door_name & " | Value " & hs.DeviceValue(devd)) If hs.DeviceValue(devd) = 1 Then dv = hs.GetDeviceByRef(devd) door_name = dv.Name(hs) doors_count = doors_count + 1 dstr = dstr & door_name & ", <br>" hs.WriteLog("DoorWindow", door_name & " Open") End If Next If doors_count > 0 Then hs.SetDeviceValueByRef(8829, 100, True) hs.SetDeviceString(8829, dstr, True) Else hs.SetDeviceValueByRef(8829, 0, True) hs.SetDeviceString(8829, "All Doors Closed", True) End If hs.WriteLog("DoorWindow", "Door Count: " & doors_count) Catch ex As Exception hs.WriteLog("DoorWindow", "Error: " & ex.Message) End Try If windows_count > 0 Then Return "Alarm is not set. The " & hs.DeviceString(5281).Replace("<br>", "") & " Windows are open. Do you want to bypass them or wait until they are all closed before setting the alarm?" ElseIf doors_count > 0 Then Return "Alarm is not set. The " & hs.DeviceString(8829).Replace("<br>", "") & " Doors are open. Do you want to bypass them or wait until they are all closed before setting the alarm?" ElseIf windows_count > 0 And doors_count > 0 Then Return "Alarm is not set. The " & hs.DeviceString(5281).Replace("<br>", "") & " Windows and " & hs.DeviceString(8829).Replace("<br>", "") & " Doors are open. Do you want to bypass them or wait until they are all closed before setting the alarm?" Else Return "Goodnight" End If End Function
Leave a comment: