From 90e2ad3902d8113681eb35ff6ec816179c39724e Mon Sep 17 00:00:00 2001 From: Ole Markus With Date: Sun, 1 Nov 2026 18:13:59 +0100 Subject: [PATCH] Expose heat exchanger rotor speed Read AO:0 as a read-only percentage sensor for both Nordic transports, including automatic capability migration for existing paired devices. Enable Insights and cover zero values, unsupported cloud reads, and fake-unit BACnet polling. --- .../measure_heat_exchanger_speed_percent.json | 17 +++++++++ app.json | 19 ++++++++++ drivers/nordic-cloud/driver.compose.json | 1 + drivers/nordic/driver.compose.json | 1 + lib/FlexitNordicBaseDevice.ts | 1 + lib/UnitRegistry.ts | 15 ++++---- test/cloud_transport.vitest.ts | 38 +++++++++++++++++++ test/nordic_device.vitest.ts | 12 ++++++ test/unit_registry_fake_e2e.vitest.ts | 15 ++++++++ 9 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 .homeycompose/capabilities/measure_heat_exchanger_speed_percent.json diff --git a/.homeycompose/capabilities/measure_heat_exchanger_speed_percent.json b/.homeycompose/capabilities/measure_heat_exchanger_speed_percent.json new file mode 100644 index 0000000..fca924a --- /dev/null +++ b/.homeycompose/capabilities/measure_heat_exchanger_speed_percent.json @@ -0,0 +1,17 @@ +{ + "type": "number", + "title": { + "en": "Heat exchanger speed" + }, + "icon": "/assets/capabilities/measure_motor_rpm.svg", + "units": { + "en": "%" + }, + "min": 0, + "max": 100, + "decimals": 0, + "getable": true, + "setable": false, + "uiComponent": "sensor", + "insights": true +} diff --git a/app.json b/app.json index 682356e..7879e2e 100644 --- a/app.json +++ b/app.json @@ -627,6 +627,7 @@ "measure_humidity", "dehumidification_active", "free_cooling_active", + "measure_heat_exchanger_speed_percent", "measure_power", "fan_mode", "ventilation_stopped", @@ -1227,6 +1228,7 @@ "measure_humidity", "dehumidification_active", "free_cooling_active", + "measure_heat_exchanger_speed_percent", "measure_power", "fan_mode", "ventilation_stopped", @@ -1896,6 +1898,23 @@ "setable": false, "insights": true }, + "measure_heat_exchanger_speed_percent": { + "type": "number", + "title": { + "en": "Heat exchanger speed" + }, + "icon": "/assets/capabilities/measure_motor_rpm.svg", + "units": { + "en": "%" + }, + "min": 0, + "max": 100, + "decimals": 0, + "getable": true, + "setable": false, + "uiComponent": "sensor", + "insights": true + }, "measure_motor_rpm": { "type": "number", "title": { diff --git a/drivers/nordic-cloud/driver.compose.json b/drivers/nordic-cloud/driver.compose.json index a178703..d23dcf3 100644 --- a/drivers/nordic-cloud/driver.compose.json +++ b/drivers/nordic-cloud/driver.compose.json @@ -17,6 +17,7 @@ "measure_humidity", "dehumidification_active", "free_cooling_active", + "measure_heat_exchanger_speed_percent", "measure_power", "fan_mode", "ventilation_stopped", diff --git a/drivers/nordic/driver.compose.json b/drivers/nordic/driver.compose.json index 15d647d..7715657 100644 --- a/drivers/nordic/driver.compose.json +++ b/drivers/nordic/driver.compose.json @@ -17,6 +17,7 @@ "measure_humidity", "dehumidification_active", "free_cooling_active", + "measure_heat_exchanger_speed_percent", "measure_power", "fan_mode", "ventilation_stopped", diff --git a/lib/FlexitNordicBaseDevice.ts b/lib/FlexitNordicBaseDevice.ts index 57c23b1..4fd2370 100644 --- a/lib/FlexitNordicBaseDevice.ts +++ b/lib/FlexitNordicBaseDevice.ts @@ -47,6 +47,7 @@ const REQUIRED_CAPABILITIES = [ RESET_FILTER_CAPABILITY, 'measure_fan_setpoint_percent', 'measure_fan_setpoint_percent.extract', + 'measure_heat_exchanger_speed_percent', ] as const; interface SuppressedSetting { diff --git a/lib/UnitRegistry.ts b/lib/UnitRegistry.ts index 146bf7f..c1429b9 100644 --- a/lib/UnitRegistry.ts +++ b/lib/UnitRegistry.ts @@ -212,6 +212,7 @@ const COOKER_HOOD_ON = 1; const FREE_COOLING_ACTIVE_MODE_VALUE = 10; const BACNET_OBJECTS = { + heatExchangerSpeed: { type: OBJECT_TYPE.ANALOG_OUTPUT, instance: 0 }, comfortButton: { type: OBJECT_TYPE.BINARY_VALUE, instance: 50 }, comfortButtonDelay: { type: OBJECT_TYPE.POSITIVE_INTEGER_VALUE, instance: 318 }, ventilationMode: { type: OBJECT_TYPE.MULTI_STATE_VALUE, instance: 42 }, @@ -359,6 +360,7 @@ const CAPABILITY_MAPPINGS = [ { dataKey: 'measure_temperature.outdoor', capability: 'measure_temperature.outdoor' }, { dataKey: 'measure_temperature.exhaust', capability: 'measure_temperature.exhaust' }, { dataKey: 'measure_temperature.extract', capability: 'measure_temperature.extract' }, + { dataKey: 'measure_heat_exchanger_speed_percent', capability: 'measure_heat_exchanger_speed_percent' }, { dataKey: 'measure_power', capability: 'measure_power' }, { dataKey: 'measure_humidity', capability: 'measure_humidity' }, { dataKey: 'measure_motor_rpm', capability: 'measure_motor_rpm' }, @@ -865,6 +867,7 @@ function buildPollRequest() { presentValueRequest({ type: OBJECT_TYPE.ANALOG_INPUT, instance: 96 }), // Humidity presentValueRequest({ type: OBJECT_TYPE.ANALOG_VALUE, instance: 194 }), // Heater Power presentValueRequest(BACNET_OBJECTS.heatingCoilEnable), // Heating coil enable + presentValueRequest(BACNET_OBJECTS.heatExchangerSpeed), // Rotor speed % // Fan capabilities presentValueRequest({ type: OBJECT_TYPE.ANALOG_INPUT, instance: 5 }), // Fan RPM Supply @@ -911,6 +914,10 @@ function buildPollRequest() { } const POLL_VALUE_MAPPINGS: Record void> = { + [objectKey( + BACNET_OBJECTS.heatExchangerSpeed.type, + BACNET_OBJECTS.heatExchangerSpeed.instance, + )]: mapPollValue('measure_heat_exchanger_speed_percent'), [objectKey( TARGET_TEMPERATURE_OBJECTS.home.type, TARGET_TEMPERATURE_OBJECTS.home.instance, @@ -4564,13 +4571,7 @@ export class UnitRegistry { paths.slice(midpoint), depth + 1, ); - const datapoints = { ...firstHalf, ...secondHalf }; - if (Object.keys(datapoints).length === 0) { - throw new Error( - `[UnitRegistry] Cloud poll for ${unit.unitId} (plant ${plantId}) returned no datapoints`, - ); - } - return datapoints; + return { ...firstHalf, ...secondHalf }; } } diff --git a/test/cloud_transport.vitest.ts b/test/cloud_transport.vitest.ts index e322242..aadf816 100644 --- a/test/cloud_transport.vitest.ts +++ b/test/cloud_transport.vitest.ts @@ -90,6 +90,9 @@ function defaultSensorValues(): Array<{ type: number; instance: number; value: n { type: OBJ.ANALOG_VALUE, instance: 194, value: 0.5 }, // heater power (kW) { type: OBJ.BINARY_VALUE, instance: 445, value: 1 }, // heating coil on + // Rotor speed percentage is separate from heater power and efficiency. + { type: OBJ.ANALOG_OUTPUT, instance: 0, value: 6.25 }, + // Fan { type: OBJ.ANALOG_INPUT, instance: 5, value: 1200 }, // supply RPM { type: OBJ.ANALOG_INPUT, instance: 12, value: 1180 }, // extract RPM @@ -411,6 +414,7 @@ describe('Cloud transport – UnitRegistry integration', () => { expect(mock.capabilityValues['measure_temperature.exhaust']).toBe(22.0); expect(mock.capabilityValues['measure_temperature.extract']).toBe(23.1); expect(mock.capabilityValues['measure_humidity']).toBe(45); + expect(mock.capabilityValues['measure_heat_exchanger_speed_percent']).toBe(6.25); expect(mock.capabilityValues['measure_motor_rpm']).toBe(1200); expect(mock.capabilityValues['measure_motor_rpm.extract']).toBe(1180); expect(mock.capabilityValues['measure_fan_speed_percent']).toBe(75); @@ -422,6 +426,40 @@ describe('Cloud transport – UnitRegistry integration', () => { expect(mock.capabilityValues['measure_power']).toBe(500); }); + it.each([0, 6.25, 100])('reports heat exchanger speed %s as a percentage via cloud', async (speed) => { + const sensorValues = defaultSensorValues(); + sensorValues.find((entry) => entry.type === OBJ.ANALOG_OUTPUT && entry.instance === 0)!.value = speed; + mockClient = makeMockCloudClient({ sensorValues }); + registry.registerCloud(UNIT_ID, mock.device, { plantId: PLANT_ID, client: mockClient }); + await sleep(50); + + expect(mock.capabilityValues['measure_heat_exchanger_speed_percent']).toBe(speed); + const paths = mockClient.readDatapoints.getCalls().flatMap((call) => call.args[1]); + expect(paths).toContain(bacnetObjectToCloudPath(OBJ.ANALOG_OUTPUT, 0)); + expect(mockClient.writeDatapoint.called).toBe(false); + }); + + it.each([ + { paths: [bacnetObjectToCloudPath(OBJ.ANALOG_OUTPUT, 0)] }, + { paths: [bacnetObjectToCloudPath(OBJ.ANALOG_OUTPUT, 0), bacnetObjectToCloudPath(OBJ.ANALOG_INPUT, 5)] }, + ])('continues cloud polling without inventing rotor speed with unsupported paths $paths', async ({ paths }) => { + mockClient = makeMockCloudClient({ + sensorValues: defaultSensorValues().filter((entry) => ( + entry.type !== OBJ.ANALOG_OUTPUT || entry.instance !== 0 + )), + unsupportedReadPaths: paths, + }); + registry.registerCloud(UNIT_ID, mock.device, { plantId: PLANT_ID, client: mockClient }); + await sleep(100); + + const unit = (registry as any).units.get(UNIT_ID); + expect(paths.every((path) => unit.unsupportedCloudPollPaths.has(path))).toBe(true); + expect(unit.consecutiveFailures).toBe(0); + expect(mock.capabilityValues['measure_heat_exchanger_speed_percent']).toBe(undefined); + expect(mock.capabilityValues.measure_temperature).toBe(21.5); + expect(mock.device.setUnavailable.called).toBe(false); + }); + it('writes temperature setpoint via cloud', async () => { registry.registerCloud(UNIT_ID, mock.device, { plantId: PLANT_ID, diff --git a/test/nordic_device.vitest.ts b/test/nordic_device.vitest.ts index 8a0e845..e549fb1 100644 --- a/test/nordic_device.vitest.ts +++ b/test/nordic_device.vitest.ts @@ -189,6 +189,18 @@ describe('Nordic device', () => { expect(registryStub.register.calledOnceWithExactly('test_unit', device)).toBe(true); }); + it('adds the heat exchanger sensor to an existing paired device', async () => { + const device = new DeviceClass(); + device.hasCapability.withArgs('measure_heat_exchanger_speed_percent').returns(false); + + await device.onInit(); + + expect(device.addCapability.calledOnceWithExactly('measure_heat_exchanger_speed_percent')).toBe(true); + expect(device.registerCapabilityListener.getCalls().some((call: any) => ( + call.args[0] === 'measure_heat_exchanger_speed_percent' + ))).toBe(false); + }); + it('adds dehumidification capability during onInit when missing', async () => { const device = new DeviceClass(); device.hasCapability.withArgs(EXHAUST_TEMP_CAPABILITY).returns(true); diff --git a/test/unit_registry_fake_e2e.vitest.ts b/test/unit_registry_fake_e2e.vitest.ts index 00d78c3..087d43f 100644 --- a/test/unit_registry_fake_e2e.vitest.ts +++ b/test/unit_registry_fake_e2e.vitest.ts @@ -436,6 +436,21 @@ describe('UnitRegistry fake-unit e2e', { timeout: 10000 }, () => { expect(device.setUnavailable.notCalled).toBe(true); }); + it('polls heat exchanger speed over BACnet and reports zero when ventilation stops', async () => { + const device = makeMockDevice(SERVER_BIND_ADDRESS, serverPort, 4380); + registry.register('test_unit', device); + const hasSpeed = (speed: number) => device.setCapabilityValue.getCalls().some((call: any) => ( + call.args[0] === 'measure_heat_exchanger_speed_percent' && call.args[1] === speed + )); + + await waitFor(() => hasSpeed(65)); + const observed = state.readPresentValue(OBJECT_TYPE.ANALOG_OUTPUT, 0, PROPERTY_ID.PRESENT_VALUE); + expect(observed.ok && observed.value.value).toBe(65); + + await registry.stopVentilation('test_unit'); + await waitFor(() => hasSpeed(0)); + }); + it('writes filter change interval to the unit and verifies it', async () => { const device = makeMockDevice(SERVER_BIND_ADDRESS, serverPort, 4380); state.setFilterLimitHours(4380);