Announcement

Collapse
No announcement yet.

Monthly Low Battery Check

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

  • Homeseer666
    replied
    Nice script indeed;
    I needed to scan device names instead of device type:

    Code:
    If (UCASE(dv.name(Nothing)).contains("BATT")) Then




    Leave a comment:


  • DaleRS
    replied
    I cant believe I just found this, awesome script. THANK YOU for sharing.

    Leave a comment:


  • caguinotte
    replied
    I know this is an old thread, but I was hoping that someone has a version that works on Linux and HS4.

    thanks, Chris

    Leave a comment:


  • wkearney99
    replied
    I ran into an issue with it not recognizing some devices that have battery in the name. I change the comparison code:

    From:
    Code:
    If InStr(UCase(dv.Device_Type_String(Nothing)), "BATTERY") > 1 Then
    To:
    Code:
     If (UCASE(dv.Device_Type_String(Nothing)).contains("BATTERY")) Then
    Ref ID Battery % Device Location / Name Last Updated
    [2584] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2610] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2626] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2606] 49% Hubitat Hubitat Battery 3/3/2021 8:25:13 PM
    [2638] 52% Hubitat Hubitat Battery 3/3/2021 8:24:54 PM
    [2622] 52% Hubitat Hubitat Battery 3/4/2021 11:21:54 AM
    [2614] 56% Hubitat Hubitat Battery 3/3/2021 7:28:51 PM
    [2598] 57% Hubitat Hubitat Battery 3/4/2021 2:40:08 PM
    [2634] 65% Hubitat Hubitat Battery 3/3/2021 8:25:00 PM
    [2618] 66% Hubitat Hubitat Battery 3/3/2021 8:25:08 PM
    [2630] 69% Hubitat Hubitat Battery 3/3/2021 7:28:51 PM
    [2580] 72% Hubitat Hubitat Battery 3/4/2021 2:41:06 PM
    [2576] 73% Hubitat Hubitat Battery 3/4/2021 2:41:02 PM
    [2602] 76% Hubitat Hubitat Battery 3/4/2021 2:40:10 PM
    [2727] 100% Basement Downstairs Bar Battery Laundry Shutoff Water Sensor 4/16/2021 10:22:59 AM
    [2731] 100% JowiHue JowiHue Battery Temperature 27 4/29/2021 7:35:30 AM
    [2657] 100% Basement Fridge Battery Back Sump Sensor Temperature 3/13/2021 5:51:59 PM
    [2671] 100% 1st Floor Kitchen Battery Kitchen Undercabinet Left Switch 3/19/2021 2:03:32 PM
    [2706] 100% JowiHue JowiHue Battery Presence 18 3/24/2021 4:29:09 PM
    [2715] 100% JowiHue JowiHue Battery Coffee Undercabinet Switch 3/29/2021 1:15:49 PM
    [2561] 100% 1st Floor Powder Room Battery Powder Room Water Sensor 3/19/2021 2:47:46 PM
    [2560] 100% 1st Floor Kitchen Kitchen Sensor Battery 3/1/2021 9:08:35 PM
    [2541] 100% Outside Trash Area Presense 2 Battery 2/21/2021 12:22:19 PM
    [2642] 100% Basement Workshop Battery Front Sump Water 4/1/2021 6:57:25 PM
    [2534] 100% Outside Trash Area Hue sensor 1 Battery 4/15/2021 1:36:35 PM
    [2562] 100% Battery Health SDJ-Health Battery Health Root 4/24/2021 5:45:37 AM
    [26 Battery Devices] - Report created 4/29/2021 7:39:10 PM
    Because otherwise it would only pick up these:
    Ref ID Battery % Device Location / Name Last Updated
    [2584] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2626] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2610] 0% Hubitat Hubitat Battery 1/1/0001 12:00:00 AM
    [2606] 49% Hubitat Hubitat Battery 3/3/2021 8:25:13 PM
    [2622] 52% Hubitat Hubitat Battery 3/4/2021 11:21:54 AM
    [2638] 52% Hubitat Hubitat Battery 3/3/2021 8:24:54 PM
    [2614] 56% Hubitat Hubitat Battery 3/3/2021 7:28:51 PM
    [2598] 57% Hubitat Hubitat Battery 3/4/2021 2:40:08 PM
    [2634] 65% Hubitat Hubitat Battery 3/3/2021 8:25:00 PM
    [2618] 66% Hubitat Hubitat Battery 3/3/2021 8:25:08 PM
    [2630] 69% Hubitat Hubitat Battery 3/3/2021 7:28:51 PM
    [2580] 72% Hubitat Hubitat Battery 3/4/2021 2:41:06 PM
    [2576] 73% Hubitat Hubitat Battery 3/4/2021 2:41:02 PM
    [2602] 76% Hubitat Hubitat Battery 3/4/2021 2:40:10 PM
    [2562] 100% Battery Health SDJ-Health Battery Health Root 4/24/2021 5:45:37 AM
    [15 Battery Devices] - Report created 4/29/2021 5:26:53 PM

    Leave a comment:


  • Hillmar
    replied
    I've been using this script without problems for a while now. But this weekend I added a Hue motion detector to my system and because it runs on battery I wanted to check that it was included in the report generated by the script. It was not...

    It looks like the reason is that Device Type = "Battery" (ONLY Battery) and because of this it is not recognized by the script. If I change the Device Type to something like "Test Battery" the device shows up in the report.

    Is there some way to change the script to fix this? I would avoid having to change the Device Type as this is easily forgotten when I add another Hue motion later...

    Leave a comment:


  • Charles_cz
    replied
    Is there easy way to modify the script to write the report in html file or any other file that I could display in HS Touch?
    Let say I would run the script once a day to update (overwrite) the report file.

    Thanks. Charles

    Leave a comment:


  • devanb
    replied
    I also am having the same error of

    ERROR: Exception in script: Failed to compare two elements in the array.

    Current Date/Time: 17/09/2019 08:33:37
    HomeSeer Version: HS3 Standard Edition 3.0.0.500
    Linux version: Linux HS3-Closter 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux System Uptime: 0 Days 7 Hours 13 Minutes 14 Seconds
    IP Address: 172.20.0.17
    Number of Devices: 179
    Number of Events: 39
    Available Threads: 399
    HSTouch Enabled: False
    Event Threads: 1
    Event Trigger Eval Queue: 0
    Event Trigger Priority Eval Queue: 0
    Device Exec Queue: 0
    HSTouch Event Queue: 0
    Email Send Queue: 0

    Enabled Plug-Ins
    1.3.7.3: Device History
    3.0.0.67: EasyTrigger
    0.0.0.45: Pushover 3P
    3.0.1.252: Z-Wave


    If anybody has success running this on linux?

    Thanks,

    Devan

    Leave a comment:


  • Guest
    Guest replied
    Originally posted by jvm View Post
    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:
    Works GREAT! thanks. Just tried it with pushover

    Attached Files

    Leave a comment:


  • Tomgru
    replied
    i'm trying to set this up again, an for all that is holy I can't seem to remember how to remove the txt extension???? and I must be the worst search person ever, as I can't find it online at all.

    please someone put me out of my misery.

    EDIT. Nevermind… finally found it.

    Leave a comment:


  • Timon
    replied
    Easy trigger method seems to work although I’ve had some issues using pushover to send messages. Have to look at it some more.

    Leave a comment:


  • WhitW
    replied
    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

    Leave a comment:


  • jvm
    replied
    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:	395
Size:	227.2 KB
ID:	1306846



    Leave a comment:


  • Timon
    replied
    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

    Leave a comment:


  • sparkman
    replied
    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.

    Leave a comment:


  • Timon
    replied
    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.

    Leave a comment:

Working...
X