Skip to content

Commit

Permalink
Omni occupancy detection improvements
Browse files Browse the repository at this point in the history
Minimum sound level set to 47dBA based on dust sensor fan noise as guard for spurious low reading. Provide option to restart detection algorithm on Homebridge restart.
  • Loading branch information
DMBlakeley committed Nov 20, 2020
1 parent 046d16c commit 95b408e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).

## v5.5.5
* Omni occupancy detection improvments. Minimum sound level set to 47dBA based on dust sensor fan noise as guard for spurious low reading. Provide option to restart detection algorithm on Homebridge restart.

## v5.5.4
* Omni occupancy detection improvments. Now based on minimum detected sound level + user defined offset.
* Correct existing device recovery from cache on Homebridge restart.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ See [config-sample.json](https://github.com/DMBlakeley/homebridge-awair2/blob/ma
"vocMw": 72.66578273019740,
"occupancyDetection": false,
"occupancyOffset": 2,
"occupancyRestart": false,
"logging": false,
"verbose": false,
"development": false,
Expand All @@ -80,6 +81,7 @@ Parameter | Description
`vocMw` | (OPTIONAL, default = `72.66578273019740`) The Molecular Weight (g/mol) of a reference gas or mixture that you use to convert from ppb to ug/m^3
`occupancyDetection` | (OPTIONAL - Omni only, default = `false`) Enables Omni occupancy detection based on minimum environmental sound level detected.
`occupancyOffset` | (OPTIONAL - Omni only, default = `2`) Used when `occupancy detection` enabled. Offset value in dBA above background sound level to set `not occupied` level, `occupied` is 0.5dBA higher.
`occupancyRestart` | (OPTIONAL - Omni only, default = `false`, use historical data) `true` enables restart of occupancy detection algorithm on Homebridge reboot.
`logging` | Whether to output logs to the Homebridge logs (OPTIONAL, default = `false`)
`verbose` | Whether to log results from API data calls (OPTIONAL, default = `false`). Requires `logging` to be `true`.
`development` | Enables Development mode to allow use of `test` Awair devices lacking `end user`/Awair OUI formatted Serial numbers.
Expand All @@ -88,7 +90,8 @@ Parameter | Description

# Resources

- Awair API: https://docs.developer.getawair.com/
- Awair Cloud API: https://docs.developer.getawair.com/
- Awair Local API: https://docs.google.com/document/d/1001C-ro_ig7aEyz0GiWUiiJn0M6DLj47BYWj31acesg/edit
- Homebridge: https://github.com/nfarina/homebridge
- Homebridge API: https://developers.homebridge.io/#/
- Homebridge examples: https://github.com/homebridge/homebridge-examples
Expand All @@ -97,6 +100,6 @@ Parameter | Description
- Using async-await and npm-promise with TypeScript: https://github.com/patdaburu/request-promise-typescript-example
- Another Awair plugin: https://github.com/henrypoydar/homebridge-awair-glow
- Reference AQ plugin: https://github.com/toto/homebridge-airrohr
- Refenerce temperature plugin: https://github.com/metbosch/homebridge-http-temperature
- Reference temperature plugin: https://github.com/metbosch/homebridge-http-temperature
- AQI Calculation NPM package: https://www.npmjs.com/package/aqi-bot
- Homebridge-philips-air plugin: https://github.com/Sunoo/homebridge-philips-air
1 change: 1 addition & 0 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"vocMw": 72.66578273019740,
"occupancyDetection": false,
"occupancyOffset": 2,
"occupancyRestart": false,
"logging": false,
"verbose": false,
"development": false,
Expand Down
9 changes: 8 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"description": "The Molecular Weight (g/mol) of a reference gas or mixture that you use to convert from ppb to ug/m^3."
},
"occupancyDetection": {
"title": "Omni - Whether to enable auto Occupancy detection based on minimum sound level.",
"title": "Omni - Whether to enable Occupancy detection based on minimum sound level.",
"type": "boolean",
"default": false,
"description": "Omni only - enables occupancy detection based on minimum sound level + occupancyOffset value."
Expand All @@ -70,6 +70,12 @@
"placeholder": 2,
"description": "Omni only - Used when `occupancy detection` enabled. Offset value in dBA above background sound level to set `not occupied` level, `occupied` is 0.5dBA higher."
},
"occupancyRestart": {
"title": "Omni - restart Occupancy detection measurement on next Homebridge reboot.",
"type": "boolean",
"default": false,
"description": "Omni only - reinitialize Occupancy detection measurement on Homebridge reboot."
},
"logging": {
"title": "Whether to output logs to the Homebridge logs.",
"type": "boolean",
Expand Down Expand Up @@ -121,6 +127,7 @@
"vocMw",
"occupancyDetection",
"occupancyOffset",
"occupancyRestart",
"logging",
"verbose",
"development"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge Awair2",
"name": "homebridge-awair2",
"version": "5.5.4",
"version": "5.5.5",
"description": "HomeKit integration of Awair air purifier as Dynamic Platform.",
"main": "dist/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type AwairPlatformConfig = {
vocMw: number;
occupancyDetection: boolean;
occupancyOffset: number;
occupancyRestart: false;
occupancyDetectedLevel: number;
occupancyNotDetectedLevel: number;
logging: boolean;
Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,16 @@ class AwairPlatform implements DynamicPlatformPlugin {
} else { // acessory exists, use data from cache
if (this.config.logging) {
this.log(accessory.context.name + ' exists, using data from cache');
}
}
if (accessory.context.deviceType === 'awair-omni') {
this.omniPresent = true; // set flag for Occupancy detected loop
}
// use Omni cache data unless 'occupancyRestart' enabled
if ((accessory.context.deviceType === 'awair-omni') && this.config.occupancyRestart) {
accessory.context.occDetectedLevel = this.occDetectedLevel;
accessory.context.occDetectedNotLevel = this.occDetectedNotLevel;
accessory.context.minSoundLevel = this.occDetectedNotLevel;
}
}
return;
}
Expand Down Expand Up @@ -796,8 +802,8 @@ class AwairPlatform implements DynamicPlatformPlugin {
this.log('[' + accessory.context.serial + '] spl_a: ' + omniSpl_a);
}

if(omniSpl_a < accessory.context.minSoundLevel) { // use context to track occupancy status for each Omni device
accessory.context.minSoundLevel = omniSpl_a;
if(omniSpl_a > 47.0 && omniSpl_a < accessory.context.minSoundLevel) { // 50dBA (±3) baseline set by dust sensor fan noise
accessory.context.minSoundLevel = omniSpl_a; // use 'context' to track occupancy status for each Omni device
accessory.context.occDetectedLevel = accessory.context.minSoundLevel + this.occupancyOffset + 0.5; // dBA
accessory.context.occDetectedNotLevel = accessory.context.minSoundLevel + this.occupancyOffset; // dBA
if(this.config.logging) {
Expand Down

0 comments on commit 95b408e

Please sign in to comment.