Announcement

Collapse
No announcement yet.

Monthly Low Battery Check

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

    #61
    Originally posted by adeux View Post

    Hi,

    thanks for the response. At the moment the device is a MQTT feed so that there are no status graphics. The OK and Low values come from the sensors manufacturer spec. As the batteries are new it is currently displaying OK.

    The other alternative is to do some preprocessing in the MQTT feed and allocate arbitrary numeric values to OK eg 100% and Low eg 5%, but that is a bit of a kludge.

    A
    Most of the system relies on numeric values to trigger events/etc so while the script could special case the OK and Low strings, I think you'll find things fit more naturally in the system if you indeed mapped those values to some numeric values (this way they would work in events, etc as well).

    Comment


      #62
      Originally posted by mwaite View Post
      Battery Report Script

      I added so many battery devices recently, I wanted a better way to report battery status w/o having to identify each device manually.

      I created a script that will email a battery report for all 'battery' type devices in HS3.

      ...

      To use, open the vb script with your favorite vb/txt editor, configure the first four lines, that's all that's to it. No attributes need to be sent to the script.

      The script can email the battery report as an attachment, or as the message body in the email [ReportAsAttachment = True/False].

      It defaults with a sort by lowest battery values first. It includes the device's 'Last Changed' value, so you can determine if the device is or is not reporting as expected.

      In the printout above, the last of my battery devices is reporting "ERROR". I discovered this device has an 'Invalid' range (as observed in device management) - so this is helpful to know as well.

      Note, the formatting is based on fixed-font spacing. So the attachment report looks pretty decent when viewed in Notepad, but the email body report viewed in Outlook loses some spacing characteristics. I'm over trying to clean this up any further - lol.

      Remove the .txt extension from the attached.
      I tried this on HS3 standard and get the following.
      Dec-30 9:54:37 AM BatteryReport Battery report created.
      Dec-30 9:54:37 AM BatteryReport ERROR: Exception in script: Failed to compare two elements in the array.
      No Report was found and nothing mailed.

      Here are the first 4 lines with the e-mail addresses edited out:
      Code:
          Dim filename As String = "/home/pi/Beta/HomeSeer/BatteryReport.html" ' full path and filename of report (if sending report as an email attachment)
          Dim mailTo As String = "xxx.xxx@xxxxx.com" ' email TO address
          Dim mailFrom As String = "xxxxxxxxx@gmail.com" ' email FROM address
          Dim ReportAsAttachment As Boolean = False ' set to 'True' if report should be emailed as a file (attachment), set to 'False' if report should be in email body
      Any ideas?

      It seems that with just a little editing this could be used to display just about any devices based on type and the data. Interesting.
      HomeSeer Version: HS3 Standard Edition 3.0.0.548
      Linux version: Linux auto 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
      Number of Devices: 484 | Number of Events: 776

      Enabled Plug-Ins: 3.0.0.13: AirplaySpeak | 2.0.61.0: BLBackup
      3.0.0.70: EasyTrigger | 1.3.7006.42100: LiftMaster MyQ
      4.2.3.0: mcsMQTT | 3.0.0.53: PHLocation2 | 0.0.0.47: Pushover 3P
      3.0.0.16: RaspberryIO | 3.0.1.262: Z-Wave

      Z-Net version: 1.0.23 for Inclusion Nodes
      SmartStick+: 6.04 (ZDK 6.81.3) on Server

      Comment


        #63
        Originally posted by Timon View Post

        I tried this on HS3 standard and get the following.
        Dec-30 9:54:37 AM BatteryReport Battery report created.
        Dec-30 9:54:37 AM BatteryReport ERROR: Exception in script: Failed to compare two elements in the array.
        No Report was found and nothing mailed.

        Here are the first 4 lines with the e-mail addresses edited out:
        Code:
        Dim filename As String = "/home/pi/Beta/HomeSeer/BatteryReport.html" ' full path and filename of report (if sending report as an email attachment)
        Dim mailTo As String = "xxx.xxx@xxxxx.com" ' email TO address
        Dim mailFrom As String = "xxxxxxxxx@gmail.com" ' email FROM address
        Dim ReportAsAttachment As Boolean = False ' set to 'True' if report should be emailed as a file (attachment), set to 'False' if report should be in email body
        Any ideas?

        It seems that with just a little editing this could be used to display just about any devices based on type and the data. Interesting.
        The first line should contain the complete path to the batter report file, example:
        Code:
        Dim filename As String = "C:\Program Files (x86)\HomeSeer HS3\BatteryReport.html" ' full path and filename of report
        If you still have the issue then let's determine which device is the culprit, add the following immediately after the first Catch ex As Exception statement (after line 67):
        Code:
        hs.WriteLog("BatteryReport", "Device issue with RefID: " &  dv.Ref(Nothing).ToString)
        Mike

        Comment


          #64
          Incase it makes a difference I'm on Linux so the path was correct as Linux doesn't have drive letters and the path separators are "/" not "". That said I don't see any reason that Linux paths shouldn't work.

          I tried the debug line and here is the result:
          Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: 'dv' is not declared. It may be inaccessible due to its protection level.
          Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
          Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
          Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: The import 'System.Core' could not be found.
          HomeSeer Version: HS3 Standard Edition 3.0.0.548
          Linux version: Linux auto 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
          Number of Devices: 484 | Number of Events: 776

          Enabled Plug-Ins: 3.0.0.13: AirplaySpeak | 2.0.61.0: BLBackup
          3.0.0.70: EasyTrigger | 1.3.7006.42100: LiftMaster MyQ
          4.2.3.0: mcsMQTT | 3.0.0.53: PHLocation2 | 0.0.0.47: Pushover 3P
          3.0.0.16: RaspberryIO | 3.0.1.262: Z-Wave

          Z-Net version: 1.0.23 for Inclusion Nodes
          SmartStick+: 6.04 (ZDK 6.81.3) on Server

          Comment


            #65
            Originally posted by Timon View Post
            Incase it makes a difference I'm on Linux so the path was correct as Linux doesn't have drive letters and the path separators are "/" not "". That said I don't see any reason that Linux paths shouldn't work.

            I tried the debug line and here is the result:
            Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: 'dv' is not declared. It may be inaccessible due to its protection level.
            Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
            Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
            Dec-30 2:54:08 PM Error Compiling script /home/pi/Beta/HomeSeer/scripts/BatteryReport.vb: The import 'System.Core' could not be found.
            Sorry, I should have tested this, the location of that debug line is invalid.

            Place the same line immediately after line 29:
            Code:
            If InStr(UCase(dv.Device_Type_String(Nothing)), "BATTERY") > 1 Then
            Note, this placement will print out every BATTERY device REFID found until the error occurs. So the LAST entry in the log will be the RefID of the device causing the issue.
            Mike

            Comment


              #66
              Great script!

              I have made a little adjustment to it, since i would like to know what batterytype my device uses. The way i do that is that i write battery type on notes on the battery device. I've also added that if the notes is empty it will write "Unknown" in the list, this to avoid the list to become wrong if there is no notes on the device.
              Also as u see from me screenshot my list wont sort on battery %, looks like it sorts on refID(?). Is there a way to fix this? I am using HS3 on a RasPi, so its running on Linux. Which means that i have commented out line 46 as mentioned earlier in this thread.

              I would also like to get additional info about how many of each battery type there are.
              Like in this example i would get:
              Unknown - 3
              CR123A - 1
              I think this could either be presented like the Footer([4 battery Devices] - Report Created) or like a completely new arraylist
              The problem is that i am not that good at programming and especially not in vb, is this something anyone on here could fix for me?
              Click image for larger version

