Announcement

Collapse
No announcement yet.

Script that checks for all devices to make sure they are working

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

  • Script that checks for all devices to make sure they are working

    I have several devices like zwave or motion sensors that stop working. I'm looking for a script that goes thru the list of devices and warn when the device has not been updated for xx number of minutes. Really bad on scripts, does anyone have such a script that is willing to share?

    Thanks,
    Aldo

    Sent from my SM-G935V using Tapatalk


  • #2
    I should be able to modify one of my existing scripts tonight if no one posts anything before then. How do you want it to notify you? An email?
    HS 3.0.0.532: 1963 Devices 1141 Events
    Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

    Comment


    • #3
      I would love to see something like this for Batteries in particular. I have several Schlage locks with have awful battery level reporting. They will report good battery (over 50% for example), up until the moment they die. So the battery levels can all look O.K., but they won't work. Something like this that would allow checking if the battery has failed to report in, e.g., 24 hours, would be quite useful.

      Comment


      • #4
        For z-wave devices, there is the SDJ-Health plugin that will do this for battery powered z-wave devices already.

        I have a script ready which logs to the HS log, but does not deal with notifications yet. It will check all devices and any children and determine if it has not seen any updates from it within the specified interval. I've only tested it against the z-wave plugin so far and am doing more checks
        HS 3.0.0.532: 1963 Devices 1141 Events
        Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

        Comment


        • #5
          Here's the start of a script. Call it from an event with 5 parameters (plugin,number of minutes,location,location2,Battery). If you want to check devices for all plugins, for all values of location or all values of location2, then specify "all" for those values. For Battery, put "True" if you only want to check battery/non-status devices, or "False" if you want to check non-battery devices. Right now you can't check both at the same time. Note that not all plugins set that value consistently, so you may get inconsistent results. A couple of sample screen shot son how to call the script is shown below. It only logs output to the HS Log for now.

          Code:
          'This script checks devices for a given plugin to determine whether they have been updated within the last X minutes.
          
          Sub Main(ByVal Parms As String)
          
              Dim Debug As Boolean = False                        'Set to True to show more logging.  Set to False to suppress most logging.
              Dim logName As String = "Device Check"
          
              Dim ParmArray() as String
              ParmArray = Parms.ToString.Split(",")
              dim Plugin as String = ParmArray(0).ToLower            'plugin name to check only devices owned by that plugin
              dim CheckTime as Integer
              If ParmArray(1) = Nothing Then                        'time in minutes for which the script checks to see if it has had any updates
                  CheckTime = 1440                                'default to 1 day
              Else
                  CheckTime = CInt(ParmArray(1))    
              End If
              dim Location as String = ParmArray(2).ToLower        'specify the location value to only check devices that match that.  Use "all" or leave blank to check all devices.
              dim Location2 as String = ParmArray(3).ToLower        'specify the location2 value to only check devices that match that.  Use "all" or leave blank to check all devices.
              dim Battery As Boolean = CBool(ParmArray(4))        'specify whether to check battery (True) (non status) devices or non-battery (False).
          
              If Location = "" Then Location = "all"
              If Location2 = "" Then Location2 = "all"
              If CheckTime = 0 Then CheckTime = 1440                'default to 1 day
              If Plugin = "" Then Plugin = "all"
          
              Dim LastChange As Date
              Dim TimeDifference As TimeSpan
              Dim ShortestTimeDifference As TimeSpan
              Dim LastChangeChild As Date
              Dim TimeDifferenceChild As TimeSpan
              Dim ChildDevices() As Integer
              Dim i As Integer
              Dim j As Integer
          
              Try
                  Dim dv As Scheduler.Classes.DeviceClass
                  Dim dvchild As Scheduler.Classes.DeviceClass
                  Dim EN As Scheduler.Classes.clsDeviceEnumeration
                  EN = hs.GetDeviceEnumerator
          
                  If Debug Then hs.writelog(logName, "Checking Devices")
          
                  Do
                      j = 0
                      dv = EN.GetNext
                      If dv Is Nothing Then Continue Do
                      If (dv.Interface(Nothing).ToLower = Plugin Or Plugin = "all") And (dv.Location(Nothing).ToLower = Location Or Location = "all") And (dv.Location2(Nothing).ToLower = Location2 Or Location2 = "all") And dv.Status_Support(Nothing) = Not(Battery) And dv.Relationship(Nothing) < 4 Then
                          LastChange = dv.Last_Change(Nothing)
                          TimeDifference = Now - LastChange
                          If TimeDifference.TotalMinutes > CheckTime Then
                              If Debug Then hs.writelog(logName & " Debug", "Device: " & dv.Name(Nothing) & " (" & dv.Ref(Nothing) & ") Result: " & CStr(TimeDifference.TotalMinutes) & " minutes" )
                          Else
                              j = j + 1
                              If Debug Then hs.writelog(logName & " Debug", "Device: " & dv.Name(Nothing) & " (" & dv.Ref(Nothing) & ") Result: " & CStr(TimeDifference.TotalMinutes) & " minutes" )
                          End If
                          ShortestTimeDifference = TimeDifference
                          i = 0
                          ChildDevices = dv.AssociatedDevices(Nothing)
                          If uBound(ChildDevices) > 0 Then
                              For i = 0 To uBound(ChildDevices)
                                  dvchild = hs.GetDeviceByRef(ChildDevices(i))
                                  If dvchild Is Nothing Then Continue For
                                  LastChangeChild = dvchild.Last_Change(Nothing)
                                  TimeDifferenceChild = Now - LastChangeChild
                                  If TimeDifferenceChild.TotalMinutes > CheckTime Then
                                      If Debug Then hs.writelog(logName & " Debug", "Child Device: " & dvchild.Name(Nothing) & " (" & dvchild.Ref(Nothing) & ") Result: " & CStr(TimeDifferenceChild.TotalMinutes) & " minutes" )
                                  Else
                                      j = j + 1
                                      If Debug Then hs.writelog(logName & " Debug", "Child Device: " & dvchild.Name(Nothing) & " (" & dvchild.Ref(Nothing) & ") Result: " & CStr(TimeDifferenceChild.TotalMinutes) & " minutes" )
                                  End If
                                  If TimeDifferenceChild < ShortestTimeDifference Then ShortestTimeDifference = TimeDifferenceChild
                              Next
                              ChildDevices = Nothing
                          Else
                              'No Children
                          End If
                          If j = 0 Then 'the device or its children has not been udated within the specified interval
                              hs.writelog(logName, "Device: " & dv.Name(Nothing) & " (" & dv.Ref(Nothing) & ") has not been updated for over " & CStr(Math.Truncate(ShortestTimeDifference.TotalMinutes)) & " minutes" )
                          Else
                              If Debug Then hs.writelog(logName, "Device: " & dv.Name(Nothing) & " (" & dv.Ref(Nothing) & ") was updated " & CStr(Math.Truncate(ShortestTimeDifference.TotalMinutes)) & " minutes ago." )
                          End If
                      End If
          
                  Loop Until EN.Finished
          
                  If Debug Then hs.writelog(logName, "Finished Checking Devices")
          
              Catch ex As Exception : hs.writelog(logName, "Exception: " & ex.message)
              End Try
          
          End Sub
          Click image for larger version  Name:	Capture2.JPG Views:	1 Size:	16.0 KB ID:	1260966
          Click image for larger version  Name:	Capture.JPG Views:	1 Size:	19.4 KB ID:	1260958
          HS 3.0.0.532: 1963 Devices 1141 Events
          Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

          Comment


          • #6
            Sparkman,
            I was checking one of the other posting and I was thinking how greatful we are to have you as part of this board, not sure about the others but I really appreciate you helping us. You take lot of your time and dedicate it to us, we know how precious that commodity is, thank you. I will check the script tomorrow, I will keep you posted.

            P. S. Of course there are many others like you that are always willing to help, so thanks all.

            Aldo

            Sent from my SM-G935V using Tapatalk

            Comment


            • #7
              aldo Thanks for the kind words! Let me know how the script works for you and then we can look at the notification piece.

              Cheers
              Al
              HS 3.0.0.532: 1963 Devices 1141 Events
              Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

              Comment


              • #8
                Sparkman, I did not fully tested it but so far the plugin works like a charm. One question, by plugin, do you mean the plugin name from the plug-ins list?
                Brainstorming about the notification, what about another param field like E for email notification or V for virtual device. Could you also filter for device name so I could run it for a specific name of the device. Great job.

                Aldo

                Comment


                • #9
                  Originally posted by aldo View Post
                  Sparkman, I did not fully tested it but so far the plugin works like a charm. One question, by plugin, do you mean the plugin name from the plug-ins list?
                  Brainstorming about the notification, what about another param field like E for email notification or V for virtual device. Could you also filter for device name so I could run it for a specific name of the device. Great job.

                  Aldo
                  Thanks Aldo, yes the plugin name from the list (shown on the advanced tab of the devices as well). Yes, could add another parameter for notification options. For doing single devices (based on name or reference ID), I'd probably write another script, rather than trying to make this one work for that scenario. My availability for the next 6 days or so will be limited, although will have some cycles here and there.

                  Cheers
                  Al
                  HS 3.0.0.532: 1963 Devices 1141 Events
                  Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                  Comment


                  • #10
                    Al, absolutely not a problem, happy holidays.

                    Aldo

                    Sent from my SM-G935V using Tapatalk

                    Comment


                    • #11
                      Originally posted by sparkman View Post
                      Here's the start of a script. Call it from an event with 5 parameters (plugin,number of minutes,location,location2,Battery). If you want to check devices for all plugins, for all values of location or all values of location2, then specify "all" for those values. For Battery, put "True" if you only want to check battery/non-status devices, or "False" if you want to check non-battery devices. Right now you can't check both at the same time. Note that not all plugins set that value consistently, so you may get inconsistent results. A couple of sample screen shot son how to call the script is shown below. It only logs output to the HS Log for now.
                      ...
                      I've written scripts that check if any of my devices' last update time is more than x minutes ago, and if so, send me pushover message.
                      Great for things like HSM200 sensors, which sometimes people unplug (so if an HSM200's current status is "Motion" [when person was unplugging it] but it's been more than x minutes since its status changed, then chances are someone unplugged it.

                      However, I do have a number devices that, under normal conditions, can go days or weeks without changing status. For example: water valve, devices in basement (noone may go down there for days), etc. I'd prefer not getting email or text for these devices if they are okay. So, I was wondering if it were possible to do something like:

                      If minutesSinceLastUpdate > myThreshold Then
                      ping device
                      If ping fails Then
                      send email or Pushover text
                      End if
                      Else
                      hs.WriteLog("Info", "Device " & devName " & " has not changed state in a while, but it is okay, so do not send email.)
                      End If

                      My question is: what is a good way to "ping" Z-Wave devices just as a sanity check to make sure they are reachable?
                      The "Z-Wave" tab in Device Configuration has a 'Test Connectiivity" button. What does it do underneath the covers, and would it be a good way to check if a device is reachable?



                      Comment


                      • #12
                        Originally posted by randman View Post
                        My question is: what is a good way to "ping" Z-Wave devices just as a sanity check to make sure they are reachable?
                        The "Z-Wave" tab in Device Configuration has a 'Test Connectiivity" button. What does it do underneath the covers, and would it be a good way to check if a device is reachable?
                        Test Connectivity works as a good way to ping a z-wave device to see if it responds. There's a script here to poll all of your z-wave listening devices: https://forums.homeseer.com/forum/li...ng-all-devices. The intent of the script was to ensure device statuses were up to date if the z-wave plugin/HS had been shutdown for a while.
                        HS 3.0.0.532: 1963 Devices 1141 Events
                        Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                        Comment


                        • #13
                          Originally posted by sparkman View Post

                          Test Connectivity works as a good way to ping a z-wave device to see if it responds. There's a script here to poll all of your z-wave listening devices: https://forums.homeseer.com/forum/li...ng-all-devices. The intent of the script was to ensure device statuses were up to date if the z-wave plugin/HS had been shutdown for a while.
                          Thanks. I’ll play around and see if I can use PollResult in your script to discern if a poll failed or not, and if it failed send a pushover message or email.

                          Comment

                          Working...
                          X