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

Z-Wave JS: Certification requirements for Meter CC not fulfilled #17

Open
1 of 2 tasks
marcelveldt opened this issue Jul 13, 2023 · 15 comments
Open
1 of 2 tasks
Assignees
Labels
backend This bug or request (primary) involves the Home Assistant backend/integration (and its dependencies) bug Something isn't working but should by design new feature New feature or request zwave-certification Required for Z-Wave certification

Comments

@marcelveldt
Copy link
Collaborator

marcelveldt commented Jul 13, 2023

From core created by AlCalzone: home-assistant/core#92799

The problem

If a device reports support for resetting meters, the end user must be able to perform this action. The driver exposes a writeonly value in this case, see node diagnostics.

We should add additional button entities, similar to PING or the planned IDENTIFY (Indicator CC).

  • Button to reset all meters
  • (optionally) buttons to reset individual meters

Diagnostics information

zwave_js-f0926e113c178046d0d249fcdc42964a-Node 58-24fb445b526b3d5d614f25141d6cc278.json.txt

@marcelveldt
Copy link
Collaborator Author

We need to add additional button entities to implement this

@marcelveldt marcelveldt added new feature New feature or request backend This bug or request (primary) involves the Home Assistant backend/integration (and its dependencies) and removed integration: zwave_js zwave-certification Required for Z-Wave certification labels Jul 13, 2023
@raman325
Copy link
Collaborator

is the zwave_js.reset_meter service not sufficient for this?

And how does a device advertise support for reset?

@AlCalzone
Copy link
Member

It's enough to pass the test (well, except for a bug in the test suite 🙄), but having buttons could be nice. Not sure.

@marcelveldt
Copy link
Collaborator Author

For certification there is nothing left to do, we have the service call.
Nice to have would be a button entity to reset the meter value(s)

@raman325
Copy link
Collaborator

Can we close this and add a nice to have issue? We can link to this one I just want to make the scope clear as I triage the board

@marcelveldt marcelveldt changed the title Z-Wave JS: Certification requirements for Meter CC not fulfilled Add button entity to reset Meter CC Nov 23, 2023
@marcelveldt
Copy link
Collaborator Author

done

@raman325 raman325 changed the title Add button entity to reset Meter CC Z-Wave JS: Certification requirements for Meter CC not fulfilled Nov 23, 2023
@raman325
Copy link
Collaborator

sorry, this is what I meant ^

@AlCalzone
Copy link
Member

AlCalzone commented Apr 25, 2024

Tested again, looks like the service call isn't working as expected.
home-assistant/core#116222

I also found some discrepancies from the specs, which mean the reset calls will need an overhaul anyways:
zwave-js/node-zwave-js#6921

@AlCalzone AlCalzone reopened this Apr 26, 2024
@marcelveldt marcelveldt added the bug Something isn't working but should by design label May 23, 2024
@AlCalzone
Copy link
Member

This mock-server script can be used to test the implementation. It simulates a node with 4 meter readings, two of which are accumulated and can be reset. Every 5 seconds, a random reading increases by a small amount.

To test, ensure that a reset all only results in a single call to Z-Wave JS and a single MeterCCReset being sent.

// @ts-check
const { CommandClasses } = require("@zwave-js/core");
const { ccCaps, createMockZWaveRequestFrame } = require("@zwave-js/testing");
const { roundTo } = require("alcalzone-shared/math");
const { RateType, MeterCCReport } = require("zwave-js");

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

const values = new Map([
	[0x00, 1],
	[0x03, 2.5],
	[0x04, 4],
	[0x05, 50],
]);

