Skip to content

Commit

Permalink
Add PLC_CarbonDioxideSensor and PLC_CarbonMonoxideSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Feilner committed Mar 16, 2024
1 parent 86bb3bf commit 24ea215
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 10 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Changelog

## [2.0.1] 2023-09-12
⚠️⚠️⚠️**Action required breaking changes!** ⚠️⚠️⚠️
- Version 2.0.x has changed the name of some configurations.
- Please stay on version 1.0.x if you do not want to adapt your configuration.

## [2.0.2] 2024-03-16

### Added
- `PLC_CarbonDioxideSensor`
- `PLC_CarbonMonoxideSensor`


## [2.0.1] 2023-09-12

### Notable changes
- Configuration via GUI

Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ SIEMENS S7 PLC plugin for [Homebridge](https://homebridge.io)
* [Light Sensor as `PLC_LightSensor`](#PLC_LightSensor)
* [Air Purifier as `PLC_AirPurifier`](#PLC_AirPurifier)
* [Filter Maintenance as `PLC_FilterMaintenance`](#PLC_FilterMaintenance)
* [CarbonDioxideSensor as `PLC_CarbonDioxideSensor`](#PLC_CarbonDioxideSensor)
* [CarbonMonoxideSensor as `PLC_CarbonMonoxideSensor`](#PLC_CarbonMonoxideSensor)

# Installation

Expand Down Expand Up @@ -731,7 +733,7 @@ Air 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`
### <a name='PLC_FilterMaintenance'></a>Filter mainanance indicator as `PLC_FilterMaintenance`
Filter change indication (Currently neither supported in HomeApp and HomeBridge)

![homebridge pic](doc/filtermaintenance.png)
Expand All @@ -742,13 +744,26 @@ Filter change indication (Currently neither supported in HomeApp and HomeBridge)
- `pollInterval`: **(optional)** poll interval in seconds. Default value see platform definition.
- 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
- `false`: 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_CarbonDioxideSensor'></a>C02 Sensor as `PLC_CarbonDioxideSensor`
Carbon Dioxide Sensor
- Warning
- `get_CarbonDioxideDetected`: **(push support)** offset and bit for CO2 detection S7 type `Bool` e.g. `55.3` for `DB4DBX55.3`
- `false`: normal CO2 level
- `true`: abnormal CO2 level

### <a name='PLC_CarbonMonoxideSensor'></a>C0 Sensor as `PLC_CarbonMonoxideSensor`
Carbon Monoxid Sensor
- Warning
- `get_CarbonMonoxideDetected`: **(push support)** offset and bit for CO detection S7 type `Bool` e.g. `55.3` for `DB4DBX55.3`
- `false`: normal CO level
- `true`: abnormal CO level

## config.json Example
Note: The example is just an example it contains also some optional settings. For testing purposes all accessories are set to one DB.
Expand Down
52 changes: 46 additions & 6 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@
{
"title": "PLC_FilterMaintenance",
"enum": ["PLC_FilterMaintenance"]
},
{
"title": "PLC_CarbonDioxideSensor",
"enum": ["PLC_CarbonDioxideSensor"]
},
{
"title": "PLC_CarbonMonoxideSensor",
"enum": ["PLC_CarbonMonoxideSensor"]
}
]
},
Expand Down Expand Up @@ -872,7 +880,6 @@
"functionBody": "return (!model.accessories[arrayIndices[0]].get_RotationSpeed && !model.accessories[arrayIndices[0]].set_RotationSpeed);"
}
},

"get_RotationSpeed": {
"title": "get_RotationSpeed <b>(optional)</b> <b>(push support)</b>",
"type": "number",
Expand All @@ -889,9 +896,6 @@
"functionBody": "return (!model.accessories[arrayIndices[0]].get_RotationSpeedByte && !model.accessories[arrayIndices[0]].set_RotationSpeedByte);"
}
},



"get_RotationDirection": {
"title": "get_RotationDirection <b>(optional)</b> <b>(push support)</b>",
"type": "number",
Expand Down Expand Up @@ -971,7 +975,7 @@
"minimum": 0
},
"description": "define mapping array for `set_TargetAirPurifierState`. The home app value is used as index into the table. e.g. `[1, 0]` which maps the PLC value `0->1 1->0` when the PLC supports only two states with `0:automatic` and `1:manual`"
},
},
"get_FilterChangeIndication": {
"title": "get_FilterChangeIndication <b>(push support)</b>",
"type": "number",
Expand All @@ -980,7 +984,7 @@
"get_FilterLifeLevel": {
"title": "get_FilterLifeLevel <b>(optional)</b> <b>(push support)</b>",
"type": "number",
"description": "offset and bit to filter live level S7 type `bate` e.g. `56` for `DB4DBX56<br> - `0`: change filter<br> - `100`: filter is new"
"description": "offset and bit to filter live level S7 type `bate` e.g. `56` for `DB4DBX56<br> - `false`: change filter<br> - `100`: filter is new"
},
"set_ResetFilterIndication": {
"title": "set_ResetFilterIndication <b>(optional but required when `get_TargetAirPurifierState` is defined)</b> <b>(control support)</b>",
Expand All @@ -996,6 +1000,16 @@
"title": "get_StatusTampered <b>(optional)</b> <b>(push support)</b>",
"type": "number",
"description": "offset and bit to tamper detection. (Home app shows this only within the options) S7 type `Bool` e.g. `55.2` for `DB4DBX55.2`<br> - `false`: ok<br> - `true`: tampered"
},
"get_CarbonDioxideDetected": {
"title": "get_CarbonDioxideDetected <b>(push support)</b>",
"type": "number",
"description": "offset and bit for CO2 detection S7 type `Bool` e.g. `55.3` for `DB4DBX55.3 <br> - `false`: normal CO2 level<br> - `true`: abnormal CO2 level"
},
"get_CarbonMonoxideDetected": {
"title": "get_CarbonMonoxideDetected <b>(push support)</b>",
"type": "number",
"description": "offset and bit for CO detection S7 type `Bool` e.g. `55.3` for `DB4DBX55.3 <br> - `false`: normal CO2 level<br> - `true`: abnormal CO2 level"
}
}
}
Expand Down Expand Up @@ -1661,6 +1675,32 @@
"condition": {
"functionBody": "return ['PLC_FilterMaintenance','PLC_AirPurifier'].includes(model.accessories[arrayIndices[0]].accessory);"
}
},
{
"key": "accessories[]",
"type": "section",
"title": "CarbonDioxide",
"expandable": true,
"expanded": false,
"items": [
"accessories[].get_CarbonDioxideDetected"
],
"condition": {
"functionBody": "return ['PLC_CarbonDioxideSensor'].includes(model.accessories[arrayIndices[0]].accessory);"
}
},
{
"key": "accessories[]",
"type": "section",
"title": "CarbonMonoxide",
"expandable": true,
"expanded": false,
"items": [
"accessories[].get_CarbonMonoxideDetected"
],
"condition": {
"functionBody": "return ['PLC_CarbonMonoxideSensor'].includes(model.accessories[arrayIndices[0]].accessory);"
}
}
]
}
Expand Down
78 changes: 77 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,38 @@ function GenericPLCAccessory(platform, config, accessoryNumber) {
}

