-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e93253e
Showing
6 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Copyright 2020 Sebastian Lauber | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# homebridge-co2monitor | ||
|
||
Integrates your TFA Dostmann CO2 sensor into Homebridge. | ||
|
||
# Installation | ||
|
||
1. Install homebridge using: `npm install -g homebridge` | ||
2. Install this plugin using: `npm install -g homebridge-co2monitor` | ||
3. Update your configuration file. See `sample-config.json` in this repository for a sample. | ||
|
||
# Configuration | ||
Sample configuration: | ||
|
||
``` | ||
"accessories": [ | ||
{ | ||
"accessory": "Co2Monitor", | ||
"name": "CO2 Livingroom", | ||
"humidity": true, | ||
"co2threshold": 1200 | ||
} | ||
] | ||
``` | ||
|
||
--- | ||
|
||
Credits to | ||
|
||
- [lucacri's homebridge-http-temperature-humidity](https://github.com/lucacri/homebridge-http-temperature-humidity) for the plugin design inspiration | ||
- [huhamhire's node-co2-monitor](https://github.com/huhamhire/node-co2-monitor) for the NodeJS backend to the TFA Dostmann sensor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
var Service, Characteristic; | ||
const CO2Monitor = require('node-co2-monitor'); | ||
const monitor = new CO2Monitor({ "debug": false }); | ||
|
||
module.exports = function (homebridge) { | ||
Service = homebridge.hap.Service; | ||
Characteristic = homebridge.hap.Characteristic; | ||
homebridge.registerAccessory("homebridge-co2monitor", "Co2Monitor", Co2Monitor); | ||
} | ||
|
||
function Co2Monitor(log, config) { | ||
this.log = log; | ||
|
||
// Configuration | ||
this.name = config["name"]; | ||
this.manufacturer = config["manufacturer"] || "TFA Dostmann"; | ||
this.model = config["model"] || "AirCO2NTROL"; | ||
this.serial = config["serial"] || ""; | ||
this.humidity = config["humidity"]; | ||
this.co2threshold = config["co2threshold"] || 800; | ||
this.lastUpdateAt = config["lastUpdateAt"] || null; | ||
} | ||
|
||
monitor.connect((err) => { | ||
if (err) { | ||
return console.error(err.stack); | ||
} | ||
monitor.transfer(); | ||
}); | ||
|
||
Co2Monitor.prototype = { | ||
|
||
getTemperatureState: function (callback) { | ||
callback(null, monitor.temperature); | ||
}, | ||
|
||
getHumidityState: function (callback) { | ||
callback(null, monitor.humidity); | ||
}, | ||
|
||
getCarbonDioxideState: function (callback) { | ||
callback(null, monitor.co2); | ||
}, | ||
|
||
getCarbonDioxideDetected: function (callback) { | ||
callback(null, monitor.co2 ? (monitor.co2 > this.co2threshold) : false); | ||
}, | ||
|
||
getServices: function () { | ||
var services = [], | ||
informationService = new Service.AccessoryInformation(); | ||
|
||
informationService | ||
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer) | ||
.setCharacteristic(Characteristic.Model, this.model) | ||
.setCharacteristic(Characteristic.SerialNumber, this.serial); | ||
services.push(informationService); | ||
|
||
this.temperatureService = new Service.TemperatureSensor(this.name); | ||
this.temperatureService | ||
.getCharacteristic(Characteristic.CurrentTemperature) | ||
.setProps({ minValue: -273, maxValue: 200 }) | ||
.on("get", this.getTemperatureState.bind(this)); | ||
services.push(this.temperatureService); | ||
|
||
this.carbonDioxideService = new Service.CarbonDioxideSensor(this.name); | ||
this.carbonDioxideService | ||
.getCharacteristic(Characteristic.CarbonDioxideDetected) | ||
.on("get", this.getCarbonDioxideDetected.bind(this)); | ||
this.carbonDioxideService | ||
.getCharacteristic(Characteristic.CarbonDioxideLevel) | ||
.on("get", this.getCarbonDioxideState.bind(this)); | ||
services.push(this.carbonDioxideService); | ||
|
||
if (this.humidity !== false) { | ||
this.humidityService = new Service.HumiditySensor(this.name); | ||
this.humidityService | ||
.getCharacteristic(Characteristic.CurrentRelativeHumidity) | ||
.setProps({ minValue: 0, maxValue: 100 }) | ||
.on("get", this.getHumidityState.bind(this)); | ||
services.push(this.humidityService); | ||
} | ||
|
||
return services; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "homebridge-co2monitor", | ||
"version": "0.1.0", | ||
"description": "Homebridge plugin for TFA Dostmann USB CO2 monitors", | ||
"license": "BSD-3-Clause", | ||
"keywords": [ | ||
"homebridge-plugin" | ||
], | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"homebridge": ">=0.2.0" | ||
}, | ||
"author": { | ||
"name": "Sebastian Lauber" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/slauber/homebridge-co2monitor.git" | ||
}, | ||
"dependencies": { | ||
"node-co2-monitor": "^0.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"bridge": { | ||
"name": "Your Homebridge" | ||
}, | ||
"description": "It's my home!", | ||
"platforms": [], | ||
"accessories": [ | ||
{ | ||
"accessory": "Co2Monitor", | ||
"name": "CO2 Livingroom", | ||
"humidity": true, | ||
"co2threshold": 1200 | ||
} | ||
] | ||
} |