Announcement

Collapse
No announcement yet.

How To Create A Low Battery Level Event

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

    #76
    Chewbucka or sparkman have either of you updated the BatteryReport Script to reflect the latest? I noticed that when I execute it via the Virtual device I get the following error message;
    Aug-14 9:20:05 PM Error 3 Running script BatteryReport.vb :Object of type 'System.Object[]' cannot be converted to type 'System.String'.->Does entry point Main exist in script? at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Scheduler.clsRunVBNetScript.ExecuteScript()
    Aug-14 9:20:05 PM Device Control Device: Virtual Controls Lowest Battery to Send Report (Execute Script) by/from: CAPI Control Handler
    Not sure what not working? the funny things is that if I use an event to run it the script I'm able to get it to run (see below) so its something re the Virtual device execution any ideas? Mike
    Aug-14 9:32:49 PM email Email successfully sent to email@XXX.com
    Aug-14 9:32:47 PM Battery Report Battery report created.
    Aug-14 9:32:47 PM Event Running script and waiting: C:/Program Files (x86)/HomeSeer HS3/scripts/BatteryReport2.vb
    Aug-14 9:32:47 PM Event Event Trigger "Utilities Battery Report 2"
    Computer: CUK Intel NUC7i7BNH
    Op System: Windows10 Pro - Work Station
    HS Version: HS4 Pro Edition 4.2.19.0

    Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

    Comment


      #77
      Originally posted by MNB View Post
      James, thanxs for the comeback, I have reverted to your recommendation. I noticed you avoided my other inquiry;
      any thoughts?[/SIZE][/FONT][/COLOR][/LEFT]
      I'm not aware of any way to view past global variable.

      Comment


        #78
        James, thanx for the comeback, I was afraid of that other than writing a script to write the values into a db and being able to parse it (were getting more complex than simply using EasyTrigger), thanxs Mike
        Computer: CUK Intel NUC7i7BNH
        Op System: Windows10 Pro - Work Station
        HS Version: HS4 Pro Edition 4.2.19.0

        Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

        Comment


          #79
          Chewbucka or sparkman,
          dumb question, by the way thanxs for the great process and script, after invoking "&hs.devicescriptbutton_addbutton(<refID>,"Send Report",1002,"BatteryReport.vb","","",1,2,1)" within the Control Panel, how does one see those button attributes applied to the virtual device at a later date? Looking at the Virtual device its self doesn't give any clues other than you have two new buttons but no indication of what actions you had attached to these buttons, thanxs in advance Mike
          Computer: CUK Intel NUC7i7BNH
          Op System: Windows10 Pro - Work Station
          HS Version: HS4 Pro Edition 4.2.19.0

          Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

          Comment


            #80
            Originally posted by MNB View Post
            have either of you updated the BatteryReport Script to reflect the latest? I noticed that when I execute it via the Virtual device I get the following error message;

            Not sure what not working? the funny things is that if I use an event to run it the script I'm able to get it to run (see below) so its something re the Virtual device execution any ideas?

            dumb question, by the way thanxs for the great process and script, after invoking "&hs.devicescriptbutton_addbutton(<refID>,"Send Report",1002,"BatteryReport.vb","","",1,2,1)" within the Control Panel, how does one see those button attributes applied to the virtual device at a later date? Looking at the Virtual device its self doesn't give any clues other than you have two new buttons but no indication of what actions you had attached to these buttons, thanxs in advance Mike
            Hi Mike,

            I use a custom version of the battery script so I have not used the latest version posted here. As to why it's not executing from the button, I'm thinking that you may need to specify additional values for the add_button function. You have two parameters as "" and the first one may need to be "Main". What did you specify for the event? The only way to see what the button does is to run the script that enumerates the buttons and then dumps info about them to the log. There's one posted earlier in the thread.

            Cheers
            Al
            HS 4.2.8.0: 2134 Devices 1252 Events
            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

            Comment


              #81
              Al, thanxs for the comeback, I took a look at the script (see below) and see that it has "Sub Main", within the event the Sub or Function: is blank so I tried to update the button with Main and Sub Main
              "
              &hs.devicescriptbutton_addbutton(<refID>,"Send Report",1002,"BatteryReport.vb","Sub Main","",1,2,1)" but still get Error 3 as I posted in #76




              Code:
              Dim filename As String = "C:\Program Files (x86)\HomeSeer HS3\BatteryReport.txt" ' full path and filename of report (if sending report as an email attachment)
                  Dim mailTo As String = "michael_n_blackwell@XXX.com" ' email TO address
                  Dim mailFrom As String = "michael_n_blackwell@XXX.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 ____
              
                  Dim msg As String = ""
              
                  Public Sub Main(Parms As Object)
                      Dim myArray(0) As BatteryDevice
                      Dim MaxNameLen As Integer = 0
              
                      Try
                          Dim dv As Scheduler.Classes.DeviceClass
                          Dim EN As Scheduler.Classes.clsDeviceEnumeration
                          EN = hs.GetDeviceEnumerator
                          If EN Is Nothing Then
                              hs.WriteLog("Battery Report", "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
                                  ReDim Preserve myArray(UBound(myArray) + 1)
                                  myArray(UBound(myArray) - 1) = New BatteryDevice
              
                                  myArray(UBound(myArray) - 1).refID = ("[" & dv.Ref(Nothing).ToString & "]").PadLeft(6) & vbTab
                                  If dv.devValue(Nothing) > 100 Then ' if battery value is larger than 100(%), battery is invalid state
                                      myArray(UBound(myArray) - 1).devValue = "  ERROR" & vbTab & vbTab
                                  Else
                                      myArray(UBound(myArray) - 1).devValue = (dv.devValue(Nothing).ToString & "%").PadLeft(7) & vbTab & vbTab
                                  End If
                                  ' Determine max length of device loc/name string (for formatting)
                                  If (dv.Location2(Nothing) & " " & dv.Location(Nothing) & " " & dv.Name(Nothing)).Length > MaxNameLen Then
                                      MaxNameLen = (dv.Location2(Nothing) & " " & dv.Location(Nothing) & " " & dv.Name(Nothing)).Length
                                  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.PadRight(22)
              
                              End If
                          Loop Until EN.Finished
              
                          ReDim Preserve myArray(UBound(myArray) - 1)
                          Array.Sort(myArray)
              
                          report(Nothing, , MaxNameLen) ' HEADER
              
                          Dim battdevice As Object
                          For Each battdevice In myArray
                              report(battdevice.refID & battdevice.devValue & battdevice.devName.PadRight(MaxNameLen) & vbTab & battdevice.lastChange, UBound(myArray) + 1)
                          Next
              
                          report(Nothing, UBound(myArray) + 1, , True) ' FOOTER
              
                      Catch ex As Exception
                          hs.WriteLog("Battery Report", "ERROR:  Exception in script: " & ex.Message)
                      End Try
                      hs.WriteLog("Battery Report", "Battery report created.")
              
                      If ReportAsAttachment Then
                          hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", "Battery Report attached.", filename)
                      Else
                          hs.SendEmail(mailTo, mailFrom, "", "", "Battery Report", msg, "")
                      End If
              
                  End Sub
              
                  Public Sub report(myRow As String, Optional recCount As Integer = -1, Optional MaxNameLen As Integer = 0, Optional EndReport As Boolean = False)
                      If EndReport Then ' Add FOOTER
                          myRow = vbCrLf & " [" & recCount & " Battery Devices] - Report created " & Now.ToString & vbCrLf
              
                      ElseIf recCount = -1 Then ' Add HEADER
                          If ReportAsAttachment Then
                              Try
                                  System.IO.File.Delete(filename)
                              Catch ex As Exception
                              End Try
                          End If
                          myRow = "RefID" & vbTab & "Battery" & vbTab & vbTab & "Device Location / Name" & Space(MaxNameLen - 22) & vbTab & "Last Changed" & vbCrLf
                          myRow = myRow & "-----" & vbTab & "-------" & vbTab & vbTab & "----------------------" & Space(MaxNameLen - 22) & vbTab & "------------"
                      Else
              
                      End If
              
                      If ReportAsAttachment Then
                          Try
                              My.Computer.FileSystem.WriteAllText(filename, myRow & vbCrLf, True, System.Text.Encoding.Default)
                          Catch ex As Exception
                              hs.WriteLog("Battery Report", "REPORT ERROR: " & ex.Message)
                          End Try
                      Else
                          msg = msg & myRow & vbCrLf
                      End If
              
                  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
              Computer: CUK Intel NUC7i7BNH
              Op System: Windows10 Pro - Work Station
              HS Version: HS4 Pro Edition 4.2.19.0

              Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

              Comment


                #82
                Originally posted by MNB View Post
                Al, thanxs for the comeback,
                It should be:

                Code:
                &hs.devicescriptbutton_addbutton(<refID>,"Send Report",1002,"BatteryReport.vb","Main","",1,2,1)
                but it sounds like you may have tried both. I've seen that error message if there's something else wrong, but not sure what it could be.
                HS 4.2.8.0: 2134 Devices 1252 Events
                Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                Comment


                  #83
                  Thanxs Al, I agree with you I've seen something similar script wise (string conversion issue) a few years ago but for the life of me can't remember what the fix was (I must be getting older!) Mike
                  Computer: CUK Intel NUC7i7BNH
                  Op System: Windows10 Pro - Work Station
                  HS Version: HS4 Pro Edition 4.2.19.0

                  Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                  Comment


                    #84
                    Originally posted by sparkman View Post

                    It should be:

                    Code:
                    &hs.devicescriptbutton_addbutton(<refID>,"Send Report",1002,"BatteryReport.vb","Main","",1,2,1)"
                    but it sounds like you may have tried both. I've seen that error message if there's something else wrong, but not sure what it could be.
                    There is an odd number of double quotes - an extra one at the end?

                    Comment


                      #85
                      Originally posted by zwolfpack View Post

                      There is an odd number of double quotes - an extra one at the end?
                      Yes, that was a copy/paste error on my part. I've corrected my post. Thanks for noticing!
                      HS 4.2.8.0: 2134 Devices 1252 Events
                      Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                      Comment


                        #86
                        I just upgraded to HS4 and the buttons on the lowest battery virtual device were no longer there. I had to re-run the script commands to get them added again. Here's what I ran and the buttons came back. I then had to check the events that triggered these scripts to verify that the device was being set to Update or Send Report.

                        My virtual device refID is 221 in this example. The first set of "" indicates to use Main by default.

                        Here is the command for the lowest battery device update button:

                        Code:
                        &hs.devicescriptbutton_addbutton(221,"Update",1001,"LowBatteryCheck.vb","","",1,1,1)
                        And the send report button:

                        Code:
                        &hs.devicescriptbutton_addbutton(221,"Send Report",1002,"BatteryReport.vb","","",1,2,1)
                        In the attached events, I also have an advanced option to not re-run for 5 seconds. This prevents multiple emails from being sent.
                        Attached Files

                        Comment

                        Working...
                        X