From 56bbf6715417f07482fd1fb40e51d530b09fd1ae Mon Sep 17 00:00:00 2001 From: Simone Karin Lehmann Date: Mon, 13 May 2024 09:49:01 +0200 Subject: [PATCH 1/4] no need for targetTemperaturDivisor, use _getDividedState() instead --- config.schema.json | 7 ------- lib/SimpleHeaterAccessory.js | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/config.schema.json b/config.schema.json index 2e122b11..d0462bff 100644 --- a/config.schema.json +++ b/config.schema.json @@ -454,13 +454,6 @@ "functionBody": "return model.devices && model.devices[arrayIndices] && ['SimpleHeater'].includes(model.devices[arrayIndices].type);" } }, - "targetTemperatureDivisor": { - "type": "integer", - "placeholder": "1", - "condition": { - "functionBody": "return model.devices && model.devices[arrayIndices] && ['SimpleHeater'].includes(model.devices[arrayIndices].type);" - } - }, "dpAction": { "type": "integer", "placeholder": "1", diff --git a/lib/SimpleHeaterAccessory.js b/lib/SimpleHeaterAccessory.js index a6862d75..f8ff5534 100644 --- a/lib/SimpleHeaterAccessory.js +++ b/lib/SimpleHeaterAccessory.js @@ -27,7 +27,6 @@ class SimpleHeaterAccessory extends BaseAccessory { this.dpCurrentTemperature = this._getCustomDP(this.device.context.dpCurrentTemperature) || '3'; this.temperatureDivisor = parseInt(this.device.context.temperatureDivisor) || 1; this.thresholdTemperatureDivisor = parseInt(this.device.context.thresholdTemperatureDivisor) || 1; - this.targetTemperatureDivisor = parseInt(this.device.context.targetTemperatureDivisor) || 1; const characteristicActive = service.getCharacteristic(Characteristic.Active) .updateValue(this._getActive(dps[this.dpActive])) @@ -75,7 +74,7 @@ class SimpleHeaterAccessory extends BaseAccessory { if (changes.hasOwnProperty(this.dpDesiredTemperature)) { if (characteristicHeatingThresholdTemperature.value !== changes[this.dpDesiredTemperature]) - characteristicHeatingThresholdTemperature.updateValue(changes[this.dpDesiredTemperature * this.targetTemperatureDivisor]); + characteristicHeatingThresholdTemperature.updateValue(this._getDividedState(changes[this.dpDesiredTemperature], this.thresholdTemperatureDivisor)); } if (changes.hasOwnProperty(this.dpCurrentTemperature) && characteristicCurrentTemperature.value !== changes[this.dpCurrentTemperature]) characteristicCurrentTemperature.updateValue(this._getDividedState(changes[this.dpCurrentTemperature], this.temperatureDivisor)); From 681783e7ca59c634734ac16c413d13456d97c8a5 Mon Sep 17 00:00:00 2001 From: Simone Karin Lehmann Date: Mon, 13 May 2024 09:59:10 +0200 Subject: [PATCH 2/4] show IDLE state in currentHeaterCoolterState to properly show up in HomeKit. state only changes above or below desiredTemperature, as all divices I know do so --- lib/SimpleHeaterAccessory.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/SimpleHeaterAccessory.js b/lib/SimpleHeaterAccessory.js index f8ff5534..0f589937 100644 --- a/lib/SimpleHeaterAccessory.js +++ b/lib/SimpleHeaterAccessory.js @@ -7,6 +7,7 @@ class SimpleHeaterAccessory extends BaseAccessory { constructor(...props) { super(...props); + this.currentHeaterCoolerState = 0; } _registerPlatformAccessory() { @@ -33,7 +34,7 @@ class SimpleHeaterAccessory extends BaseAccessory { .on('get', this.getActive.bind(this)) .on('set', this.setActive.bind(this)); - service.getCharacteristic(Characteristic.CurrentHeaterCoolerState) + const characteristicCurrentHeaterCoolerState = service.getCharacteristic(Characteristic.CurrentHeaterCoolerState) .updateValue(this._getCurrentHeaterCoolerState(dps)) .on('get', this.getCurrentHeaterCoolerState.bind(this)); @@ -79,6 +80,7 @@ class SimpleHeaterAccessory extends BaseAccessory { if (changes.hasOwnProperty(this.dpCurrentTemperature) && characteristicCurrentTemperature.value !== changes[this.dpCurrentTemperature]) characteristicCurrentTemperature.updateValue(this._getDividedState(changes[this.dpCurrentTemperature], this.temperatureDivisor)); + characteristicCurrentHeaterCoolerState.updateValue(this._getCurrentHeaterCoolerState(state)); this.log.info('SimpleHeater changed: ' + JSON.stringify(state)); }); } @@ -112,16 +114,22 @@ class SimpleHeaterAccessory extends BaseAccessory { } getCurrentHeaterCoolerState(callback) { - this.getState([this.dpActive], (err, dps) => { - if (err) return callback(err); - - callback(null, this._getCurrentHeaterCoolerState(dps)); - }); + callback(null, this.currentHeaterCoolerState); } _getCurrentHeaterCoolerState(dps) { const {Characteristic} = this.hap; - return dps[this.dpActive] ? Characteristic.CurrentHeaterCoolerState.HEATING : Characteristic.CurrentHeaterCoolerState.INACTIVE; + if (dps[this.dpActive]) { + if (dps[this.dpCurrentTemperature] < dps[this.dpDesiredTemperature]) { + this.currentHeaterCoolerState = Characteristic.CurrentHeaterCoolerState.HEATING; + } + if (dps[this.dpCurrentTemperature] > dps[this.dpDesiredTemperature]) { + this.currentHeaterCoolerState = Characteristic.CurrentHeaterCoolerState.IDLE; + } + } else { + this.currentHeaterCoolerState = Characteristic.CurrentHeaterCoolerState.INACTIVE; + }; + return this.currentHeaterCoolerState; } getTargetHeaterCoolerState(callback) { From 8fd74da876bdfbe3d701672060f143848ceb3d1d Mon Sep 17 00:00:00 2001 From: Simone Karin Lehmann Date: Mon, 13 May 2024 10:09:02 +0200 Subject: [PATCH 3/4] add temperatureOffset for temperature measurement --- config.schema.json | 7 +++++++ lib/SimpleHeaterAccessory.js | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.schema.json b/config.schema.json index d0462bff..02543b6f 100644 --- a/config.schema.json +++ b/config.schema.json @@ -454,6 +454,13 @@ "functionBody": "return model.devices && model.devices[arrayIndices] && ['SimpleHeater'].includes(model.devices[arrayIndices].type);" } }, + "temperatureOffset": { + "type": "integer", + "placeholder": "0", + "condition": { + "functionBody": "return model.devices && model.devices[arrayIndices] && ['SimpleHeater'].includes(model.devices[arrayIndices].type);" + } + }, "dpAction": { "type": "integer", "placeholder": "1", diff --git a/lib/SimpleHeaterAccessory.js b/lib/SimpleHeaterAccessory.js index 0f589937..29b8ec35 100644 --- a/lib/SimpleHeaterAccessory.js +++ b/lib/SimpleHeaterAccessory.js @@ -28,6 +28,7 @@ class SimpleHeaterAccessory extends BaseAccessory { this.dpCurrentTemperature = this._getCustomDP(this.device.context.dpCurrentTemperature) || '3'; this.temperatureDivisor = parseInt(this.device.context.temperatureDivisor) || 1; this.thresholdTemperatureDivisor = parseInt(this.device.context.thresholdTemperatureDivisor) || 1; + this.temperatureOffset = parseInt(this.device.context.temperatureOffset) || 0; const characteristicActive = service.getCharacteristic(Characteristic.Active) .updateValue(this._getActive(dps[this.dpActive])) @@ -146,7 +147,7 @@ class SimpleHeaterAccessory extends BaseAccessory { } setTargetThresholdTemperature(value, callback) { - this.setState(this.dpDesiredTemperature, value * this.thresholdTemperatureDivisor, err => { + this.setState(this.dpDesiredTemperature, (value - this.temperatureOffset) * this.thresholdTemperatureDivisor, err => { if (err) return callback(err); if (this.characteristicHeatingThresholdTemperature) { @@ -156,6 +157,10 @@ class SimpleHeaterAccessory extends BaseAccessory { callback(); }); } + + _getDividedState(dp, divisor) { + return ((parseFloat(dp) + this.temperatureOffset) / divisor) || 0; + } } module.exports = SimpleHeaterAccessory; From 6b872e64698ef86f126036728ee23880d825a166 Mon Sep 17 00:00:00 2001 From: Simone Karin Lehmann Date: Mon, 13 May 2024 11:39:42 +0200 Subject: [PATCH 4/4] fix temperatureOffset calculation --- lib/SimpleHeaterAccessory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/SimpleHeaterAccessory.js b/lib/SimpleHeaterAccessory.js index 29b8ec35..74c2cad7 100644 --- a/lib/SimpleHeaterAccessory.js +++ b/lib/SimpleHeaterAccessory.js @@ -159,7 +159,7 @@ class SimpleHeaterAccessory extends BaseAccessory { } _getDividedState(dp, divisor) { - return ((parseFloat(dp) + this.temperatureOffset) / divisor) || 0; + return ((parseFloat(dp) / divisor) + this.temperatureOffset) || 0; } }