Hi
I've tasked myself with making a burglar alarm system as a bit of a side project. Very new to all this, except the programming side which I've done professionally for the last 23 years (mainly .NET).
Progress so far. Got an Aeotec Z-Stick Gen5 (device 001), this is in my pc and I have it detected and seen by the PC using openHAB. I then used the openHAB to add in 2 door sensor devices. Both sensors are detected and showing online.
Door sensor 004 is a Neo Coolcam
Door sensor 005 is a Fibaro
Then I switch over to a simple .NET console application and use the zwave4net library.
From piecing together bits of code I can find on the net I can see all the devices listed and iterate through them.
The Fibero (005) door sensor I can get to raise an event on the
var alarm = node.GetCommandClass<Alarm>();
alarm.Changed += (_, e) => {
LogMessage($"Alarm report of Node {e.Report.Node:D3} changed to [{e.Report}]");
}
08:28:30.0073321 Version: Z-Wave 4.54
08:28:30.0135671 HomeID: D72ED72E
08:28:30.0209015 ControllerID: 001
08:28:30.0237880 Node: 001, Generic = StaticController, Basic = StaticController, Listening = True
08:28:30.0314335 Node: 001, Neighbours =
08:28:35.5214052 Node: 004, Generic = SensorNotification, Basic = RoutingSlave, Listening = False
08:28:35.5296022 Node: 004, Neighbours =
08:28:35.5330908 Node: 005, Generic = SensorNotification, Basic = RoutingSlave, Listening = False
08:28:35.5382839 Node: 005, Neighbours =
08:29:22.5098799 Alarm report of Node 005 changed to [Type:General, Level:0, Detail:22, Unknown:0]
08:29:32.9548747 Alarm report of Node 005 changed to [Type:General, Level:0, Detail:23, Unknown:0]
The last two lines here you can see the event being raised. I assume that this is the event that detects whether the sensor is open or closed, however, it does seem pretty flakey. But I am at least getting some kind of a response.
The Neo Coolcam (004) however, I cannot get it to raise any event at all. The device appears to be working, showing as online on openHAB and the internal led on the device is lighting as the sensor is operated. Just no events.
Is there some way I can enable some kind of logging for the devices so I can see what kind of events they're broadcasting / receiving?
Some working code examples for the door sensors would be fantastic too if anyone has any available.
Does anyone know what is going on with the Neo Coolcam device?
Does anyone have any kind of resource they could point me to that may help?
I have attached my code as it stands now below, its only really what is readily available on the net currently though.
Thanks
Steve,
A Log file of the sensors in operation.
ZWave.log
using System;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
using ZWave;
using ZWave.Channel;
using ZWave.CommandClasses;
namespace ZWaveControllerSample
{
class Program
{
static void Main(string[] args)
{
var portName = "COM5";
var controller = new ZWaveController(portName);
controller.Channel.Log = Console.Out;
controller.Open();
try
{
Run(controller);
}
catch (AggregateException ex)
{
foreach (var inner in ex.InnerExceptions)
{
LogMessage($"{inner}");
}
}
catch (Exception ex)
{
LogMessage($"{ex}");
}
finally
{
Console.ReadLine();
controller.Close();
}
}
private static void LogMessage(string message)
{
var text = $"{DateTime.Now.TimeOfDay} {message}";
Console.WriteLine(text);
lock (typeof(File))
{
if (Directory.Exists(@"D:\Temp"))
{
File.AppendAllText(@"D:\Temp\ZWave.log", text + Environment.NewLine);
}
}
}
static private async Task Run(ZWaveController controller)
{
foreach (var node in await controller.GetNodes())
{
Console.WriteLine(node.NodeID);
var protocolInfo = await node.GetProtocolInfo();
Console.WriteLine(protocolInfo.BasicType);
Console.WriteLine(protocolInfo.GenericType);
}
LogMessage($"Version: {await controller.GetVersion()}");
LogMessage($"HomeID: {await controller.GetHomeID():X}");
var controllerNodeID = await controller.GetNodeID();
LogMessage($"ControllerID: {controllerNodeID:D3}");
var nodes = await controller.GetNodes();
foreach (var node in nodes)
{
var protocolInfo = await node.GetProtocolInfo();
LogMessage($"Node: {node}, Generic = {protocolInfo.GenericType}, Basic = {protocolInfo.BasicType}, Listening = {protocolInfo.IsListening} ");
var neighbours = await node.GetNeighbours();
LogMessage($"Node: {node}, Neighbours = {string.Join(", ", neighbours.Cast<object>().ToArray())}");
// subcribe to changes
Subscribe(node);
}
//byte motionSensorID = 5;
//// get the motionSensor
//var nodex = nodes[motionSensorID];
Console.ReadLine();
controller.Close();
}
private static void Subscribe(Node node)
{
node.UnknownCommandReceived += Node_UnknownCommandReceived;
var basic = node.GetCommandClass<Basic>();
basic.Changed += (_, e) => LogMessage($"Basic report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var sensorMultiLevel = node.GetCommandClass<SensorMultiLevel>();
sensorMultiLevel.Changed += (_, e) => LogMessage($"SensorMultiLevel report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var meter = node.GetCommandClass<Meter>();
meter.Changed += (_, e) => LogMessage($"Meter report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var alarm = node.GetCommandClass<Alarm>();
alarm.Changed += (_, e) =>
{
LogMessage($"Alarm report of Node {e.Report.Node:D3} changed to [{e.Report}]");
// sendEmail($"Alarm report of Node {e.Report.Node:D3} changed to [{e.Report}]");
};
var sensorBinary = node.GetCommandClass<SensorBinary>();
sensorBinary.Changed += (_, e) => LogMessage($"SensorBinary report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var sensorAlarm = node.GetCommandClass<SensorAlarm>();
sensorAlarm.Changed += (_, e) => LogMessage($"SensorAlarm report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var wakeUp = node.GetCommandClass<WakeUp>();
wakeUp.Changed += (_, e) => { LogMessage($"WakeUp report of Node {e.Report.Node:D3} changed to [{e.Report}]"); };
var switchBinary = node.GetCommandClass<SwitchBinary>();
switchBinary.Changed += (_, e) => LogMessage($"SwitchBinary report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var thermostatSetpoint = node.GetCommandClass<ThermostatSetpoint>();
thermostatSetpoint.Changed += (_, e) => LogMessage($"thermostatSetpoint report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var sceneActivation = node.GetCommandClass<SceneActivation>();
sceneActivation.Changed += (_, e) => LogMessage($"sceneActivation report of Node {e.Report.Node:D3} changed to [{e.Report}]");
var multiChannel = node.GetCommandClass<MultiChannel>();
multiChannel.Changed += (_, e) => LogMessage($"multichannel report of Node {e.Report.Node:D3} changed to [{e.Report}]");
}
private static void Node_UnknownCommandReceived(object sender, NodeEventArgs e)
{
throw new NotImplementedException();
}
}
}