Originally posted by zwolfpack
View Post
Announcement
Collapse
No announcement yet.
Polling All Devices
Collapse
X
-
Originally posted by ramans View PostHi 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.HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
Originally posted by sparkman View Post
If you remove the Do Until loop, does the script start and terminate properly?
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
-
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!HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
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 20, 2018, 02:42 AM.
- Likes 1
Comment
-
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 AlHS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
- Likes 1
Comment
-
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
-
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
-
I need a way to tell if any Z-Wave devices are unreachable.
I wrote a script to poll all my Z-Wave devices to (1) ensure that HomeSeer is in sync with actual device state and (2) as a way to know if there are any devices that are unreachable. Unfortunately, for some types of Z-Wave devices, polling might say "Ok" even though the device is actually unreachable.
My script basically does similar to what has been discussed earlier in this thread:
PollResult = CType(hs.PluginFunction("Z-Wave", "", "PollDevice", New Object() {dvRef}), HomeSeerAPI.IPlugInAPI.PollResultInfo)
If (String.Compare(PollResult.Result.ToString, "OK", True) <> 0) Then
pollStr = "Device: " & dv.Location(Nothing) & " " & dv.Name(Nothing) & " (" & dvRef & ") Result: " & PollResult.Result.ToString & " (value: " & PollResult.Value.ToString & ")"
hs.WriteLog("Error", logName & ": Unable to poll " & pollStr)
emailBody = emailBody & Environment.NewLine & pollStr
Else
If any of my Z-Wave light switches (Leviton), are unreachable (for example, they are not powered), the poll fails. However if any of my HomeSeer HSM200 or Aeotec Siren Gen5 devices are unplugged, the aforementioned PollResult still succeeds. The PollResult will still be "OK" even if those devices are unplugged.
For my HomeSeer HSM200 sensors, I have a script that checks if any HSM200 has had Motion=On for too a long time, since it is likely someone unplugged the HSM200 (and its Motion turned On right before it was unplugged). I have another script to check each device's last update time and report if the device hasn't been updated for a certain amount of time. However, I still need a script to tell if any of my Aeotec Siren Gen 5 devices have been unplugged. If they are unplugged, polling still returns "OK". Since the Aeotec Sirens are only used as security alarms, and therefore will likely have status "Off" for many months at a time, I need a way to tell if someone unplugged them. When I unplug an Aeotec Siren, PollResult still returns "OK". The HomeSeer GUI's Z-Wave->Test Connectivity test will fail, as desired/expected.
What I really want to know: What HomeSeer API is equivalent to the Z-Wave->Test Connectivity so that I can call this HomeSeer API from a script? For some reason, polling can say "Ok" even though a device (e.g. Aeotec Siren and HomeSeer HSM200) is actually unreachable, while Z-Wave->Test Connectivity correctly reports if a device actually can't be reached.
Comment
Comment