/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */
module.exports.default = {
	nodes: [
		{
			id: 2,
			capabilities: {
				commandClasses: [
					CommandClasses.Version,
					ccCaps({
						ccId: CommandClasses.Meter,
						isSupported: true,
						version: 6,
						meterType: 0x01, // Electric
						supportedScales: [0x00, 0x03, 0x04, 0x05],
						supportedRateTypes: [RateType.Consumed],
						supportsReset: true,
						getValue: (scale) => {
							return values.get(scale) ?? 0;
						},
						onReset: (options) => {
							if (!options) {
								values.set(0x00, 0);
								values.set(0x03, 0);
							} else {
								const { scale, targetValue } = options;
								values.set(scale, targetValue);
							}
						},
					}),
				],
			},
			behaviors: [
				{
					// Small hack - start the state simulation timer when the node
					// receives a command from the controller
					async onControllerFrame(controller, self, _frame) {
						if (!simulationTimer) {
							// Then send notifications regularly
							simulationTimer = setInterval(() => {
								// Randomly select a scale
								const scale = Array.from(values.keys())[
									Math.floor(Math.random() * values.size)
								];
								// Randomly increase the value by a small amount
								const newValue = (values.get(scale) ?? 0)
									+ roundTo(
										Math.random() * 5,
										1,
									);
								values.set(scale, newValue);

								const cc = new MeterCCReport(self.host, {
									nodeId: controller.host.ownNodeId,
									type: 0x01, // Electric
									scale,
									rateType: RateType.Consumed,
									value: newValue,
								});

								self.sendToController(
									createMockZWaveRequestFrame(cc, {
										ackRequested: false,
									}),
								);
								// Tune this value according to how often you want to get notifications
							}, 10000).unref();
						}
						return false;
					},
				},
			],
		},
	],
};

@MartinHjelmare
Copy link
Collaborator

MartinHjelmare commented Sep 2, 2024

TODO

  • Provide device diagnostics from the above emulation so we can write a test. There is one attached in the top post. Is that one accurate?
  • Write a test that reproduces the problem.
  • Fix it.

@AlCalzone
Copy link
Member

AlCalzone commented Sep 2, 2024

This issue is mostly fixed by home-assistant/core#119968, except the service call still behaves buggy: home-assistant/core#116222

IMO we should either remove the service call, or - if we want to support resetting individual meters - fix the behavior in the planned expert UI.

I'll create new device diagnostics to reproduce.

@MartinHjelmare
Copy link
Collaborator

Shouldn't we fix the service call first? We can still deprecate it, in preference of the button entity, but before the service is removed, it should still work.

@AlCalzone AlCalzone added the needs-diagnostics Needs device diagnostics to work on this label Sep 2, 2024
@AlCalzone
Copy link
Member

Does having device diagnostics help for debugging a service call? If so, I'll make sure we have an up to date diagnostics file.

@MartinHjelmare
Copy link
Collaborator

MartinHjelmare commented Sep 3, 2024

Yes, it'll help. I'm looking at the service issue. I can't even get it to perform the driver call. I'll continue looking at this on Thursday if I don't solve it before then.

@MartinHjelmare MartinHjelmare self-assigned this Sep 3, 2024
@AlCalzone
Copy link
Member

AlCalzone commented Sep 4, 2024

Diagnostics:
zwave_js-01J2ZVFHVQG8V8J9D9360S4VCQ-Node 2-6b3c038d0e8198c0853551db5e4df035.json

Screenshot:
grafik

Driver logs:

2024-09-04T11:08:54.265Z SERIAL » 0x011e00a90102129f03b7001af056c29d0243116db7edea507a2500000000b0a3  (32 bytes)
2024-09-04T11:08:54.265Z DRIVER » [Node 002] [REQ] [SendDataBridge]
                                  │ source node id:   1
                                  │ transmit options: 0x25
                                  │ callback id:      176
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 183
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0x1d3e277dd9eb854374d29f71cb
                                    │ ciphertext:      0x1af056c29d02
                                    │ auth data:       0x0102f88f6c270012b700
                                    │ auth tag:        0x43116db7edea507a
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCGet]
                                      │ session id:      14
                                      │ request updates: true
                                      └─[MeterCCReset]
2024-09-04T11:08:54.273Z SERIAL « [ACK]                                                                   (0x06)
2024-09-04T11:08:54.278Z SERIAL « 0x010401a90152                                                       (6 bytes)
2024-09-04T11:08:54.278Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.279Z DRIVER « [RES] [SendDataBridge]
                                    was sent: true
2024-09-04T11:08:54.293Z SERIAL « 0x011d00a9b000000100bb7f7f7f7f00000300000000030100007f7f7f7f7f3f    (31 bytes)
2024-09-04T11:08:54.294Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.294Z DRIVER « [REQ] [SendDataBridge]
                                    callback id:            176
                                    transmit status:        OK, took 10 ms
                                    routing attempts:       1
                                    protocol & route speed: Z-Wave, 100 kbit/s
                                    routing scheme:         LWR
                                    ACK RSSI:               -69 dBm
                                    ACK channel no.:        0
                                    TX channel no.:         0
