Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slauber committed Oct 15, 2020
0 parents commit e93253e
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .gitignore
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

11 changes: 11 additions & 0 deletions LICENSE
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.
30 changes: 30 additions & 0 deletions README.md
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.
86 changes: 86 additions & 0 deletions index.js
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;
}
};
23 changes: 23 additions & 0 deletions package.json
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"
}
}
15 changes: 15 additions & 0 deletions sample-config.json
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
}
]
}

0 comments on commit e93253e

Please sign in to comment.