diff --git a/README.md b/README.md index 42cc080..d2d86f3 100644 --- a/README.md +++ b/README.md @@ -722,23 +722,32 @@ Air filter - Separate Bits for on/off: - `set_Active_Set`: **(control support)** offset and bit set to 1 when switching on S7 type `Bool` **PLC has to set to 0** e.g. `55.1` for `DB4DBX55.1` - `set_Active_Reset`: offset and bit set to 1 when switching off S7 type `Bool` **PLC has to set to 0** e.g. `55.2` for `DB4DBX55.2` - +- Filter change + - `get_FilterChangeIndication`: **(push support)** offset and bit to filter change indication S7 type `Bool` e.g. `55.3` for `DB4DBX55.3` + - `0`: filter ok + - `true`: change filter + - `get_FilterLifeLevel`: **(optional)** **(push support)** offset and bit to filter live level S7 type `bate` e.g. `56` for `DB4DBX56` + - `0`: change filter + - `100`: filter is new + - `set_ResetFilterIndication`: **(optional)** **(control support)** offset and bit to filter change indication S7 type `Bool` **PLC has to set to 0** after detecting change to true via homebridge e.g. `55.4` for `DB4DBX55.4` NOTE: Currently not used by HomeApp ### Light Sensor as `PLC_FilterMaintenance` -Filter change indication +Filter change indication (Currently neither supported in HomeApp and HomeBridge) + ![homebridge pic](doc/filtermaintenance.png) - `name`: unique name of the accessory - `manufacturer`: **(optional)** description - `db`: s7 data base number e.g. `4` for `DB4` - `enablePolling`: **(optional)** when set to `true` the current state will be polled. It is mandatory as well to enable polling mode on platform level. - `pollInterval`: **(optional)** poll interval in seconds. Default value see platform definition. -- `get_FilterChangeIndication`: **(push support)** offset and bit to filter change indication S7 type `Bool` e.g. `55.3` for `DB4DBX55.3` - - `0`: filter ok - - `true`: change filter -- `get_FilterLifeLevel`: **(optional)** **(push support)** offset and bit to filter live level S7 type `bate` e.g. `56` for `DB4DBX56` - - `0`: change filter - - `100`: filter is new -- `set_ResetFilterIndication`: **(optional)** **(control support)** offset and bit to filter change indication S7 type `Bool` **PLC has to set to 0** after detecting change to true via homebridge e.g. `55.4` for `DB4DBX55.4` +- Filter change + - `get_FilterChangeIndication`: **(push support)** offset and bit to filter change indication S7 type `Bool` e.g. `55.3` for `DB4DBX55.3` + - `0`: filter ok + - `true`: change filter + - `get_FilterLifeLevel`: **(optional)** **(push support)** offset and bit to filter live level S7 type `bate` e.g. `56` for `DB4DBX56` + - `0`: change filter + - `100`: filter is new + - `set_ResetFilterIndication`: **(optional)** **(control support)** offset and bit to filter change indication S7 type `Bool` **PLC has to set to 0** after detecting change to true via homebridge e.g. `55.4` for `DB4DBX55.4` NOTE: Currently not used by HomeApp ## config.json Example diff --git a/config.schema.json b/config.schema.json index 74f3d35..1f6f9bd 100644 --- a/config.schema.json +++ b/config.schema.json @@ -1598,7 +1598,7 @@ "accessories[].set_ResetFilterIndication" ], "condition": { - "functionBody": "return ['PLC_FilterMaintenance'].includes(model.accessories[arrayIndices[0]].accessory);" + "functionBody": "return ['PLC_FilterMaintenance','PLC_AirPurifier'].includes(model.accessories[arrayIndices[0]].accessory);" } }, { @@ -1611,7 +1611,7 @@ "accessories[].get_FilterLifeLevel" ], "condition": { - "functionBody": "return ['PLC_FilterMaintenance'].includes(model.accessories[arrayIndices[0]].accessory);" + "functionBody": "return ['PLC_FilterMaintenance','PLC_AirPurifier'].includes(model.accessories[arrayIndices[0]].accessory);" } } ] diff --git a/doc/airpurifier.png b/doc/airpurifier.png new file mode 100644 index 0000000..6150545 Binary files /dev/null and b/doc/airpurifier.png differ diff --git a/doc/filtermaintenance.png b/doc/filtermaintenance.png new file mode 100644 index 0000000..a61f84e Binary files /dev/null and b/doc/filtermaintenance.png differ diff --git a/index.js b/index.js index 5c20df1..2b5400f 100644 --- a/index.js +++ b/index.js @@ -1496,6 +1496,7 @@ function GenericPLCAccessory(platform, config, accessoryNumber) { } this.initActive(true); + this.initFilterMaintainance(); if ('get_RotationSpeed' in config) { this.service.getCharacteristic(Characteristic.RotationSpeed) @@ -1546,33 +1547,8 @@ function GenericPLCAccessory(platform, config, accessoryNumber) { this.service = new Service.FilterMaintenance(this.name); this.accessory.addService(this.service); - if ('get_FilterChangeIndication' in this.config) { - this.service.getCharacteristic(Characteristic.FilterChangeIndication) - .on('get', function(callback) {this.getBit(callback, - this.config.db, - Math.floor(this.config.get_FilterChangeIndication), Math.floor((this.config.get_FilterChangeIndication*10)%10), - 'get FilterChangeIndication' - );}.bind(this)); - } - - if ('get_FilterLifeLevel' in config) { - this.service.getCharacteristic(Characteristic.FilterLifeLevel) - .on('get', function(callback) {this.getByte(callback, - config.db, - config.get_FilterLifeLevel, - "get FilterLifeLevel", - this.modFunctionGet - );}.bind(this)); - } - - if ('set_ResetFilterIndication' in this.config) { - this.service.getCharacteristic(Characteristic.ResetFilterIndication) - .on('set', function(powerOn, callback) { this.setBit(powerOn, callback, - this.config.db, - Math.floor(this.config.set_ResetFilterIndication), Math.floor((this.config.set_ResetFilterIndication*10)%10), - 'set ResetFilterIndication' - );}.bind(this)); - } + this.initFilterMaintainance(); + } // INIT handling /////////////////////////////////////////////// @@ -1705,6 +1681,36 @@ GenericPLCAccessory.prototype = { } }, + initFilterMaintainance: function() { + if ('get_FilterChangeIndication' in this.config) { + this.service.getCharacteristic(Characteristic.FilterChangeIndication) + .on('get', function(callback) {this.getBit(callback, + this.config.db, + Math.floor(this.config.get_FilterChangeIndication), Math.floor((this.config.get_FilterChangeIndication*10)%10), + 'get FilterChangeIndication' + );}.bind(this)); + } + + if ('get_FilterLifeLevel' in config) { + this.service.getCharacteristic(Characteristic.FilterLifeLevel) + .on('get', function(callback) {this.getByte(callback, + config.db, + config.get_FilterLifeLevel, + "get FilterLifeLevel", + this.modFunctionGet + );}.bind(this)); + } + + if ('set_ResetFilterIndication' in this.config) { + this.service.getCharacteristic(Characteristic.ResetFilterIndication) + .on('set', function(powerOn, callback) { this.setBit(powerOn, callback, + this.config.db, + Math.floor(this.config.set_ResetFilterIndication), Math.floor((this.config.set_ResetFilterIndication*10)%10), + 'set ResetFilterIndication' + );}.bind(this)); + } + }, + poll: function() { if (this.config.enablePolling || this.config.adaptivePolling) { if ((this.pollActive || this.adaptivePollActive ) && --this.pollCounter <= 0) @@ -2259,6 +2265,18 @@ GenericPLCAccessory.prototype = { this.service.getCharacteristic(Characteristic.SwingMode).updateValue(value); rv = true; } + if ('get_FilterChangeIndication' in this.config && this.config.get_FilterChangeIndication == offset) + { + this.log.debug( "[" + this.name + "] Push FilterChangeIndication:" + value); + this.service.getCharacteristic(Characteristic.FilterChangeIndication).updateValue(value); + rv = true; + } + if ('get_FilterLifeLevel' in this.config && this.config.get_FilterLifeLevel == offset) + { + this.log.debug( "[" + this.name + "] Push FilterLifeLevel:" + value); + this.service.getCharacteristic(Characteristic.FilterLifeLevel).updateValue(value); + rv = true; + } } // PUSH handling /////////////////////////////////////////////// // FilterMaintenance @@ -2548,6 +2566,12 @@ GenericPLCAccessory.prototype = { this.service.getCharacteristic(Characteristic.SwingMode).setValue(value); rv = true; } + if ('set_ResetFilterIndication' in this.config && this.config.set_ResetFilterIndication == offset) + { + this.log.debug( "[" + this.name + "] Control ResetFilterIndication:" + value); + this.service.getCharacteristic(Characteristic.ResetFilterIndication).setValue(value); + rv = true; + } } // CONTROL handling //////////////////////////////////////////// @@ -3041,6 +3065,16 @@ GenericPLCAccessory.prototype = { this.service.getCharacteristic(Characteristic.SwingMode).updateValue(value); } }.bind(this)); + this.service.getCharacteristic(Characteristic.FilterChangeIndication).getValue(function(err, value) { + if (!err) { + this.service.getCharacteristic(Characteristic.FilterChangeIndication).updateValue(value); + } + }.bind(this)); + this.service.getCharacteristic(Characteristic.FilterLifeLevel).getValue(function(err, value) { + if (!err) { + this.service.getCharacteristic(Characteristic.FilterLifeLevel).updateValue(value); + } + }.bind(this)); } // POLL handling /////////////////////////////////////////////// // FilterMaintenance diff --git a/package.json b/package.json index a21cf7d..a84c94d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-plc", - "version": "1.1.0-beta.6", + "version": "1.1.0-beta.7", "description": "Homebridge plugin for Siemens Step7 and compatible PLCs. (https://github.com/homebridge)", "license": "MIT", "keywords": [