I am very green when it comes to scripting, and asking some guidance here. I have created a script to monitor my doors and windows in a single virtual device. I have it all working as expected, but have decided to go one step further and have the device string display which door/window is actively open. I can get it to show one door open (lowest #'d device), but it won't show multiple doors. I suspect this is because the way I have it setup, it's looking at the first entry from the Array I built. (It's also just showing the device #, but that's because I am referencing the devices by their ref ID. I didn't think of this new requirement to display the door names until after the fact . I think I just have to change the script to look at the names of the devices, vs the ID).
Can anyone help?
Can anyone help?
Code:
'Define Windows/Doors Array '604 Master Bath Right Window '600 Master Bath Left WIndow '502 Master Bedroom Right Window '498 Master Bedroom Left Window '394 Loft Window '55 Dining/Piano Windows '53 Laundry/TV Windows '58 Garage Door from Laundry '54 Front Door '57 Back Door dim array_windows() as integer = {604,600,502,498,394,55,53} dim array_doors() as integer = {58,54,57} dim windows_count as integer = 0 dim doors_count as integer = 0 dim locked as integer = 0 dim door_name as string = "" sub windows(ByVal Parms as Object) Try windows_count = 0 'Counts thru array to check if any windows are opened for each devw as integer in array_windows if hs.DeviceValueEx(devw) = 255 or hs.DeviceValueEx(devw) = 100 then windows_count = windows_count + 1 Else If hs.DeviceValueEx(devw) = 0 then 'No windows open end if next If windows_count > 0 then 'hs.writelog ("Window Count", windows_count & " windows are opened") hs.SetDeviceValueByRef(171,100,true) hs.SetDeviceString(171, "Windows Opened",true) Else 'hs.writelog ("Window Count", "All windows are closed") hs.SetDeviceValueByRef(171,0,true) hs.SetDeviceString(171, "All Windows Closed",true) End If Catch ex As Exception hs.WriteLog ("Array", "Error: " & ex.Message) End Try End Sub sub doors(ByVal Parms as Object) Try doors_count = 0 locked = hs.DeviceValueEx(1069) for each devd as integer in array_doors if hs.DeviceValueEx(devd) = 255 or hs.DeviceValueEx(devd) = 100 then doors_count = doors_count + 1 door_name = devd Else If hs.DeviceValueEx(devd) = 0 then 'No doors open end if next If doors_count > 0 then hs.SetDeviceValueByRef(170,100,true) hs.SetDeviceString(170, door_name & " Opened",true) ElseIf (doors_count = 0 and locked = 255) then hs.SetDeviceValueByRef(170,150,true) hs.SetDeviceString(170, "All Doors Closed and Locked",true) Else hs.SetDeviceValueByRef(170,0,true) hs.SetDeviceString(170, "All Doors Closed",true) End If Catch ex As Exception hs.WriteLog ("Array", "Error: " & ex.Message) End Try End Sub
Comment