Name:	BatteryReport_battery.PNG
Views:	387
Size:	55.6 KB
ID:	1288979

              Comment


                #67
                Originally posted by Zheep View Post
                Great script!

                I have made a little adjustment to it, since i would like to know what batterytype my device uses. The way i do that is that i write battery type on notes on the battery device. I've also added that if the notes is empty it will write "Unknown" in the list, this to avoid the list to become wrong if there is no notes on the device.
                Also as u see from me screenshot my list wont sort on battery %, looks like it sorts on refID(?). Is there a way to fix this? I am using HS3 on a RasPi, so its running on Linux. Which means that i have commented out line 46 as mentioned earlier in this thread.

                I would also like to get additional info about how many of each battery type there are.
                Like in this example i would get:
                Unknown - 3
                CR123A - 1
                I think this could either be presented like the Footer([4 battery Devices] - Report Created) or like a completely new arraylist
                The problem is that i am not that good at programming and especially not in vb, is this something anyone on here could fix for me?
                Click image for larger version

Name:	BatteryReport_battery.PNG
Views:	387
Size:	55.6 KB
ID:	1288979
                Just found out that the formatting only looks good on gmail.com or on gmail app.
                When i open the e-mail on mail app on iphone or in Outlook it looks really weird, can anyone see what i have done wrong with the formatting? Click image for larger version

