Skip to content

Commit e93253e

Browse files
committed
Initial commit
0 parents  commit e93253e

File tree

6 files changed

+213
-0
lines changed

6 files changed

+213
-0
lines changed

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# nyc test coverage
19+
.nyc_output
20+
21+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# node-waf configuration
25+
.lock-wscript
26+
27+
# Compiled binary addons (http://nodejs.org/api/addons.html)
28+
build/Release
29+
30+
# Dependency directories
31+
node_modules
32+
jspm_packages
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional eslint cache
38+
.eslintcache
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
43+
# Output of 'npm pack'
44+
*.tgz
45+
46+
# Yarn Integrity file
47+
.yarn-integrity
48+

LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright 2020 Sebastian Lauber
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
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.
8+
9+
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.
10+
11+
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.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# homebridge-co2monitor
2+
3+
Integrates your TFA Dostmann CO2 sensor into Homebridge.
4+
5+
# Installation
6+
7+
1. Install homebridge using: `npm install -g homebridge`
8+
2. Install this plugin using: `npm install -g homebridge-co2monitor`
9+
3. Update your configuration file. See `sample-config.json` in this repository for a sample.
10+
11+
# Configuration
12+
Sample configuration:
13+
14+
```
15+
"accessories": [
16+
{
17+
"accessory": "Co2Monitor",
18+
"name": "CO2 Livingroom",
19+
"humidity": true,
20+
"co2threshold": 1200
21+
}
22+
]
23+
```
24+
25+
---
26+
27+
Credits to
28+
29+
- [lucacri's homebridge-http-temperature-humidity](https://github.com/lucacri/homebridge-http-temperature-humidity) for the plugin design inspiration
30+
- [huhamhire's node-co2-monitor](https://github.com/huhamhire/node-co2-monitor) for the NodeJS backend to the TFA Dostmann sensor.

index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var Service, Characteristic;
2+
const CO2Monitor = require('node-co2-monitor');
3+
const monitor = new CO2Monitor({ "debug": false });
4+
5+
module.exports = function (homebridge) {
6+
Service = homebridge.hap.Service;
7+
Characteristic = homebridge.hap.Characteristic;
8+
homebridge.registerAccessory("homebridge-co2monitor", "Co2Monitor", Co2Monitor);
9+
}
10+
11+
function Co2Monitor(log, config) {
12+
this.log = log;
13+
14+
// Configuration
15+
this.name = config["name"];
16+
this.manufacturer = config["manufacturer"] || "TFA Dostmann";
17+
this.model = config["model"] || "AirCO2NTROL";
18+
this.serial = config["serial"] || "";
19+
this.humidity = config["humidity"];
20+
this.co2threshold = config["co2threshold"] || 800;
21+
this.lastUpdateAt = config["lastUpdateAt"] || null;
22+
}
23+
24+
monitor.connect((err) => {
25+
if (err) {
26+
return console.error(err.stack);
27+
}
28+
monitor.transfer();
29+
});
30+
31+
Co2Monitor.prototype = {
32+
33+
getTemperatureState: function (callback) {
34+
callback(null, monitor.temperature);
35+
},
36+
37+
getHumidityState: function (callback) {
38+
callback(null, monitor.humidity);
39+
},
40+
41+
getCarbonDioxideState: function (callback) {
42+
callback(null, monitor.co2);
43+
},
44+
45+
getCarbonDioxideDetected: function (callback) {
46+
callback(null, monitor.co2 ? (monitor.co2 > this.co2threshold) : false);
47+
},
48+
49+
getServices: function () {
50+
var services = [],
51+
informationService = new Service.AccessoryInformation();
52+
53+
informationService
54+
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
55+
.setCharacteristic(Characteristic.Model, this.model)
56+
.setCharacteristic(Characteristic.SerialNumber, this.serial);
57+
services.push(informationService);
58+
59+
this.temperatureService = new Service.TemperatureSensor(this.name);
60+
this.temperatureService
61+
.getCharacteristic(Characteristic.CurrentTemperature)
62+
.setProps({ minValue: -273, maxValue: 200 })
63+
.on("get", this.getTemperatureState.bind(this));
64+
services.push(this.temperatureService);
65+
66+
this.carbonDioxideService = new Service.CarbonDioxideSensor(this.name);
67+
this.carbonDioxideService
68+
.getCharacteristic(Characteristic.CarbonDioxideDetected)
69+
.on("get", this.getCarbonDioxideDetected.bind(this));
70+
this.carbonDioxideService
71+
.getCharacteristic(Characteristic.CarbonDioxideLevel)
72+
.on("get", this.getCarbonDioxideState.bind(this));
73+
services.push(this.carbonDioxideService);
74+
75+
if (this.humidity !== false) {
76+
this.humidityService = new Service.HumiditySensor(this.name);
77+
this.humidityService
78+
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
79+
.setProps({ minValue: 0, maxValue: 100 })
80+
.on("get", this.getHumidityState.bind(this));
81+
services.push(this.humidityService);
82+
}
83+
84+
return services;
85+
}
86+
};

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "homebridge-co2monitor",
3+
"version": "0.1.0",
4+
"description": "Homebridge plugin for TFA Dostmann USB CO2 monitors",
5+
"license": "BSD-3-Clause",
6+
"keywords": [
7+
"homebridge-plugin"
8+
],
9+
"engines": {
10+
"node": ">=10.0.0",
11+
"homebridge": ">=0.2.0"
12+
},
13+
"author": {
14+
"name": "Sebastian Lauber"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git://github.com/slauber/homebridge-co2monitor.git"
19+
},
20+
"dependencies": {
21+
"node-co2-monitor": "^0.3.0"
22+
}
23+
}

sample-config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"bridge": {
3+
"name": "Your Homebridge"
4+
},
5+
"description": "It's my home!",
6+
"platforms": [],
7+
"accessories": [
8+
{
9+
"accessory": "Co2Monitor",
10+
"name": "CO2 Livingroom",
11+
"humidity": true,
12+
"co2threshold": 1200
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)