Originally posted by adeux
View Post
Announcement
Collapse
No announcement yet.
Monthly Low Battery Check
Collapse
X
-
Originally posted by mwaite View PostBattery 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.
Dec-30 9:54:37 AM BatteryReport Battery report created. No Report was found and nothing mailed.Dec-30 9:54:37 AM BatteryReport ERROR: Exception in script: Failed to compare two elements in the array.
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
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
-
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. No Report was found and nothing mailed.Dec-30 9:54:37 AM BatteryReport ERROR: Exception in script: Failed to compare two elements in the array.
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
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.
Code:Dim filename As String = "C:\Program Files (x86)\HomeSeer HS3\BatteryReport.html" ' full path and filename of report
Code:hs.WriteLog("BatteryReport", "Device issue with RefID: " & dv.Ref(Nothing).ToString)
Mike
Comment
-
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
-
Originally posted by Timon View PostIncase 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.
Place the same line immediately after line 29:
Code:If InStr(UCase(dv.Device_Type_String(Nothing)), "BATTERY") > 1 Then
Mike
Comment
-
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?
- Likes 1
Comment
-
Originally posted by Zheep View PostGreat 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?
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?
Comment
-
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?
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.
Edit:Found a workaround/solution for this problem, mentioned in post 3 here for those who are interested.
Comment
-
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. These don't seem to be run time errors but compile errors.May-14 9:24:23 AM Error Compiling script /opt/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
-
Originally posted by Timon View PostI 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.
HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
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) & "> "
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 ClassHomeSeer 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
-
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:
Comment
-
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 PostHere 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
Comment
-
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
Comment