Announcement

Collapse
No announcement yet.

How To Create A Low Battery Level Event

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

  • #76
    slbuck 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: Windows 10 Pro - Work Station
    HS Version: HS3 Pro Edition 3.0.0.435

    Plug-Ins: BLBackup, BLGData, BLRoombaWifi, Device History, EasyTrigger, ImperiHome, Nest, PHLocation, Pushover 3P, Restart, Sonos, UltraCID3, UltraWeatherWU3, Z-Wave, 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: Windows 10 Pro - Work Station
        HS Version: HS3 Pro Edition 3.0.0.435

        Plug-Ins: BLBackup, BLGData, BLRoombaWifi, Device History, EasyTrigger, ImperiHome, Nest, PHLocation, Pushover 3P, Restart, Sonos, UltraCID3, UltraWeatherWU3, Z-Wave, and Jon00 scripts.

        Comment


        • #79
          slbuck 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: Windows 10 Pro - Work Station
          HS Version: HS3 Pro Edition 3.0.0.435

          Plug-Ins: BLBackup, BLGData, BLRoombaWifi, Device History, EasyTrigger, ImperiHome, Nest, PHLocation, Pushover 3P, Restart, Sonos, UltraCID3, UltraWeatherWU3, Z-Wave, 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 3.0.0.548: 1965 Devices 1146 Events
            Z-Wave 3.0.1.262: 122 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: Windows 10 Pro - Work Station
              HS Version: HS3 Pro Edition 3.0.0.435

              Plug-Ins: BLBackup, BLGData, BLRoombaWifi, Device History, EasyTrigger, ImperiHome, Nest, PHLocation, Pushover 3P, Restart, Sonos, UltraCID3, UltraWeatherWU3, Z-Wave, 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 3.0.0.548: 1965 Devices 1146 Events
                Z-Wave 3.0.1.262: 122 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: Windows 10 Pro - Work Station
                  HS Version: HS3 Pro Edition 3.0.0.435

                  Plug-Ins: BLBackup, BLGData, BLRoombaWifi, Device History, EasyTrigger, ImperiHome, Nest, PHLocation, Pushover 3P, Restart, Sonos, UltraCID3, UltraWeatherWU3, Z-Wave, 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 3.0.0.548: 1965 Devices 1146 Events
                      Z-Wave 3.0.1.262: 122 Nodes on one Z-Net

                      Comment

                      Working...
                      X