Name:	outlook.JPG
Views:	424
Size:	26.2 KB
ID:	1289267Click image for larger version

Name:	iphonegmailapp.png
Views:	402
Size:	274.5 KB
ID:	1289265Click image for larger version

Name:	iphonemailapp.jpg
Views:	451
Size:	72.8 KB
ID:	1289266
                Attached Files

                Comment


                  #68
                  Originally posted by bsobel View Post

                  Hi. Can you post a screen shot of the Status Graphics page from one of these devices? I also made some more updates last night and merged another script so that in addition to email you can update a virtual device with the lowest battery in your system. I meant to automate the path (windows/linux), I'll hit that after you post the screen shot. If the values are 'sane' it should be doable. Oh, can you also post the the first two Configuration and Advanced tab for one of the devices too?
                  I have ran into this problem with devices from Netatmo, see the pics below.
                  As we can see the value is far greater than 100 which is the rule we filter on in this script. Is there a way to divide value by 100 to get the "correct" battery %?

                  I have tried to change the Status Graphics to both 1-100 and 1-10000(rangevalues, just like it is in the other batterydevices), but it will still print out Error because that doesnt change the actual value of the device..
                  I have also tried to set av value ofset to 9900, but that didnt work either, because that only moves the scale, and doesnt downscale it by 100.
                  Click image for larger version  Name:	5.jpg Views:	1 Size:	34.6 KB ID:	1289843
                  Click image for larger version  Name:	3.PNG Views:	1 Size:	96.0 KB ID:	1289842Click image for larger version  Name:	4.PNG Views:	1 Size:	56.1 KB ID:	1289840Click image for larger version  Name:	1.PNG Views:	1 Size:	86.2 KB ID:	1289841Click image for larger version  Name:	2.PNG Views:	1 Size:	31.6 KB ID:	1289839

                  Click image for larger version  Name:	6.PNG Views:	2 Size:	34.7 KB ID:	1289838

                  Edit:Found a workaround/solution for this problem, mentioned in post 3 here for those who are interested.
                  Last edited by Zheep; March 4, 2019, 06:09 PM. Reason: Found solution/workaround

                  Comment


                    #69
                    Insteon door sensor 2845-222 Battery Level

                    How do I get rid of old or duplicate devices from this script? attached is a screen shot of the current and old version

                    the old device has a date 1/1/001
                    the new device has a date 1/5/2019

                    or how do I delete "RefID"

                    Many thanks



                    Devoir
                    Attached Files

                    Comment


                      #70
                      I still want to get this working but I'm still getting the following errors. I'm running this on Linux not windows.
                      May-14 9:24:23 AM Error Compiling script /opt/HomeSeer/scripts/BatteryReport.vb: 'dv' is not declared. It may be inaccessible due to its protection level.
                      May-14 9:24:23 AM Error Compiling script /opt/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
                      May-14 9:24:23 AM Error Compiling script /opt/HomeSeer/scripts/BatteryReport.vb: Variable declaration without an 'As' clause; Object type assumed.
                      May-14 9:24:23 AM Error Compiling script /opt/HomeSeer/scripts/BatteryReport.vb: The import 'System.Core' could not be found.
                      These don't seem to be run time errors but compile errors.
                      HomeSeer Version: HS3 Standard Edition 3.0.0.548
                      Linux version: Linux auto 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
                      Number of Devices: 484 | Number of Events: 776

                      Enabled Plug-Ins: 3.0.0.13: AirplaySpeak | 2.0.61.0: BLBackup
                      3.0.0.70: EasyTrigger | 1.3.7006.42100: LiftMaster MyQ
                      4.2.3.0: mcsMQTT | 3.0.0.53: PHLocation2 | 0.0.0.47: Pushover 3P
                      3.0.0.16: RaspberryIO | 3.0.1.262: Z-Wave

                      Z-Net version: 1.0.23 for Inclusion Nodes
                      SmartStick+: 6.04 (ZDK 6.81.3) on Server

                      Comment


                        #71
                        Originally posted by Timon View Post
                        I still want to get this working but I'm still getting the following errors. I'm running this on Linux not windows.

                        These don't seem to be run time errors but compile errors.
                        Which version of the script are you running. Probably best to post the exact script you are using as there have been quite a few mods to it over time.
                        HS 4.2.8.0: 2134 Devices 1252 Events
                        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                        Comment


                          #72
                          Here is the one I'm using. Remember the addresses are in linux format not Windows. My e-mail addresses have been altered.

                          Dim filename As String = "/opt/HomeSeer/BatteryReport.html" ' full path and filename of report (if sending report as an email attachment)
                          Dim mailTo As String = "user@comedomain.com" ' email TO address
                          Dim mailFrom As String = "anotherdomain@gmail.com" ' email FROM address
                          Dim ReportAsAttachment As Boolean = False ' set to 'True' if report should be emailed as a file (attachment), set to 'False' if report should be in email body
                          '____ End of User Configuration ____

                          Public Sub Main(ByVal param As String)
                          Dim myArray(0) As BatteryDevice
                          Dim strDeviceString, centerSTR

                          ' Header
                          strDeviceString = "<html><head><style type=" & chr(34) & "text/css" & chr(34) & ">TD{font-family: Arial; font-size: 10pt;}</style></head><body><p><table cellpadding=" & chr(34) & "4" & chr(34) & " WIDTH=" & chr(34) & "100%" & chr(34) & "border=" & chr(34) & "1" & chr(34) & "><tr><th>Ref ID</th><th>Battery %</th><th>Device Location / Name</th><th>Last Updated</th></tr>"
                          centerSTR = "<td align=" & chr(34) & "center" & chr(34) & "valign=" & chr(34) & "middle" & chr(34) & ">&nbsp;"

                          Try
                          Dim dv As Scheduler.Classes.DeviceClass
                          Dim EN As Scheduler.Classes.clsDeviceEnumeration
                          EN = hs.GetDeviceEnumerator
                          If EN Is Nothing Then
                          hs.WriteLog("BatteryReport", "Error getting Enumerator")
                          Exit Sub
                          End If

                          Do
                          dv = EN.GetNext
                          If dv Is Nothing Then Continue Do

                          ' Add to array if device type contains 'battery'
                          If InStr(UCase(dv.Device_Type_String(Nothing)), "BATTERY") > 1 Then
                          hs.WriteLog("BatteryReport", "Device issue with RefID: " & dv.Ref(Nothing).ToString)
                          ReDim Preserve myArray(UBound(myArray) + 1)
                          myArray(UBound(myArray) - 1) = New BatteryDevice

                          myArray(UBound(myArray) - 1).refID = ("[" & dv.Ref(Nothing).ToString & "]")
                          If dv.devValue(Nothing) > 100 Then ' if battery value is larger than 100(%), battery is invalid state
                          myArray(UBound(myArray) - 1).devValue = " ERROR"
                          Else
                          myArray(UBound(myArray) - 1).devValue = (dv.devValue(Nothing).ToString & "%").PadLeft(7)
                          End If
                          myArray(UBound(myArray) - 1).devName = dv.Location2(Nothing) & " " & dv.Location(Nothing) & " " & dv.Name(Nothing)
                          myArray(UBound(myArray) - 1).lastChange = dv.Last_Change(Nothing).ToString

                          End If
                          Loop Until EN.Finished

                          ReDim Preserve myArray(UBound(myArray) - 1)
                          Array.Sort(myArray)

                          Dim battdevice As Object
                          For Each battdevice In myArray
                          strDeviceString = strDeviceString & "<tr>" & centerSTR & battdevice.refID & "</td>" & centerSTR & battdevice.devValue & "</td>" & "<td>" & battdevice.devName & "</td>" & centerSTR & battdevice.lastChange & "</td></tr>"
                          Next

                          ' FOOTER
                          strDeviceString = strDeviceString & "</table></p>"
                          strDeviceString = strDeviceString & " [" & UBound(myArray) + 1 & " Battery Devices] - Report created " & Now.tostring
                          strDeviceString = strDeviceString & "</body></html>"

                          ' SEND
                          If ReportAsAttachment Then
                          System.IO.File.Delete(filename)
                          My.Computer.FileSystem.WriteAllText(filename, strDeviceString, True, System.Text.Encoding.Default)
                          hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", "Battery Report attached.", filename)
                          Else
                          hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", strDeviceString, "")
                          End If

                          Catch ex As Exception
                          hs.WriteLog("BatteryReport", "Device issue with RefID: " & dv.Ref(Nothing).ToString)
                          hs.WriteLog("BatteryReport", "ERROR: Exception in script: " & ex.Message)
                          End Try
                          hs.WriteLog("BatteryReport", "Battery report created.")

                          End Sub

                          Public Class BatteryDevice
                          Implements IComparable(Of BatteryDevice)

                          Public refID As String
                          Public devValue As String
                          Public lastChange As String
                          Public devName As String

                          Public Function CompareTo(ByVal other As BatteryDevice) As Integer Implements IComparable(Of BatteryDevice).CompareTo
                          Return Me.devValue.CompareTo(other.devValue)
                          End Function
                          End Class
                          HomeSeer Version: HS3 Standard Edition 3.0.0.548
                          Linux version: Linux auto 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
                          Number of Devices: 484 | Number of Events: 776

                          Enabled Plug-Ins: 3.0.0.13: AirplaySpeak | 2.0.61.0: BLBackup
                          3.0.0.70: EasyTrigger | 1.3.7006.42100: LiftMaster MyQ
                          4.2.3.0: mcsMQTT | 3.0.0.53: PHLocation2 | 0.0.0.47: Pushover 3P
                          3.0.0.16: RaspberryIO | 3.0.1.262: Z-Wave

                          Z-Net version: 1.0.23 for Inclusion Nodes
                          SmartStick+: 6.04 (ZDK 6.81.3) on Server

                          Comment


                            #73
                            I have an easy solution that works if you have the Easy Trigger Plugin.

                            1. From the Easy Trigger plugin's "Config" screen, set up a dynamic Device Group called "Batteries" consisting of all devices there "Type" equals "Z-Wave Battery". If you have devices other than Z-Wave, you may need to modify this.

                            2. Set up a simple event that triggers whenever a "Battery" device is set (i.e., at each battery report). The event just checks the battery level and sends an email if its too low. In the example below, I set that to 50%. Since most battery devices report their battery state about every 12-24 hours, this won't result in too many alerts. Also, I have it sent as a text to my phone (your cell phone provider typically has an address where you send an email and it converts into a text to your phone. Here, in the US, for ATT, that would be XXXXXXXXXX@mms.att.com where you replace XXXXXXXXXX with your phone #). Here's the event:

                            Click image for larger version

