From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview callable routines for Z-wave control of household appliances

Has anyone developed a software interface (Labview callable library) for the remote control of household appliances?  Specifically, Z-wave is a wireless protocol supported by multiple manufactures that has both USB and Wifi hardware interfaces.  Intermatic, for example, has a SDK inteface in C#, C++, etc. Has anyone yet taken the time to bundle the SDK routines or to talk directly to a Z-wave interface (USB/Wifi) within a Labview callable library?

 

Message 1 of 9
(8,055 Views)

I am working on a z-wave driver to control home automation using the ControlThink SDK that uses .NET.  Here is a snippet of the code:

 

 

Currently I'm having problems connecting to the USB controller.  If anyone can help please advise.  Yes, I have added the ControltThink.ZWave.dll as a reference to the calling VI and I do have it in the same folder as the .dll.

 

Sample.png

 

The error is:

 

Error calling method ControlThink.ZWave.ZWaveController.Connect of NULL ObjectId, (System.ArgumentNullException: Key cannot be null. Parameter name: key)
0 Kudos
Message 2 of 9
(7,543 Views)
I figured it out!  A Constructor Node is required for the reference.  Also, the ThinkEssentials.exe cannot be running while using the SDK .NET calls!
0 Kudos
Message 3 of 9
(7,497 Views)

So I have working code to control Z-Wave devices,  now I need help getting events from the event handler.  Can anyone who knows VB.NET help translate this code to LabView?  I have attached the dll and the sample code provided by ControlThink.  I'm not really sure how to set this up in LabView, but it seems like it would be very simple for someone who knows both VB.NET and LabView.  I get confused with all the properties and methods associated with the event handler.  I'm  interested in getting events when the level of a device has changed.

 

 

 

Setting up an event handler for handling a device’s Level update (node id #4)

 

[C#]

zc.Devices.GetByNodeID(4).LevelChanged += DeviceLevelChanged();

 

[VB.NET]

AddHandler zc.Devices.GetByNodeID(4).LevelChanged, AddressOf DeviceLevelChanged

 

The event handler for a device’s Level update, writing out the update level

 

[C#]

private void DeviceLevelChanged(object sender, ControlThink.Devices.LevelChangedEventArgs e)

{

ControlThink.ZWave.Devices.ZWaveDevice d =

(ControlThink.ZWave.Devices.ZWaveDevice)sender;

Console.WriteLine("Node ID #" + d.NodeID.ToString() + " level: " +

e.Level.ToString());

}

 

[VB.NET]

Public Sub DeviceLevelChanged(ByVal sender As Object, ByVal e As ControlThink.Devices.LevelChangedEventArgs)

    Dim d As ZWave.Devices.ZWaveDevice = DirectCast(sender, _

ZWave.Devices.ZWaveDevice)

    Console.WriteLine("Node ID #" & d.NodeID.ToString & " level: " & _

e.Level.ToString)

End Sub

 

0 Kudos
Message 4 of 9
(7,448 Views)

Hi kreienhe,

 

Without hardware to test this, I think this VI may work.  You may need to setup some other things beforehand (configure controller, start controller, etc.) but this should setup the LevelChanged callback. 

 

This example is based from the KnowledgeBase here (http://digital.ni.com/public.nsf/allkb/2B897E408671182F86257012005A5859?OpenDocument) and the .NET callback examples in the example finder.

Message 5 of 9
(7,419 Views)

Kyle,

 

I tried the event callback and I don't seem to get any response from the callback vi.  The program seems to run ok "No Error" and I set up code in the callback vi to toggle a boolean in the top level vi that has the register event and while loop.  The boolean value doesn't seem to change state.  I set up the boolean similar to the chart reference that you provided.  I have a simple foor loop (one iteration to hold the last value in a shift reg) to toggle the boolean when the callback vi executes.  It is my understanding that the callback vi is executed after an event happens.  So I'm thinking I am not getting a registered event.  I do have the two devices "associated" in the same group (Z-Wave terminology).  The controller (USB) and the battery powered motion sensor are the two devices that I am testing.  I do see the level of the controller change just after the motion detector changes state as they should when motion is detected if I poll both device values.  Polling is not a very good option because the battery powered motion and door sensors sleep to conserve battery power.  Thus the use of events to trigger the controller that a battery powered device has changed states. 

 

Here is the sequence of events:

 

1) Both levels for the controller and motion sensor are 0

2) Provide Motion to activate the motion sensor

3) The Motion Sensor Device Level changes from 0 to 255 for a short timeframe (sometimes too fast for me to see if i am polling all devices)

4) The Controller's Device Level changes from 0 to 255 and stays 255 for about two minutes.

 

 

As you can see I tell that a motion sensor has been activated, but I cannot tell which one based on polling if I have multiple sensors.  The sensor goes back to sleep too fast.
From controlthinks website I see that others are using hail events.  Not sure what those are or how to set them up or what else to try.
Thanks for you help,
Jason
Message Edited by kreienhe on 11-24-2009 01:51 PM
Message Edited by kreienhe on 11-24-2009 01:52 PM
0 Kudos
Message 6 of 9
(7,352 Views)

This post explains the hail events.

 

http://forums.controlthink.com/p/1824/6259.aspx#6259

0 Kudos
Message 7 of 9
(7,329 Views)

Hi kreienhe,

 

It sounds like you need to create 2 callbacks, where when the hail event callback occurs, you initiate the level change event to get the level value. 

 

Are there any better code snippets to help design the VI to see how it's called? 

0 Kudos
Message 8 of 9
(7,308 Views)

  Hi! I found your Vi really helpful, so I made some changes till it works with the controller without polling door sensors.

 

   1. Zwave.vi adds the controller to group 1 which is accosiated with door sensor/motion sensor/water sensor. 

   2. Monitor Level (callback).vi polls the controller every 2 sec. You can see that NodeID is sent out as soon as the event is triggered not until every 2 sec.

   3.LevelChanged Event Callback.vi used in Monitor Level (callback).vi as a callback vi. Basically, you can add your code here whenever an event is triggered. Send E-mail, for instance.

 

 

 

 

0 Kudos
Message 9 of 9
(6,644 Views)