Announcement

Collapse
No announcement yet.

[VB.NET] Poll All Devices In Order Recurring

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

  • [VB.NET] Poll All Devices In Order Recurring

    OK so this is probably stupid I don't know. I have all GE switches in my house that do not report status as well as thermostats that do not report status without polling them. Setting the timers to offset each other on each devices was a pain and always conflicted. I created a script to poll each device every 15 seconds. Just setup an event triggered on recurring intervals of 15 seconds. Set the parameters for the script to ("Main","24") where 24 is the last device number in Homeseer. In my homeseer setup, all my devices start with Q. I don't have a lot of devices so I haven't hit a limitation where the letter would be incremented I guess. Anyway feel free to try. Ask questions if you like. This is my first stab at scripting and by no means should this be scrutinized by a real developer. I probably suck at it. I learned it in like 1 hour.


    Code:
        Public Sub Main(ByVal Parms As String)
    
            'Setup variables for script
            Dim LastDevice
            Dim LastDeviceValue
            Dim ErrorCode
            Dim FinalDevice
            Dim Status
            Dim DeviceName
            Dim DevRef As Object
            Dim DevRefNum
            'Set this variable to the last device code
            FinalDevice = Parms
    
            'Get global variable status if it exists
            LastDevice = hs.GetVar("LastDevice")
            LastDeviceValue = LastDevice.ToString
    
            'Check to see if global variable is set to 1. If not do so.
            If LastDeviceValue = "Name not found" Then
                ErrorCode = hs.CreateVar("LastDevice")
                hs.SaveVar("LastDevice", 1)
                LastDevice = hs.GetVar("LastDevice")
                hs.WriteLog("Info", "Variable not set. Setting to 1")
            End If
    
            If LastDevice > FinalDevice Then
                hs.SaveVar("LastDevice", 1)
                LastDevice = hs.GetVar("LastDevice")
            End If
    
            hs.PollDevice("Q" + LastDevice.ToString)
            Status = hs.DeviceStatus("Q" + LastDevice.ToString)
            If Status = 2 Then
                Status = "On"
            ElseIf Status = 3 Then
                Status = "Off"
            Else
    
            End If
    
    
            Try
                DevRefNum = hs.GetDeviceRef("Q" + LastDevice.ToString)
                DevRef = hs.GetDeviceByRef(DevRefNum)
                DeviceName = DevRef.name
                Status = DevRef.dev_type_String
    
                '____________________________________________________________________________________
    
                'I was just using the below code to indicate in my log entry that it was a thermostat
                'If Status = "Z-Wave Thermostat" Then
                'Status = "Is a thermostat"
                'End If
    
                '________________________________________________________________________________________
    
                'Disable Logging Status
                'hs.WriteLog("Info", DeviceName + " " + Status + " Device Code Q" + LastDevice.ToString)
                LastDevice = 1 + LastDevice
                hs.SaveVar("LastDevice", LastDevice)
            Catch
                LastDevice = 1 + LastDevice
                hs.SaveVar("LastDevice", LastDevice)
                hs.WriteLog("Info", "Exception Polling Device Code Q" + LastDevice.ToString)
            End Try
    
    
        End Sub

    Ohhh yeah. I used the tenScripting package with VB Studio Express 2010. Works awesome!
Working...
X