Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of Door/Window state #23

Open
AlCalzone opened this issue Aug 24, 2023 · 5 comments · Fixed by zwave-js/node-zwave-js#6958
Open

Improve handling of Door/Window state #23

AlCalzone opened this issue Aug 24, 2023 · 5 comments · Fixed by zwave-js/node-zwave-js#6958

Comments

@AlCalzone
Copy link
Member

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
Copy link
Member Author

AlCalzone commented Aug 24, 2023

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
Copy link
Collaborator

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
Copy link
Member Author

AlCalzone commented Jul 30, 2024

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

Image

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

@AlCalzone
Copy link
Member Author

  • figure out why there are two identical-named entities with different states
  • figure out which is the working one
  • fix it

@AlCalzone
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

3 participants