2024-09-04T11:08:54.322Z SERIAL « 0x011a00a8000102119f031000fab06b6b6595a1ecf4f88bb0a000bb08          (28 bytes)
2024-09-04T11:08:54.323Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.323Z DRIVER « [Node 002] [REQ] [BridgeApplicationCommand]
                                  │ RSSI: -69 dBm
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 16
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0xebe0b3ec422e0e35d8bc91b08a
                                    │ plaintext:       0x6c020eff00
                                    │ auth tag:        0x95a1ecf4f88bb0a0
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCReport]
                                        session id:          14
                                        more updates follow: false
                                        status:              Success
                                        duration:            0s
2024-09-04T11:08:54.324Z SERIAL » 0x011e00a90102129f03b8006832c5df4883cdd7375d102cd6902500000000b168  (32 bytes)
2024-09-04T11:08:54.324Z DRIVER » [Node 002] [REQ] [SendDataBridge]
                                  │ source node id:   1
                                  │ transmit options: 0x25
                                  │ callback id:      177
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 184
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0x1936633aaaeef4dd359cce6677
                                    │ ciphertext:      0x6832c5df4883
                                    │ auth data:       0x0102f88f6c270012b800
                                    │ auth tag:        0xcdd7375d102cd690
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCGet]
                                      │ session id:      15
                                      │ request updates: true
                                      └─[MeterCCReset]
2024-09-04T11:08:54.330Z SERIAL « [ACK]                                                                   (0x06)
2024-09-04T11:08:54.336Z SERIAL « 0x010401a90152                                                       (6 bytes)
2024-09-04T11:08:54.336Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.336Z DRIVER « [RES] [SendDataBridge]
                                    was sent: true
2024-09-04T11:08:54.350Z SERIAL « 0x011d00a9b100000100bb7f7f7f7f00000300000000030100007f7f7f7f7f3e    (31 bytes)
2024-09-04T11:08:54.350Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.350Z DRIVER « [REQ] [SendDataBridge]
                                    callback id:            177
                                    transmit status:        OK, took 10 ms
                                    routing attempts:       1
                                    protocol & route speed: Z-Wave, 100 kbit/s
                                    routing scheme:         LWR
                                    ACK RSSI:               -69 dBm
                                    ACK channel no.:        0
                                    TX channel no.:         0
2024-09-04T11:08:54.395Z SERIAL « 0x011a00a8000102119f03110067338b9eed52a7bcf4ac5eb21800bb20          (28 bytes)
2024-09-04T11:08:54.396Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.397Z DRIVER « [Node 002] [REQ] [BridgeApplicationCommand]
                                  │ RSSI: -69 dBm
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 17
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0x026863cc2df68fc8622ad1192d
                                    │ plaintext:       0x6c020fff00
                                    │ auth tag:        0x52a7bcf4ac5eb218
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCReport]
                                        session id:          15
                                        more updates follow: false
                                        status:              Success
                                        duration:            0s
2024-09-04T11:08:54.398Z SERIAL » 0x011e00a90102129f03b90007bf212095810ac50fb9b8a798d82500000000b260  (32 bytes)
2024-09-04T11:08:54.398Z DRIVER » [Node 002] [REQ] [SendDataBridge]
                                  │ source node id:   1
                                  │ transmit options: 0x25
                                  │ callback id:      178
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 185
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0xa153b2b37f7f58451f70eeac16
                                    │ ciphertext:      0x07bf21209581
                                    │ auth data:       0x0102f88f6c270012b900
                                    │ auth tag:        0x0ac50fb9b8a798d8
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCGet]
                                      │ session id:      16
                                      │ request updates: true
                                      └─[MeterCCReset]
2024-09-04T11:08:54.405Z SERIAL « [ACK]                                                                   (0x06)
2024-09-04T11:08:54.411Z SERIAL « 0x010401a90152                                                       (6 bytes)
2024-09-04T11:08:54.411Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.411Z DRIVER « [RES] [SendDataBridge]
                                    was sent: true
