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
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