ZWaveSerialApi.Devices
1.0.0
See the version list below for details.
dotnet add package ZWaveSerialApi.Devices --version 1.0.0
NuGet\Install-Package ZWaveSerialApi.Devices -Version 1.0.0
<PackageReference Include="ZWaveSerialApi.Devices" Version="1.0.0" />
paket add ZWaveSerialApi.Devices --version 1.0.0
#r "nuget: ZWaveSerialApi.Devices, 1.0.0"
// Install ZWaveSerialApi.Devices as a Cake Addin #addin nuget:?package=ZWaveSerialApi.Devices&version=1.0.0 // Install ZWaveSerialApi.Devices as a Cake Tool #tool nuget:?package=ZWaveSerialApi.Devices&version=1.0.0
C# Z-Wave Serial API
This API is for C#/.NET developers who want to create their own home automation tool using a Z-Wave USB stick, such as the Aeotec Z-Stick 7.
Since this API doesn't support Z-Wave protocol security (S0 or S2) it should not be used for burglar alarms, door locks, etc.
Requirements
- .NET 5.0
- Devices should already be included/added to the network. Use any other software for this purpose, eg. Z-Wave PC Controller (part of Simplicity Studio).
Examples
Getting started
using var network = new ZWaveNetwork("COM3");
await network.ConnectAsync();
var multiSensor = network.GetDevices<AeotecMultiSensor6>().First();
// Register for unsolicited motion notifications
multiSensor.MotionDetected += (_, _) =>
{
/* Motion detection started */
};
multiSensor.MotionIdle += (_, _) =>
{
/* Motion detection stopped */
};
// Get sensor values
var temperature = await multiSensor.GetTemperatureAsync(TemperatureScale.Celsius);
Console.WriteLine($"Temperature: {temperature.Value}{temperature.Unit}");
var humidity = await multiSensor.GetHumidityAsync(HumidityScale.Percentage);
Console.WriteLine($"Humidity: {humidity.Value}{humidity.Unit}");
Console.ReadKey();
Network settings persistance
When connecting, the API will attempt to query all unknown devices. Devices that are sleeping will be added when they wake up.
Cut down startup time by persisting the network information.
using var network = new ZWaveNetwork("COM3");
await network.LoadAsync("ZWaveNetwork.json");
await network.ConnectAsync();
// ... program logic ...
await network.SaveAsync("ZWaveNetwork.json");
Wake up processing
Make calls to battery operated devices while they are awake, either every time or just once.
var multiSensor = network.GetDevices<AeotecMultiSensor6>().First();
multiSensor.WakeUpNotification += async (_, _) =>
{
// ... processing every time device wakes up ...
};
async Task MultiSensorSetupAsync(object? sender, EventArgs eventArgs)
{
// ... one-time setup of device when it wakes up ...
multiSensor.WakeUpNotification -= MultiSensorSetupAsync;
}
multiSensor.WakeUpNotification += MultiSensorSetupAsync;
Device parameters
Read and write device configuration parameters.
var multiSensor = network.GetDevices<AeotecMultiSensor6>().First();
// Get current value
var timeout = await multiSensor.Parameters.MotionTimeout.GetAsync();
Console.WriteLine($"MotionTimeout: {timeout.TotalSeconds}");
// Set new value
await multiSensor.Parameters.MotionTimeout.SetAsync(TimeSpan.FromMinutes(1));
Using device location
When using multiple devices of the same type, it helps to assign a location to each device.
// Set location
var unknownMultiSensor = network.GetDevices<AeotecMultiSensor6>().First();
unknownMultiSensor.Location = "Kitchen";
// Get by location
var kitchenMultiSensor = network.GetDevice<AeotecMultiSensor6>("Kitchen");
Converting unsolicited values
Units for unsolicited values are defined in the configuration of each device. If there is a need to use alternative units they can be converted manually.
static void OutputBothTemperatureUnits(MultilevelSensorReport temperature)
{
switch (temperature.Scale)
{
case TemperatureScale.Celsius:
var farenheitValue = temperature.Value * 9 / 5 + 32;
var (farenheitUnit, _) = AttributeHelper.GetUnit(TemperatureScale.Fahrenheit);
Console.WriteLine($"Temperature = {temperature.Value}{temperature.Unit} / {farenheitValue}{farenheitUnit}");
break;
case TemperatureScale.Fahrenheit:
var celsiusValue = (temperature.Value - 32) * 5 / 9;
var (celsiusUnit, _) = AttributeHelper.GetUnit(TemperatureScale.Fahrenheit);
Console.WriteLine($"Temperature = {celsiusValue}{celsiusUnit} / {temperature.Value}{temperature.Unit}");
break;
}
}
var aerq = network.GetDevices<AeotecAerqSensor>().First();
aerq.TemperatureReport += (_, eventArgs) => OutputBothTemperatureUnits(eventArgs.Report);
Custom device types
Create an issue for missing devices. Until they are part of the API, you can create a custom type. See CustomMultilevelSensor.cs source code and below example for how it's used.
using var network = new ZWaveNetwork("COM3");
// Get the device type of the unsupported device, either
// 1) Input the data manually, eg.:
// var customDeviceType = new DeviceType(0x0086, 0x0002, 0x0064);
// *OR*
// 2) Get the data from a device already on the network, eg.:
var customDeviceType = network.GetUnsupportedDeviceTypes().First();
network.RegisterCustomDeviceType(customDeviceType, (client, deviceState) => new CustomMultilevelSensor(client, deviceState));
await network.ConnectAsync();
var multiSensor = network.GetDevices<CustomMultilevelSensor>().First();
var temperature = await multiSensor.GetTemperatureAsync(TemperatureScale.Celsius);
Features not supported
- Z-Wave security (ie. S0 and S2 classed communication with nodes)
- Multi channel communication
- Association groups (device signalling other device, bypassing controller)
- Scenes
- Inclusion/exclusion of devices
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.VisualStudio.Threading (>= 17.0.63)
- Serilog (>= 2.10.0)
- ZWaveSerialApi (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.