Announcement

Collapse
No announcement yet.

Polling All Devices

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

  • #31
    Originally posted by zwolfpack View Post
    Cool, that cures the "System.Core" issue. But the "VB.Net script exception(0), re-starting: ..." and never finishing script remains.
    It's pretty hosed; I put a writelog at the very start and it doesn't show.
    If you remove the Do Until loop, does the script start and terminate properly?
    HS 3.0.0.548: 1970 Devices 1149 Events
    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

    Comment


    • #32
      Originally posted by ramans View Post
      Hi again ...
      I copied the script that only polls zwave root devices from sparkman's post above and it works on my system. The original script from rprade with the latest modifications still did not work. I did have to delay the start of the script because the timing of all on/all off is not instantaneous. Using mono is a hit or miss proposition ... so thanks to everyone.

      HS3 v 3.0.0.435
      Mono v 5.0.1.1
      Odroid HC1 running Ubuntu LT v 18.04
      homemade znet via Rpi2 and HomeSeer smartstick+

      I'm not sure if "all" of mono is installed, but I installed mono-complete and mono-vbnc only and locked the version of mono to 5.0.1.1 with "snapshot" per the mono project. I found if you go beyond this version other scripts and things may not work.

      My "ALL ON and ALL OFF" zwave command in events are now updated on the HomeSeer web page. I only use the command shortly after startup or when I'm unsure of what to do to return the system to a known and controllable state so future events provide expected results.
      Glad it's working for you!
      HS 3.0.0.548: 1970 Devices 1149 Events
      Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

      Comment


      • #33
        Originally posted by sparkman View Post

        If you remove the Do Until loop, does the script start and terminate properly?
        Expect the unexpected, I guess -- commenting out the Do and Until lines returns to "The import 'System.Core' could not be found" !

        This is a test system on a raspberry pi. Maybe I'll load up mono 5.0.1 and see if that makes a difference, given the success reported by ramans, though on a different platform. Crazy stuff!

        Comment


        • #34
          Originally posted by zwolfpack View Post

          Expect the unexpected, I guess -- commenting out the Do and Until lines returns to "The import 'System.Core' could not be found" !

          This is a test system on a raspberry pi. Maybe I'll load up mono 5.0.1 and see if that makes a difference, given the success reported by ramans, though on a different platform. Crazy stuff!
          Did you comment out the whole section, or just the Do line and the Until line? I meant the whole section. Can you run any scripts on the pi? If not, then likely a mono issue.
          HS 3.0.0.548: 1970 Devices 1149 Events
          Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

          Comment


          • #35
            Thanks - I took another look at it last night and got it working.

            For the most recent problem, I had indeed commented out only the Do and Until lines, but the Continue Do line was still there. With that commented out, "VB.Net script exception(0), re-starting: ..." returned. That one is particularly inconvenient, as HS3 has to be cycled (service restart) to clear it. Turns out I made a bonehead mistake - I had changed the subroutine name from Main but neglected to put that name in the form field. That corrected, another daunting messsage:
            Running script /opt/HomeSeer/scripts/Z-Wave.vb :Exception has been thrown by the target of an invocation.->Does entry point ZWavePoll exist in script? at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00051] in :0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0 at Scheduler.clsRunVBNetScript.ExecuteScript () [0x0039b] in :0

            With the sub named Main, shorter but similarly cryptic:
            Running script /opt/HomeSeer/scripts/Z-Wave.vb :Exception has been thrown by the target of an invocation.Invalid IL code in scriptcode3.VBWrapper:Main (object): IL_0263: nop

            Further commenting out isolated an issue the line

            dvRef = hs.GetDeviceRefByName(dv.Name(Nothing))

            By breaking this into
            dvName = dv.Name(Nothing)
            dvRef = hs.GetDeviceRefByName(dvName)

            (with dvName declared as string up top), it runs like its supposed to!

            Once again, thanks for your assistance!

            Working version:
            Code:
            Sub Main(ByVal Parm As Object)
                Dim logName As String = "ZWavePoll"
                Dim dvName As String
                Dim dvRef As Integer
                Dim PollDelay As Integer = 5000
            
                Try
                    Dim PollResult As New HomeSeerAPI.IPlugInAPI.PollResultInfo
                    Dim dv As Scheduler.Classes.DeviceClass
                    Dim EN As Scheduler.Classes.clsDeviceEnumeration
                    EN = hs.GetDeviceEnumerator
                    hs.WriteLog(logName, "Starting.")
                    Do
                        dv = EN.GetNext
                        If dv Is Nothing Then Continue Do
                        If dv.Interface(Nothing).ToLower = "z-wave" And dv.Relationship(Nothing) < 4 And dv.Status_Support(Nothing) = True Then
                           dvName = dv.Name(Nothing)
                           dvRef = hs.GetDeviceRefByName(dvName)            
                           PollResult = hs.PluginFunction("Z-Wave", "", "PollDevice", New Object() {dvRef})  
                           hs.WriteLog(logName, "Device: " & dvName & " (" & dv.Ref(nothing) & ") Result: " & PollResult.Result.ToString & " (" & PollResult.Value.ToString    &")" )
                           System.Threading.Thread.Sleep(PollDelay)
                        End If
            
                    Loop Until EN.Finished
                    hs.WriteLog(logName, "Finished.")
            
                Catch ex As Exception : hs.WriteLogEx(logName, "Exception: " & ex.message, "#FF0000")
                End Try
            
            End Sub
            Last edited by zwolfpack; November 20th, 2018, 02:42 AM.

            Comment


            • #36
              Great! In one of the later versions of the script that I had posted (post #26), I had changed

              dvRef = hs.GetDeviceRefByName(dv.Name(Nothing))

              to

              dvRef = dv.Ref(Nothing) which is a bit simpler, but either way is fine. Cheers Al
              HS 3.0.0.548: 1970 Devices 1149 Events
              Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

              Comment


              • #37
                sparkman. This is great. I had been trying to write a script like the one you posted at #26 for some time and could never get it right. I've now set it to poll through all of my devices at startup (with a 30 second delay to make sure the Z-Wave plugin gets initialized) and its working fine! This took care of a big issue I had with the status of non-polled Z-Wave devices getting out-of-sync during periods in which HomeSeer was not operating.

                Comment


                • #38
                  jvm, glad it's working for you, but most of the thanks goes to rprade who posted the first version of it at the beginning of the thread.
                  HS 3.0.0.548: 1970 Devices 1149 Events
                  Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

                  Comment


                  • #39
                    Originally posted by sparkman View Post
                    jvm, glad it's working for you, but most of the thanks goes to rprade who posted the first version of it at the beginning of the thread.
                    rprade - Thanks for posting this polling script. Its something I've been looking for for a while and works great.

                    Comment


                    • #40
                      Originally posted by jvm View Post

                      rprade - Thanks for posting this polling script. Its something I've been looking for for a while and works great.
                      You're welcome. I'm not sure how much credit I deserve, I cobbled it together from bits posted by others such as rjh and jon00 Then sparkman cleaned it up.
                      Randy Prade
                      Aurora, CO
                      Prades.net

                      PHLocation - Pushover - EasyTrigger - UltraECM3 - Ultra1Wire3 - Arduino

                      Comment


                      • #41
                        Thanks all. I was looking for this. It was as easy as Copy and Paste "Working version" into a nightly script. Many thanks to ALL !!!!!

                        Comment


                        • #42
                          I ran into issues running the VB version of the script so I ported it to C#. Here it is in case anyone else finds needs it in the future (thanks to those who put the original together, saved me a ton of time):

                          Code:
                          private static bool _debug = true;
                          private static string _logName = "Z-Wave Poll";
                          private static int _pollDelay = 5000; //delay between polls in milliseconds
                          
                          public object Main(object[] args)
                          {
                              try
                              {
                                  // run through the enumerator, remove the location two strings
                                  HomeSeerAPI.IPlugInAPI.PollResultInfo pollResult;
                                  Scheduler.Classes.clsDeviceEnumeration devEnum;
                                  Scheduler.Classes.DeviceClass dv;
                          
                                  // Get a list of devices
                                  devEnum = (Scheduler.Classes.clsDeviceEnumeration)hs.GetDeviceEnumerator();
                          
                                  if (devEnum == null)
                                  {
                                      hs.WriteLog("Info", "No devices to enumerate");
                                      return null;
                                  }
                          
                                  while (!devEnum.Finished)
                                  {
                                      dv = devEnum.GetNext();
                          
                                      if (dv.get_Status_Support(null)
                                          && dv.get_Interface(null).ToLower() == "z-wave"
                                          && dv.get_Relationship(null) != HomeSeerAPI.Enums.eRelationship.Child)
                                      {
                                          int dvRef = dv.get_Ref(null);
                                          pollResult = (HomeSeerAPI.IPlugInAPI.PollResultInfo)hs.PluginFunction("Z-Wave", "", "PollDevice", new object[] { dvRef });
                                          if (_debug)
                                              hs.WriteLog(_logName, string.Format("Device: {0} ({1}) - Result: {2}  Value: {3}",
                                                  dv.get_Name(null), dv.get_Ref(null), pollResult.Result, pollResult.Value));
                          
                                          System.Threading.Thread.Sleep(_pollDelay);
                                      }
                                  }
                              }
                              catch (Exception ex)
                              {
                                  hs.WriteLog("Error Polling Devices", "Exception: " + ex.Message);
                              }
                          
                              return null;
                          }

                          Comment

                          Working...
                          X