From 7feb584cdaedb88f3bfe319108301ad5189ee727 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Wed, 29 Jun 2022 04:06:01 +0000 Subject: [PATCH 1/9] add humidity sensor via direct access --- config.schema.json | 5 +++++ src/ductless.ts | 51 +++++++++++++++++++++++++++++++++++++++++- src/ductless_simple.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ src/kumo-api.ts | 14 ++++++++---- 4 files changed, 116 insertions(+), 5 deletions(-) diff --git a/config.schema.json b/config.schema.json index 4587979..5eace1f 100644 --- a/config.schema.json +++ b/config.schema.json @@ -22,6 +22,11 @@ "type": "boolean", "required": false }, + "useExternalSensor": { + "title": "Use external sensor? (requires direct access)", + "type": "boolean", + "required": false + }, "simpleDuctless": { "title": "Show simple HeaterCooler accessory only?", "type": "boolean", diff --git a/src/ductless.ts b/src/ductless.ts index 62095a9..e1d795c 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -20,11 +20,13 @@ export class KumoPlatformAccessory_ductless { private Fan: Service; private PowerSwitch: Service; private Dehumidifier: Service; + private Humdity: Service | null; private lastupdate; private lastquery; private directAccess; + private useExternalSensor; private historyService: fakegato.FakeGatoHistoryService; @@ -33,6 +35,7 @@ export class KumoPlatformAccessory_ductless { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; + this.useExternalSensor = this.platform.config.useExternalSensor; // determine device profile and additional sensors to tailor accessory to // the capabilities of the kumo device @@ -79,6 +82,13 @@ export class KumoPlatformAccessory_ductless { this.Fan.setCharacteristic(this.platform.Characteristic.Name, 'Fan'); this.PowerSwitch.setCharacteristic(this.platform.Characteristic.Name, 'Power'); + this.Humdity = this.useExternalSensor && this.directAccess ? this.accessory.getService( + this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + + if (this.Humdity) { + this.Humdity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -147,6 +157,11 @@ export class KumoPlatformAccessory_ductless { // .on('get', this.handleDehumidiferActiveGet.bind(this)) // .on('set', this.handleDehumidiferActiveSet.bind(this)); + if (this.Humdity) { + this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) + .on('get', this.handleHumidityGet.bind(this)); + } + this.updateDevice(); // setup interval for updating device for historyService @@ -239,6 +254,14 @@ export class KumoPlatformAccessory_ductless { callback(null, this.Dehumidifier.getCharacteristic(this.platform.Characteristic.On).value); } + async handleHumidityGet(callback) { + if (!this.Humdity) { + return; + } + await this.updateAccessoryCharacteristics(); + callback(null, this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); + } + async updateAccessoryCharacteristics() { // updateAccessoryCharacteristics @@ -259,6 +282,7 @@ export class KumoPlatformAccessory_ductless { this.updateFanSwingMode(); this.updatePowerSwitchOn(); this.updateDehumidifierSwitchOn(); + this.updateCurrentRelativeHumidity(); //this.platform.log.debug('updateAccessoryCharacteristic completed (%s)', this.accessory.context.serial) return true; @@ -306,12 +330,37 @@ export class KumoPlatformAccessory_ductless { return false; } this.platform.log.debug('%s (queryDevice_Direct): success.', this.accessory.displayName); + + if (this.Humdity) { + this.platform.log.info('querying external sensors on %s', this.accessory.context.serial); + const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); + if (sensorData) { + this.accessory.context.sensors = sensorData; + } + } } // update device contect this.accessory.context.device = device; return true; - } + } + + private updateCurrentRelativeHumidity() { + if (!this.Humdity) { + return; + } + let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; + if (this.accessory.context.sensors.length) { + const ourSensor = this.accessory.context.sensors[0]; + currentValue = ourSensor.humidity; + this.platform.log.debug('setting humidity to %s', currentValue); + + if (ourSensor.battery) { + this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); + } + } + this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); + } private updateHeaterCoolerActive() { // HeaterCooler Active diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 0ec3ed0..8d545ff 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -7,6 +7,7 @@ import { KumoDevice, KumoDeviceDirect } from './kumo-api'; import { KumoHomebridgePlatform } from './platform'; import { KUMO_LAG, KUMO_DEVICE_WAIT } from './settings'; +import util from 'util'; /* * Platform Accessory - Kumo 'ductless' accessory tested with a @@ -16,11 +17,13 @@ import { KUMO_LAG, KUMO_DEVICE_WAIT } from './settings'; */ export class KumoPlatformAccessory_ductless_simple { private HeaterCooler: Service; + private Humdity: Service | null; private lastupdate; private lastquery; private directAccess; + private useExternalSensor; private historyService: fakegato.FakeGatoHistoryService; @@ -29,6 +32,7 @@ export class KumoPlatformAccessory_ductless_simple { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; + this.useExternalSensor = this.platform.config.useExternalSensor; // set accessory information if (accessory.context.zoneTable.unitType !== undefined && accessory.context.zoneTable.unitType !== null) { @@ -47,9 +51,16 @@ export class KumoPlatformAccessory_ductless_simple { this.HeaterCooler = this.accessory.getService( this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler); + this.Humdity = this.useExternalSensor && this.directAccess ? this.accessory.getService( + this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + // set sevice names. this.HeaterCooler.setCharacteristic(this.platform.Characteristic.Name, 'Heater/Cooler'); + if (this.Humdity) { + this.Humdity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -79,6 +90,11 @@ export class KumoPlatformAccessory_ductless_simple { this.HeaterCooler.getCharacteristic(this.platform.Characteristic.SwingMode) .on('set', this.handleFanSwingModeSet.bind(this)); + if (this.Humdity) { + this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) + .on('get', this.handleHumidityGet.bind(this)); + } + this.updateDevice(); // setup interval for updating device for historyService @@ -138,6 +154,14 @@ export class KumoPlatformAccessory_ductless_simple { callback(null, this.HeaterCooler.getCharacteristic(this.platform.Characteristic.SwingMode).value); } + async handleHumidityGet(callback) { + if (!this.Humdity) { + return; + } + await this.updateAccessoryCharacteristics(); + callback(null, this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); + } + async updateAccessoryCharacteristics() { // updateAccessoryCharacteristics @@ -155,6 +179,7 @@ export class KumoPlatformAccessory_ductless_simple { this.updateCurrentTemperature(); this.updateFanRotationSpeed(); this.updateFanSwingMode(); + this.updateCurrentRelativeHumidity(); //this.platform.log.debug('updateAccessoryCharacteristic completed (%s)', this.accessory.context.serial) return true; @@ -202,6 +227,15 @@ export class KumoPlatformAccessory_ductless_simple { return false; } this.platform.log.debug('%s (queryDevice_Direct): success.'); + + if (this.Humdity) { + this.platform.log.info('querying external sensors on %s', this.accessory.context.serial); + const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); + if (sensorData) { + this.accessory.context.sensors = sensorData; + } + } + } // update device contect @@ -316,6 +350,23 @@ export class KumoPlatformAccessory_ductless_simple { temp: currentValue, }); } + + private updateCurrentRelativeHumidity() { + if (!this.Humdity) { + return; + } + let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; + if (this.accessory.context.sensors.length) { + const ourSensor = this.accessory.context.sensors[0]; + currentValue = ourSensor.humidity; + this.platform.log.debug('setting humidity to %s', currentValue); + + if (ourSensor.battery) { + this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); + } + } + this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); + } private updateFanRotationSpeed() { // FanRotationSpeed diff --git a/src/kumo-api.ts b/src/kumo-api.ts index 40e226f..c7138a8 100644 --- a/src/kumo-api.ts +++ b/src/kumo-api.ts @@ -63,6 +63,13 @@ interface KumoDeviceDirectInterface { vaneDir: string, } +interface KumoSensorData { + battery: number; + humidity: number; + temperature: number; + uuid: string; +} + export type KumoDeviceDirect = Readonly; // Renew Kumo security credentials every so often, in hours. @@ -349,7 +356,7 @@ export class KumoApi { return true; } - // querying sensors (not implemented as not available to test) + // querying sensors async queryDeviceSensors_Direct(serial: string) { const data = await this.directRequest('{"c":{"sensors":{}}}', serial); if(!data){ @@ -357,14 +364,13 @@ export class KumoApi { } this.log.debug(util.inspect(data, { colors: true, sorted: true, depth: 3 })); - const deviceSensors = [] as any; + const deviceSensors = [] as KumoSensorData[]; try { const sensors = data.r.sensors; for(const sensor in sensors) { if(sensors[sensor].uuid !== null && sensors[sensor].uuid !== undefined) { this.log.debug('Found sensor.uuid: %s', sensors[sensor].uuid); - const uuid:string = sensors[sensor].uuid; - deviceSensors.push(uuid); + deviceSensors.push(sensors[sensor]); } } From 2e25646b1030b6bbd7703944d5982fc0aec458ff Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Wed, 29 Jun 2022 04:34:28 +0000 Subject: [PATCH 2/9] detect if the sensor exists automatically --- config.schema.json | 5 ----- src/ductless.ts | 3 ++- src/ductless_simple.ts | 3 ++- src/platform.ts | 24 ++++++++++++++++-------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/config.schema.json b/config.schema.json index 5eace1f..4587979 100644 --- a/config.schema.json +++ b/config.schema.json @@ -22,11 +22,6 @@ "type": "boolean", "required": false }, - "useExternalSensor": { - "title": "Use external sensor? (requires direct access)", - "type": "boolean", - "required": false - }, "simpleDuctless": { "title": "Show simple HeaterCooler accessory only?", "type": "boolean", diff --git a/src/ductless.ts b/src/ductless.ts index e1d795c..06c3e34 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -33,9 +33,10 @@ export class KumoPlatformAccessory_ductless { constructor( private readonly platform: KumoHomebridgePlatform, private readonly accessory: PlatformAccessory, + private readonly hasSensors: boolean, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.platform.config.useExternalSensor; + this.useExternalSensor = hasSensors; // determine device profile and additional sensors to tailor accessory to // the capabilities of the kumo device diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 8d545ff..0f11a45 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -30,9 +30,10 @@ export class KumoPlatformAccessory_ductless_simple { constructor( private readonly platform: KumoHomebridgePlatform, private readonly accessory: PlatformAccessory, + private readonly hasSensors: boolean, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.platform.config.useExternalSensor; + this.useExternalSensor = hasSensors; // set accessory information if (accessory.context.zoneTable.unitType !== undefined && accessory.context.zoneTable.unitType !== null) { diff --git a/src/platform.ts b/src/platform.ts index 50c7f2b..1f9d52e 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -132,10 +132,12 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if(existingAccessory.context.zoneTable.unitType === 'ductless' || existingAccessory.context.zoneTable.unitType === 'mvz') { this.log.info('Initializing "%s" as ductless unit.', existingAccessory.displayName); + this.log.info('seeing if "%s" has a sensor attached', existingAccessory.displayName); + const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, existingAccessory); + new KumoPlatformAccessory_ductless_simple(this, existingAccessory, hasSensors); } else { - new KumoPlatformAccessory_ductless(this, existingAccessory); + new KumoPlatformAccessory_ductless(this, existingAccessory, hasSensors); } } else { this.log.info('Initializing "%s" of unitType "%s" as generic (unspecified) unit.', @@ -148,10 +150,12 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if((existingAccessory.context.device.sp_heat !== undefined || existingAccessory.context.device.spHeat !== undefined) && ( existingAccessory.context.device.sp_cool !== undefined || existingAccessory.context.device.spCool !== undefined)) { this.log.info('%s: Found heat and cool settings will use ductless accessory', existingAccessory.displayName); + this.log.info('seeing if "%s" has a sensor attached', existingAccessory.displayName); + const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, existingAccessory); + new KumoPlatformAccessory_ductless_simple(this, existingAccessory, hasSensors); } else { - new KumoPlatformAccessory_ductless(this, existingAccessory); + new KumoPlatformAccessory_ductless(this, existingAccessory, hasSensors); } } else { this.log.info('%s: Using platformaAccessory.ts accessory.', existingAccessory.displayName); @@ -200,10 +204,12 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if(accessory.context.zoneTable.unitType === 'ductless' || accessory.context.zoneTable.unitType === 'mvz') { this.log.info('Initializing "%s" as ductless unit.', device.label); + this.log.info('seeing if "%s" has a sensor attached', device.label); + const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, accessory); + new KumoPlatformAccessory_ductless_simple(this, accessory, hasSensors); } else { - new KumoPlatformAccessory_ductless(this, accessory); + new KumoPlatformAccessory_ductless(this, accessory, hasSensors); } } else { this.log.info('Initializing "%s" of unitType "%s" as generic (unspecified) unit.', @@ -216,10 +222,12 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if((accessory.context.device.sp_heat !== undefined || accessory.context.device.spHeat !== undefined ) && ( accessory.context.device.sp_cool !== undefined || accessory.context.device.spCool !== undefined )) { this.log.info('%s: Found heat and cool settings will use ductless accessory', accessory.displayName); + this.log.info('seeing if "%s" has a sensor attached', device.displayName); + const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, accessory); + new KumoPlatformAccessory_ductless_simple(this, accessory, hasSensors); } else { - new KumoPlatformAccessory_ductless(this, accessory); + new KumoPlatformAccessory_ductless(this, accessory, hasSensors); } } else { this.log.info('%s: Using platformaAccessory.ts accessory.', accessory.displayName); From 22554210a5b20cf1fd64fa87ced4c57871769378 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 30 Jun 2022 00:47:57 +0000 Subject: [PATCH 3/9] pull if device is using external sensors from the normal device query instead of your own --- src/ductless.ts | 6 ++++-- src/ductless_simple.ts | 6 ++++-- src/platform.ts | 24 ++++++++---------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index 06c3e34..22f3ee7 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -33,10 +33,12 @@ export class KumoPlatformAccessory_ductless { constructor( private readonly platform: KumoHomebridgePlatform, private readonly accessory: PlatformAccessory, - private readonly hasSensors: boolean, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = hasSensors; + this.useExternalSensor = this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + if (this.useExternalSensor) { + this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) + } // determine device profile and additional sensors to tailor accessory to // the capabilities of the kumo device diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 0f11a45..842f5dd 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -30,10 +30,12 @@ export class KumoPlatformAccessory_ductless_simple { constructor( private readonly platform: KumoHomebridgePlatform, private readonly accessory: PlatformAccessory, - private readonly hasSensors: boolean, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = hasSensors; + this.useExternalSensor = this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + if (this.useExternalSensor) { + this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) + } // set accessory information if (accessory.context.zoneTable.unitType !== undefined && accessory.context.zoneTable.unitType !== null) { diff --git a/src/platform.ts b/src/platform.ts index 1f9d52e..896ad12 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -132,12 +132,10 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if(existingAccessory.context.zoneTable.unitType === 'ductless' || existingAccessory.context.zoneTable.unitType === 'mvz') { this.log.info('Initializing "%s" as ductless unit.', existingAccessory.displayName); - this.log.info('seeing if "%s" has a sensor attached', existingAccessory.displayName); - const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, existingAccessory, hasSensors); + new KumoPlatformAccessory_ductless_simple(this, existingAccessory); } else { - new KumoPlatformAccessory_ductless(this, existingAccessory, hasSensors); + new KumoPlatformAccessory_ductless(this, existingAccessory); } } else { this.log.info('Initializing "%s" of unitType "%s" as generic (unspecified) unit.', @@ -150,12 +148,10 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if((existingAccessory.context.device.sp_heat !== undefined || existingAccessory.context.device.spHeat !== undefined) && ( existingAccessory.context.device.sp_cool !== undefined || existingAccessory.context.device.spCool !== undefined)) { this.log.info('%s: Found heat and cool settings will use ductless accessory', existingAccessory.displayName); - this.log.info('seeing if "%s" has a sensor attached', existingAccessory.displayName); - const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, existingAccessory, hasSensors); + new KumoPlatformAccessory_ductless_simple(this, existingAccessory); } else { - new KumoPlatformAccessory_ductless(this, existingAccessory, hasSensors); + new KumoPlatformAccessory_ductless(this, existingAccessory); } } else { this.log.info('%s: Using platformaAccessory.ts accessory.', existingAccessory.displayName); @@ -204,12 +200,10 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if(accessory.context.zoneTable.unitType === 'ductless' || accessory.context.zoneTable.unitType === 'mvz') { this.log.info('Initializing "%s" as ductless unit.', device.label); - this.log.info('seeing if "%s" has a sensor attached', device.label); - const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, accessory, hasSensors); + new KumoPlatformAccessory_ductless_simple(this, accessory); } else { - new KumoPlatformAccessory_ductless(this, accessory, hasSensors); + new KumoPlatformAccessory_ductless(this, accessory); } } else { this.log.info('Initializing "%s" of unitType "%s" as generic (unspecified) unit.', @@ -222,12 +216,10 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin { if((accessory.context.device.sp_heat !== undefined || accessory.context.device.spHeat !== undefined ) && ( accessory.context.device.sp_cool !== undefined || accessory.context.device.spCool !== undefined )) { this.log.info('%s: Found heat and cool settings will use ductless accessory', accessory.displayName); - this.log.info('seeing if "%s" has a sensor attached', device.displayName); - const hasSensors = this.config.directAccess && await this.kumo.queryDeviceSensors_Direct(device.serial); if(this.config.simpleDuctless) { - new KumoPlatformAccessory_ductless_simple(this, accessory, hasSensors); + new KumoPlatformAccessory_ductless_simple(this, accessory); } else { - new KumoPlatformAccessory_ductless(this, accessory, hasSensors); + new KumoPlatformAccessory_ductless(this, accessory); } } else { this.log.info('%s: Using platformaAccessory.ts accessory.', accessory.displayName); From 4a436aeeaf7602fd70ce9a2663e51a0701e8dcdb Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 30 Jun 2022 00:52:51 +0000 Subject: [PATCH 4/9] explicity check for direct access before using external sensor --- src/ductless.ts | 2 +- src/ductless_simple.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index 22f3ee7..ad10808 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -35,7 +35,7 @@ export class KumoPlatformAccessory_ductless { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + this.useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" if (this.useExternalSensor) { this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) } diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 842f5dd..22867b8 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -32,7 +32,7 @@ export class KumoPlatformAccessory_ductless_simple { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + this.useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" if (this.useExternalSensor) { this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) } From daba5ccc014014b0f5b379bfce129bb8ba3319cb Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 30 Jun 2022 00:56:13 +0000 Subject: [PATCH 5/9] minor code cleanup --- src/ductless.ts | 8 ++++---- src/ductless_simple.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index ad10808..b250d46 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -26,7 +26,6 @@ export class KumoPlatformAccessory_ductless { private lastquery; private directAccess; - private useExternalSensor; private historyService: fakegato.FakeGatoHistoryService; @@ -35,8 +34,9 @@ export class KumoPlatformAccessory_ductless { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" - if (this.useExternalSensor) { + + const useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + if (useExternalSensor) { this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) } @@ -85,7 +85,7 @@ export class KumoPlatformAccessory_ductless { this.Fan.setCharacteristic(this.platform.Characteristic.Name, 'Fan'); this.PowerSwitch.setCharacteristic(this.platform.Characteristic.Name, 'Power'); - this.Humdity = this.useExternalSensor && this.directAccess ? this.accessory.getService( + this.Humdity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; if (this.Humdity) { diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 22867b8..f8cdb5f 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -23,7 +23,6 @@ export class KumoPlatformAccessory_ductless_simple { private lastquery; private directAccess; - private useExternalSensor; private historyService: fakegato.FakeGatoHistoryService; @@ -32,8 +31,9 @@ export class KumoPlatformAccessory_ductless_simple { private readonly accessory: PlatformAccessory, ) { this.directAccess = this.platform.config.directAccess; - this.useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" - if (this.useExternalSensor) { + + const useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + if (useExternalSensor) { this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) } @@ -54,7 +54,7 @@ export class KumoPlatformAccessory_ductless_simple { this.HeaterCooler = this.accessory.getService( this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler); - this.Humdity = this.useExternalSensor && this.directAccess ? this.accessory.getService( + this.Humdity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; // set sevice names. From 0abe72fcbc3813bfd3085c26b8fb389a9618ad02 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 30 Jun 2022 01:06:31 +0000 Subject: [PATCH 6/9] log low battery so an enduser can also see it in homebridge logs --- src/ductless.ts | 3 +++ src/ductless_simple.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/ductless.ts b/src/ductless.ts index b250d46..6a44040 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -360,6 +360,9 @@ export class KumoPlatformAccessory_ductless { if (ourSensor.battery) { this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); + if (ourSensor.battery < 10) { + this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) + } } } this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index f8cdb5f..7286962 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -366,6 +366,9 @@ export class KumoPlatformAccessory_ductless_simple { if (ourSensor.battery) { this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); + if (ourSensor.battery < 10) { + this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) + } } } this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); From 72c960150cf99e0af7a2e0605f2f14006a272875 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Thu, 30 Jun 2022 02:20:02 +0000 Subject: [PATCH 7/9] fix bug if sensor data is not present --- src/ductless.ts | 4 ++-- src/ductless_simple.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index 6a44040..e412327 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -335,7 +335,7 @@ export class KumoPlatformAccessory_ductless { this.platform.log.debug('%s (queryDevice_Direct): success.', this.accessory.displayName); if (this.Humdity) { - this.platform.log.info('querying external sensors on %s', this.accessory.context.serial); + this.platform.log.debug('querying external sensors on %s', this.accessory.context.serial); const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); if (sensorData) { this.accessory.context.sensors = sensorData; @@ -353,7 +353,7 @@ export class KumoPlatformAccessory_ductless { return; } let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; - if (this.accessory.context.sensors.length) { + if (this.accessory.context.sensors && this.accessory.context.sensors.length) { const ourSensor = this.accessory.context.sensors[0]; currentValue = ourSensor.humidity; this.platform.log.debug('setting humidity to %s', currentValue); diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 7286962..f38091a 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -232,7 +232,7 @@ export class KumoPlatformAccessory_ductless_simple { this.platform.log.debug('%s (queryDevice_Direct): success.'); if (this.Humdity) { - this.platform.log.info('querying external sensors on %s', this.accessory.context.serial); + this.platform.log.debug('querying external sensors on %s', this.accessory.context.serial); const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); if (sensorData) { this.accessory.context.sensors = sensorData; @@ -359,7 +359,7 @@ export class KumoPlatformAccessory_ductless_simple { return; } let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; - if (this.accessory.context.sensors.length) { + if (this.accessory.context.sensors && this.accessory.context.sensors.length) { const ourSensor = this.accessory.context.sensors[0]; currentValue = ourSensor.humidity; this.platform.log.debug('setting humidity to %s', currentValue); From b8182824940cec68edae0fa3328ed5cbffcd4179 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Fri, 1 Jul 2022 01:39:21 +0000 Subject: [PATCH 8/9] fix typo; fix linter comments --- src/ductless.ts | 35 ++++++++++++++++++++--------------- src/ductless_simple.ts | 40 ++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index e412327..573140a 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -20,7 +20,7 @@ export class KumoPlatformAccessory_ductless { private Fan: Service; private PowerSwitch: Service; private Dehumidifier: Service; - private Humdity: Service | null; + private Humidity: Service | null; private lastupdate; private lastquery; @@ -35,9 +35,14 @@ export class KumoPlatformAccessory_ductless { ) { this.directAccess = this.platform.config.directAccess; - const useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + const useExternalSensor = this.directAccess && + this.accessory.context.device.activeThermistor !== undefined && + this.accessory.context.device.activeThermistor !== 'unset'; + if (useExternalSensor) { - this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) + this.platform.log.info('device %s uses external sensor %s', + this.accessory.context.serial, + this.accessory.context.device.activeThermistor); } // determine device profile and additional sensors to tailor accessory to @@ -85,11 +90,11 @@ export class KumoPlatformAccessory_ductless { this.Fan.setCharacteristic(this.platform.Characteristic.Name, 'Fan'); this.PowerSwitch.setCharacteristic(this.platform.Characteristic.Name, 'Power'); - this.Humdity = useExternalSensor ? this.accessory.getService( + this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; - if (this.Humdity) { - this.Humdity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); + if (this.Humidity) { + this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } // create handlers for characteristics @@ -160,8 +165,8 @@ export class KumoPlatformAccessory_ductless { // .on('get', this.handleDehumidiferActiveGet.bind(this)) // .on('set', this.handleDehumidiferActiveSet.bind(this)); - if (this.Humdity) { - this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) + if (this.Humidity) { + this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) .on('get', this.handleHumidityGet.bind(this)); } @@ -258,11 +263,11 @@ export class KumoPlatformAccessory_ductless { } async handleHumidityGet(callback) { - if (!this.Humdity) { + if (!this.Humidity) { return; } await this.updateAccessoryCharacteristics(); - callback(null, this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); + callback(null, this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); } async updateAccessoryCharacteristics() { @@ -334,7 +339,7 @@ export class KumoPlatformAccessory_ductless { } this.platform.log.debug('%s (queryDevice_Direct): success.', this.accessory.displayName); - if (this.Humdity) { + if (this.Humidity) { this.platform.log.debug('querying external sensors on %s', this.accessory.context.serial); const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); if (sensorData) { @@ -349,23 +354,23 @@ export class KumoPlatformAccessory_ductless { } private updateCurrentRelativeHumidity() { - if (!this.Humdity) { + if (!this.Humidity) { return; } - let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; + let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; if (this.accessory.context.sensors && this.accessory.context.sensors.length) { const ourSensor = this.accessory.context.sensors[0]; currentValue = ourSensor.humidity; this.platform.log.debug('setting humidity to %s', currentValue); if (ourSensor.battery) { - this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); if (ourSensor.battery < 10) { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) } } } - this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); + this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); } private updateHeaterCoolerActive() { diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index f38091a..257a09b 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -7,7 +7,6 @@ import { KumoDevice, KumoDeviceDirect } from './kumo-api'; import { KumoHomebridgePlatform } from './platform'; import { KUMO_LAG, KUMO_DEVICE_WAIT } from './settings'; -import util from 'util'; /* * Platform Accessory - Kumo 'ductless' accessory tested with a @@ -17,7 +16,7 @@ import util from 'util'; */ export class KumoPlatformAccessory_ductless_simple { private HeaterCooler: Service; - private Humdity: Service | null; + private Humidity: Service | null; private lastupdate; private lastquery; @@ -32,9 +31,14 @@ export class KumoPlatformAccessory_ductless_simple { ) { this.directAccess = this.platform.config.directAccess; - const useExternalSensor = this.directAccess && this.accessory.context.device.activeThermistor !== undefined && this.accessory.context.device.activeThermistor !== "unset" + const useExternalSensor = this.directAccess && + this.accessory.context.device.activeThermistor !== undefined && + this.accessory.context.device.activeThermistor !== 'unset'; + if (useExternalSensor) { - this.platform.log.info('device %s uses external sensor %s', this.accessory.context.serial, this.accessory.context.device.activeThermistor) + this.platform.log.info('device %s uses external sensor %s', + this.accessory.context.serial, + this.accessory.context.device.activeThermistor); } // set accessory information @@ -54,14 +58,14 @@ export class KumoPlatformAccessory_ductless_simple { this.HeaterCooler = this.accessory.getService( this.platform.Service.HeaterCooler) || this.accessory.addService(this.platform.Service.HeaterCooler); - this.Humdity = useExternalSensor ? this.accessory.getService( + this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; // set sevice names. this.HeaterCooler.setCharacteristic(this.platform.Characteristic.Name, 'Heater/Cooler'); - if (this.Humdity) { - this.Humdity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); + if (this.Humidity) { + this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } // create handlers for characteristics @@ -93,8 +97,8 @@ export class KumoPlatformAccessory_ductless_simple { this.HeaterCooler.getCharacteristic(this.platform.Characteristic.SwingMode) .on('set', this.handleFanSwingModeSet.bind(this)); - if (this.Humdity) { - this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) + if (this.Humidity) { + this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity) .on('get', this.handleHumidityGet.bind(this)); } @@ -158,11 +162,11 @@ export class KumoPlatformAccessory_ductless_simple { } async handleHumidityGet(callback) { - if (!this.Humdity) { + if (!this.Humidity) { return; } await this.updateAccessoryCharacteristics(); - callback(null, this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); + callback(null, this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value); } async updateAccessoryCharacteristics() { @@ -231,7 +235,7 @@ export class KumoPlatformAccessory_ductless_simple { } this.platform.log.debug('%s (queryDevice_Direct): success.'); - if (this.Humdity) { + if (this.Humidity) { this.platform.log.debug('querying external sensors on %s', this.accessory.context.serial); const sensorData = await this.platform.kumo.queryDeviceSensors_Direct(this.accessory.context.serial); if (sensorData) { @@ -355,23 +359,27 @@ export class KumoPlatformAccessory_ductless_simple { } private updateCurrentRelativeHumidity() { - if (!this.Humdity) { + if (!this.Humidity) { return; } - let currentValue: number = this.Humdity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; + let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; if (this.accessory.context.sensors && this.accessory.context.sensors.length) { const ourSensor = this.accessory.context.sensors[0]; currentValue = ourSensor.humidity; this.platform.log.debug('setting humidity to %s', currentValue); if (ourSensor.battery) { - this.Humdity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); if (ourSensor.battery < 10) { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) + + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + } else { + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } + } } - this.Humdity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); + this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); } private updateFanRotationSpeed() { From 80c28b961ad064fd5dca2cf950d23b99979ec3f8 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Fri, 1 Jul 2022 02:09:34 +0000 Subject: [PATCH 9/9] add support for reading the battery for the external sensor --- src/ductless.ts | 21 +++++++++++++++++++-- src/ductless_simple.ts | 14 +++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index 573140a..798eee7 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -21,6 +21,8 @@ export class KumoPlatformAccessory_ductless { private PowerSwitch: Service; private Dehumidifier: Service; private Humidity: Service | null; + private HumidityBattery: Service | null; + private lastupdate; private lastquery; @@ -93,10 +95,18 @@ export class KumoPlatformAccessory_ductless { this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + this.HumidityBattery = useExternalSensor ? this.accessory.getService( + this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery) : null; + if (this.Humidity) { this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } + if (this.HumidityBattery) { + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor Battery'); + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -354,7 +364,7 @@ export class KumoPlatformAccessory_ductless { } private updateCurrentRelativeHumidity() { - if (!this.Humidity) { + if (!this.Humidity || !this.HumidityBattery) { return; } let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; @@ -364,10 +374,17 @@ export class KumoPlatformAccessory_ductless { this.platform.log.debug('setting humidity to %s', currentValue); if (ourSensor.battery) { - this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); if (ourSensor.battery < 10) { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) + + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + } else { + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } + + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.BatteryLevel, ourSensor.battery); } } this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 257a09b..0c5bd42 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -17,6 +17,7 @@ import { KUMO_LAG, KUMO_DEVICE_WAIT } from './settings'; export class KumoPlatformAccessory_ductless_simple { private HeaterCooler: Service; private Humidity: Service | null; + private HumidityBattery: Service | null; private lastupdate; private lastquery; @@ -61,6 +62,9 @@ export class KumoPlatformAccessory_ductless_simple { this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + this.HumidityBattery = useExternalSensor ? this.accessory.getService( + this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery) : null; + // set sevice names. this.HeaterCooler.setCharacteristic(this.platform.Characteristic.Name, 'Heater/Cooler'); @@ -68,6 +72,11 @@ export class KumoPlatformAccessory_ductless_simple { this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } + if (this.HumidityBattery) { + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor Battery'); + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -359,7 +368,7 @@ export class KumoPlatformAccessory_ductless_simple { } private updateCurrentRelativeHumidity() { - if (!this.Humidity) { + if (!this.Humidity || !this.HumidityBattery) { return; } let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; @@ -373,10 +382,13 @@ export class KumoPlatformAccessory_ductless_simple { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); } else { this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.BatteryLevel, ourSensor.battery); } } this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue);