Skip to content

Commit

Permalink
add filtermaintenance to airpurifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Feilner committed Sep 25, 2022
1 parent dd72c5b commit ee1ff17
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

### <a name='PLC_FilterMaintenance'></a>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
Expand Down
4 changes: 2 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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);"
}
},
{
Expand All @@ -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);"
}
}
]
Expand Down
Binary file added doc/airpurifier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/filtermaintenance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 61 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ function GenericPLCAccessory(platform, config, accessoryNumber) {
}

this.initActive(true);
this.initFilterMaintainance();

if ('get_RotationSpeed' in config) {
this.service.getCharacteristic(Characteristic.RotationSpeed)
Expand Down Expand Up @@ -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 ///////////////////////////////////////////////
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit ee1ff17

Please sign in to comment.