2024-09-04T11:08:54.425Z SERIAL « 0x011d00a9b200000100bb7f7f7f7f00000300000000030100007f7f7f7f7f3d    (31 bytes)
2024-09-04T11:08:54.425Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.425Z DRIVER « [REQ] [SendDataBridge]
                                    callback id:            178
                                    transmit status:        OK, took 10 ms
                                    routing attempts:       1
                                    protocol & route speed: Z-Wave, 100 kbit/s
                                    routing scheme:         LWR
                                    ACK RSSI:               -69 dBm
                                    ACK channel no.:        0
                                    TX channel no.:         0
2024-09-04T11:08:54.461Z SERIAL « 0x011a00a8000102119f0312004aec35f14ba78a2451441b642000bb00          (28 bytes)
2024-09-04T11:08:54.462Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.462Z DRIVER « [Node 002] [REQ] [BridgeApplicationCommand]
                                  │ RSSI: -69 dBm
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 18
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0x5d798470b24921d90d6909d8dc
                                    │ plaintext:       0x6c0210ff00
                                    │ auth tag:        0xa78a2451441b6420
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCReport]
                                        session id:          16
                                        more updates follow: false
                                        status:              Success
                                        duration:            0s
2024-09-04T11:08:54.463Z SERIAL » 0x011e00a90102129f03ba0028b5a9c5f4c3884b6b4a686e21202500000000b3ca  (32 bytes)
2024-09-04T11:08:54.463Z DRIVER » [Node 002] [REQ] [SendDataBridge]
                                  │ source node id:   1
                                  │ transmit options: 0x25
                                  │ callback id:      179
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 186
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0x2c1260dca17e060b9926fbadac
                                    │ ciphertext:      0x28b5a9c5f4c3
                                    │ auth data:       0x0102f88f6c270012ba00
                                    │ auth tag:        0x884b6b4a686e2120
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCGet]
                                      │ session id:      17
                                      │ request updates: true
                                      └─[MeterCCReset]
2024-09-04T11:08:54.470Z SERIAL « [ACK]                                                                   (0x06)
2024-09-04T11:08:54.475Z SERIAL « 0x010401a90152                                                       (6 bytes)
2024-09-04T11:08:54.476Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.476Z DRIVER « [RES] [SendDataBridge]
                                    was sent: true
2024-09-04T11:08:54.490Z SERIAL « 0x011d00a9b300000100bb7f7f7f7f00000300000000030100007f7f7f7f7f3c    (31 bytes)
2024-09-04T11:08:54.491Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.491Z DRIVER « [REQ] [SendDataBridge]
                                    callback id:            179
                                    transmit status:        OK, took 10 ms
                                    routing attempts:       1
                                    protocol & route speed: Z-Wave, 100 kbit/s
                                    routing scheme:         LWR
                                    ACK RSSI:               -69 dBm
                                    ACK channel no.:        0
                                    TX channel no.:         0
2024-09-04T11:08:54.527Z SERIAL « 0x011a00a8000102119f0313002b40f9db480945cf747024cb4800bb4a          (28 bytes)
2024-09-04T11:08:54.528Z SERIAL » [ACK]                                                                   (0x06)
2024-09-04T11:08:54.528Z DRIVER « [Node 002] [REQ] [BridgeApplicationCommand]
                                  │ RSSI: -69 dBm
                                  └─[Security2CCMessageEncapsulation]
                                    │ sequence number: 19
                                    │ key:             0x44b45806725f2a6ebc3e2641f36f6caa
                                    │ IV:              0xee0151bb08a9bbc20e7d63fc40
                                    │ plaintext:       0x6c0211ff00
                                    │ auth tag:        0x0945cf747024cb48
                                    │ security class:  S2_Unauthenticated
                                    └─[SupervisionCCReport]
                                        session id:          17
                                        more updates follow: false
                                        status:              Success
                                        duration:            0s
2024-09-04T11:08:54.528Z DRIVER   all queues idle

@AlCalzone AlCalzone added zwave-certification Required for Z-Wave certification and removed needs-diagnostics Needs device diagnostics to work on this labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend This bug or request (primary) involves the Home Assistant backend/integration (and its dependencies) bug Something isn't working but should by design new feature New feature or request zwave-certification Required for Z-Wave certification
Projects
Development

No branches or pull requests

4 participants