// INIT handling ///////////////////////////////////////////////
// CarbonDioxideSensor
////////////////////////////////////////////////////////////////
else if (config.accessory == 'PLC_CarbonDioxideSensor'){
this.service = new Service.CarbonDioxideSensor(this.name);
this.accessory.addService(this.service);

this.service.getCharacteristic(Characteristic.CarbonDioxideDetected)
.on('get', function(callback) {this.getBit(callback,
config.db,
Math.floor(config.get_CarbonDioxideDetected), Math.floor((config.get_CarbonDioxideDetected*10)%10),
"get CarbonDioxideDetected",
this.modFunctionGet
);}.bind(this));
}

// INIT handling ///////////////////////////////////////////////
// CarbonMonoxideSensor
////////////////////////////////////////////////////////////////
else if (config.accessory == 'PLC_CarbonMonoxideSensor'){
this.service = new Service.CarbonMonoxideSensor(this.name);
this.accessory.addService(this.service);

this.service.getCharacteristic(Characteristic.CarbonMonoxideDetected)
.on('get', function(callback) {this.getBit(callback,
config.db,
Math.floor(config.get_CarbonMonoxideDetected), Math.floor((config.get_CarbonMonoxideDetected*10)%10),
"get CarbonMonoxideDetected",
this.modFunctionGet
);}.bind(this));
}

// INIT handling ///////////////////////////////////////////
// Undefined
////////////////////////////////////////////////////////////////
else {
Expand Down Expand Up @@ -2309,6 +2341,28 @@ GenericPLCAccessory.prototype = {
rv = true;
}
}
// PUSH handling ///////////////////////////////////////////////
// CarbonDioxideSensor
////////////////////////////////////////////////////////////////
else if (this.config.accessory == 'PLC_CarbonDioxideSensor'){
if ('get_CarbonDioxideDetected' in this.config && this.config.get_CarbonDioxideDetected == offset)
{
this.log.debug( "[" + this.name + "] Push CarbonDioxideDetected:" + value);
this.service.getCharacteristic(Characteristic.CarbonDioxideDetected).updateValue(value);
rv = true;
}
}
// PUSH handling ///////////////////////////////////////////////
// CarbonMonoxideSensor
////////////////////////////////////////////////////////////////
else if (this.config.accessory == 'PLC_CarbonMonoxideSensor'){
if ('get_CarbonMonoxideDetected' in this.config && this.config.get_CarbonMonoxideDetected == offset)
{
this.log.debug( "[" + this.name + "] Push CarbonMonoxideDetected:" + value);
this.service.getCharacteristic(Characteristic.CarbonMonoxideDetected).updateValue(value);
rv = true;
}
}
return rv;
},

Expand Down Expand Up @@ -3106,7 +3160,29 @@ GenericPLCAccessory.prototype = {
}
}.bind(this));
}
},
// POLL handling ///////////////////////////////////////////////
// CarbonDioxideSensor
////////////////////////////////////////////////////////////////
else if (this.config.accessory == 'PLC_CarbonDioxideSensor') {
// get the current target system state and update the value.
this.service.getCharacteristic(Characteristic.CarbonDioxideDetected).getValue(function(err, value) {
if (!err) {
this.service.getCharacteristic(Characteristic.CarbonDioxideDetected).updateValue(value);
}
}.bind(this));
}
// POLL handling ///////////////////////////////////////////////
// CarbonDioxideSensor
////////////////////////////////////////////////////////////////
else if (this.config.accessory == 'PLC_CarbonMonoxideSensor') {
// get the current target system state and update the value.
this.service.getCharacteristic(Characteristic.CarbonMonoxideDetected).getValue(function(err, value) {
if (!err) {
this.service.getCharacteristic(Characteristic.CarbonMonoxideDetected).updateValue(value);
}
}.bind(this));
}
},

getServices: function() {
return [this.accessory.getService(Service.AccessoryInformation), this.service];
Expand Down

0 comments on commit 24ea215

Please sign in to comment.