roblans / ZWave4Net

ZWave4Net is a .NET library that interfaces with the Aeotec / Aeon Labs Z-Stick.
MIT License
41 stars 34 forks source link

Door sensor not working #55

Closed SteveGxr closed 3 years ago

SteveGxr commented 3 years ago

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();
    }

}

}

roblans commented 3 years ago

Add this line to get logging on serial level: controller.Channel.Log = Console.Out;

SteveGxr commented 3 years ago

Hi

Thanks for the quick response. I already had that included. It's not really helping.

The Fibero device is really only logging what I was already seeing and the Neo device still does not seem to be broadcasting anything.

You can see towards the bottom of the log where I am messing with the Fibero and it is logging the events. The Neo does not seem to raise anything.

zwave_controller_log_16062021.txt

I'm at a bit of a loss with this now. I've been fighting with this Neo sensor for the last 3 days and cannot seem to get it to create any response what so ever.

Any help would be greatly appreciated here.

Steve.

roblans commented 3 years ago

Run the code below. When the message "Please wakeup the sensor" appears wakeup the sensor by pressing the button and hit enter to continue.

        static async Task Main(string[] args)
        {
            var controller = new ZWaveController("COM5");

            controller.Channel.Log = Console.Out;

            controller.Open();

            var nodes = await controller.GetNodes();

            var sensor = nodes[004];

            var basic = sensor.GetCommandClass<Basic>();

            Console.WriteLine("Please wakeup the sensor.");
            Console.ReadLine();

            var report = await basic.Get();

            Console.WriteLine($"Value: {report.Value}");

            controller.Close();
        }
SteveGxr commented 3 years ago

I tried that code the other day and didn't get anywhere with it. Just given it another whirl now.

The only button on the device is the one inside it under the cover. I have tried pressing it once and then tried pressing it quickly three times (as per instructions to pair the device with the controller) both produce the same results.

The code hangs on the

var report = await basic.Get();

Line with the error

ZWave.Channel.Protocol.TransmissionException: 'Transmission failure: CompleteNoAcknowledge.'

This exception was originally thrown at this call stack: [External Code] ZWaveControllerSample.Program.Main(string[]) in Program.cs

Which from what I can gather is due to the device not being woken up, however, it is being detected and looks to be online and working. I cannot find anything anywhere that explains how to wake up a device (other than the pairing with the controller).

The logs on the console are also look to be reporting back problems.

zwave_controller_log_16062021_2.txt

I'm running out of ideas with this.

roblans commented 3 years ago

The only thing I can think of is to reset the sensor to factory settings.

The sensor will probally get a new NodeID

SteveGxr commented 3 years ago

Just had time to try this. It fixed it, the sensor started working perfectly once I removed and added it again.

Thanks for your help on this, its been much appreciated.