zwave-js / certification-backlog

Issues and discussions related to Z-Wave certification of HA + Z-Wave JS
1 stars 0 forks source link

Improve handling of Door/Window state #23

Open AlCalzone opened 1 year ago

AlCalzone commented 1 year ago

Z-Wave JS exposes two semi-duplicate values for the Door/Window state notification value:

Value sent from device Door state Door state (simple)
open open (22) open (22)
open in regular position open in regular position (5632) open (22)
open in tilt position open in tilt position (5633) open (22)
closed closed (23) closed (23)

Unfortunately it is impossible to detect whether a device supports the "open in ... position" states, or just supports the CC version that includes them. As a result, the 4-state sensor is exposed as 3 or 4 binary sensor in HA, in addition to the 2-state sensor which adds another binary sensor.

This should be simplified into two binary sensors: open / close and tilted / not tilted.

AlCalzone commented 1 year ago

Here's a mock config file to test. This automatically sends random door state notifications every 5 seconds:

// @ts-check
const { NotificationCCReport } = require("@zwave-js/cc/NotificationCC");
const { CommandClasses } = require("@zwave-js/core");
const { ccCaps, createMockZWaveRequestFrame } = require("@zwave-js/testing");

let simulationTimer;
process.on("SIGINT", () => {
    if (simulationTimer) clearInterval(simulationTimer);
});

/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */
module.exports.default = {
    nodes: [
        {
            id: 2,
            capabilities: {
                commandClasses: [
                    CommandClasses.Version,
                    ccCaps({
                        ccId: CommandClasses.Notification,
                        isSupported: true,
                        version: 11,
                        notificationTypesAndEvents: {
                            // Access Control - Door state
                            [0x06]: [0x16, 0x17],
                        },
                    }),
                ],
            },
            behaviors: [
                {
                    // Small hack - start the state simulation timer when the node
                    // receives a command from the controller
                    async handleCC(controller, self, _frame) {
                        if (!simulationTimer) {
                            // Then send notifications regularly
                            simulationTimer = setInterval(() => {
                                // 75% of reports are open, 25% are closed
                                const isOpen = Math.random() < 0.75;
                                // 50% of reports include the tilt parameter
                                const supportsTilt = Math.random() < 0.5;
                                // 50% of those are tilted, 50% are not
                                const isTilted = Math.random() < 0.5;

                                const cc = new NotificationCCReport(self.host, {
                                    nodeId: controller.host.ownNodeId,
                                    notificationType: 0x06, // Access Control
                                    notificationEvent: isOpen ? 0x16 : 0x17,
                                    eventParameters: isOpen && supportsTilt
                                        ? Buffer.from([
                                            isTilted ? 0x01 : 0x00,
                                        ])
                                        : undefined,
                                });

                                self.sendToController(
                                    createMockZWaveRequestFrame(cc, {
                                        ackRequested: false,
                                    }),
                                );
                                // Tune this value according to how often you want to get notifications
                            }, 5000).unref();
                        }
                        return undefined;
                    },
                },
            ],
        },
    ],
};
marcelveldt commented 5 months ago

Its not possible to detect if the device support tilt so pre-creating an additional binary sensor for this will cause confusion. Idea is that we add support for "dynamic properties" in the driver, where the property is only added as soon as its noticed for the first time. @AlCalzone is going to check if this is possible somehow.

AlCalzone commented 4 months ago

This results in two identical-named entities with different states:

Image

zwave_js-01J2ZVFHVQG8V8J9D9360S4VCQ-Node 2-5bce3bf4e843614bfa12a4fa32c6243b.json.txt

AlCalzone commented 2 months ago
AlCalzone commented 2 months ago

Update from Shelly, who just noticed this aswell. The "simple" door state doesn't seem to match any entity in HA.

Z-Wave JS UI is showing the correct state: grafik

HA isn't: grafik