Announcement

Collapse
No announcement yet.

[VB.NET] Simple device status watchdog

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

  • [VB.NET] Simple device status watchdog

    I had an issue where a particular interface would lockup and I would not know HS was not receiving new data. Here is a very simple watchdog script to ensure devices are updating according to your schedule. This script looks at the last time a device was changed and reports if it occured in or outside the time window you set. Keep in mind the device value/status must actually change.

    Run this in a recurring event as frequently as you like, and pass the parameters for device code and time window as noted below.

    Suggestions for improvement are welcome! Thanks to other board members for code tips!

    -BD

    Code:
     
    'Simple watchdog script to notify user when a device is not being updated in a certain period of time.
    'Call using parameters for device code and time window in minutes, eg: ("Main","x50,60"), where x50 should
    'be changed to the device code of your choice and 60 should be changed to the number of minutes to
    'check since the device has been updated. In this example, the device is checked to see if it has been
    'updated within the previous 'hour. Make sure to update your email addresses in the If block below.
    'Submitted 7-24-12, BrunDog
    
    Sub Main(Parm as object)
    
    Dim LastUpdate as Date
    Dim RefNum
    Dim Device
    Dim DeviceCode
    Dim Parms() as String
    Dim Mins as Integer 
    
    Parms = Split(Parm.ToString,",")
    DeviceCode = Parms(0)
    Mins = Parms(1)
    
    LastUpdate = hs.DeviceLastChange(DeviceCode)
    Device = hs.GetDeviceByRef(hs.GetDeviceRef(DeviceCode))
    
    If DateDiff("n",LastUpdate,Now) > Mins then
         hs.WriteLog("Status Watchdog", "The " & Device.location & " " & Device.name & " status has not been updated since " & LastUpdate & ".")
         hs.SendEmail("youremail@yourISP.com","youremail@yourISP.com","** HomeSeer Notice **","The " & Device.location & " " & Device.name & " status has not been updated since "& LastUpdate & ".")
    Else
         hs.WriteLog("Status Watchdog", "The " & Device.location & " " & Device.name & " status has been updating normally.")
    End If
    
    End Sub
Working...
X