ACT Z-Wave PIR (live status): a code sample

ChrisWalker

Active Member
Here in the lab, we have a HomePro ZIR000 motion sensor.

Tonight, we wrote a few lines of code to get live reports from the motion sensor. It's very cool--the event is raised in our code just as the motion sensor indicates that there is motion--or that there is no longer motion.

First, we started out with 2 lines of code (VB.NET here):
Private controller As New ZWave.Controller
Private WithEvents device As ZWave.Devices.BinarySensor

This set up our controller, and the event handler for our device. We could have also just used "ZWaveDevice".

Then, in the Form_Load routine, we wrote:
controller.Connect("COM4")
device = controller.Devices.GetByNodeID(5)

Node #5, in this case, in our motion sensor. And our controller is on COM4.

Now, we just wait for events to be raised! Here's our LevelChanged event handler, which simply pops up a message box with the new device level:
Private Sub device_LevelChanged(ByVal sender As Object, ByVal e As ControlThink.ZWave.Devices.LevelChangedEventArgs) Handles device.LevelChanged
MsgBox("new level: " & e.Level)
End Sub

When motion is detected, we get a level of 255 (ON), and when motion is no longer detected, we get a level of 0 (OFF).

Here are a few things to remember:

1. You must associate the PIR with your USB/RS232 controller. You can do this with Device.Groups(1).Add(Controller.Devices.GetByNodeID(Controller.NodeID)) -- but your device must be "woken up" for this to work. Since it's a battery operated device, it can't talk when it's asleep. You may need to try this a few times.
2. Be sure to set Configuration Parameter #17 to value 2 for "sensor mode"--this is easy to do from the ACT remote.

[NOTE: you must have a copy of the ControlThink Z-Wave PC SDK, v1.1 beta build 123 or better to use this code]

Chris
 

Rupp

Senior Member
Chris,
What kind of times are you seeing between the motion and the event being raised?

PS.

Chris, did you send me a PM at the HS BB? If so can you resend it. I couldn't get into my PM accounts and had to reset it. TIA

Greg
 

ChrisWalker

Active Member
Rupp said:
Chris,
What kind of times are you seeing between the motion and the event being raised?

PS.

Chris, did you send me a PM at the HS BB? If so can you resend it. I couldn't get into my PM accounts and had to reset it. TIA

Greg
Rupp: the time between the motion and the event being raised is completely based on the responsiveness of the PIR itself.

I would say that the responsiveness of the PIR is quick, but not instantaneous.

The time between the notification by the PIR and the event in the SDK library is, generally speaking, instantaneous. We're probably talking 20-80ms in direct range, 100ms-250ms even with four hops.

BTW, I just PM'd you and e-mailed you through the forum.

Chris
 

ChrisWalker

Active Member
Rupp said:
What kind of times are you seeing between the motion and the event being raised?
Rupp: I did a test today to see how fast the ACT PIR reacts.

It seems to be instantaneous, actually, which is very nice.

For the test, I stuck the PIR inside of a dark cylinder. When I opened up the cylinder and pulled the PIR out (which I did in one swift movement), the event was raised in the SDK so quickly I could notice no delay.

I'm guessing that the delay is between 100ms to 250ms max, which is fast enough for motion-sensing "lights" in a home. I'm pretty impressed.

Please note that I haven't tested the PIR for actual motion yet--just for near-absolute darkness to light. I'm assuming the response is really quick in the motion scenario too. If you want, I can run another test.

Chris
 
Top