Name:	Battery Check.PNG
Views:	433
Size:	227.2 KB
ID:	1306846



                            Comment


                              #74
                              I'm having the same issue, running on Linux as well. I'm wondering if it's a file or directory permission issue..

                              Originally posted by Timon View Post
                              Here is the one I'm using. Remember the addresses are in linux format not Windows. My e-mail addresses have been altered.

                              Dim filename As String = "/opt/HomeSeer/BatteryReport.html" ' full path and filename of report (if sending report as an email attachment)
                              Dim mailTo As String = "user@comedomain.com" ' email TO address
                              Dim mailFrom As String = "anotherdomain@gmail.com" ' email FROM address
                              Dim ReportAsAttachment As Boolean = False ' set to 'True' if report should be emailed as a file (attachment), set to 'False' if report should be in email body
                              '____ End of User Configuration ____

                              Public Sub Main(ByVal param As String)
                              Dim myArray(0) As BatteryDevice
                              Dim strDeviceString, centerSTR

                              ' Header
                              strDeviceString = "
                              " & battdevice.devName & "
                              "
                              strDeviceString = strDeviceString & " [" & UBound(myArray) + 1 & " Battery Devices] - Report created " & Now.tostring
                              strDeviceString = strDeviceString & ""

                              ' SEND
                              If ReportAsAttachment Then
                              System.IO.File.Delete(filename)
                              My.Computer.FileSystem.WriteAllText(filename, strDeviceString, True, System.Text.Encoding.Default)
                              hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", "Battery Report attached.", filename)
                              Else
                              hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", strDeviceString, "")
                              End If

                              Catch ex As Exception
                              hs.WriteLog("BatteryReport", "Device issue with RefID: " & dv.Ref(Nothing).ToString)
                              hs.WriteLog("BatteryReport", "ERROR: Exception in script: " & ex.Message)
                              End Try
                              hs.WriteLog("BatteryReport", "Battery report created.")

                              End Sub

                              Public Class BatteryDevice
                              Implements IComparable(Of BatteryDevice)

                              Public refID As String
                              Public devValue As String
                              Public lastChange As String
                              Public devName As String

                              Public Function CompareTo(ByVal other As BatteryDevice) As Integer Implements IComparable(Of BatteryDevice).CompareTo
                              Return Me.devValue.CompareTo(other.devValue)
                              End Function
                              End Class
                              Sent from my SM-G973U using Tapatalk

                              Comment


                                #75
                                Easy trigger method seems to work although I’ve had some issues using pushover to send messages. Have to look at it some more.
                                HomeSeer Version: HS3 Standard Edition 3.0.0.548
                                Linux version: Linux auto 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
                                Number of Devices: 484 | Number of Events: 776

                                Enabled Plug-Ins: 3.0.0.13: AirplaySpeak | 2.0.61.0: BLBackup
                                3.0.0.70: EasyTrigger | 1.3.7006.42100: LiftMaster MyQ
                                4.2.3.0: mcsMQTT | 3.0.0.53: PHLocation2 | 0.0.0.47: Pushover 3P
                                3.0.0.16: RaspberryIO | 3.0.1.262: Z-Wave

                                Z-Net version: 1.0.23 for Inclusion Nodes
                                SmartStick+: 6.04 (ZDK 6.81.3) on Server

                                Comment

                                Working...
                                X