Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacri committed Dec 17, 2016
2 parents b2a9b08 + 5afcf69 commit c5368e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ The /weather endpoint will return a json looking like this
```


This plugin acts as an interface between a web endpoint and homebridge only. You will still need some dedicated hardware to expose the web endpoints with the temperature and humidity information. In my case, I used a simple NodeMCU board and a DHT11 (or DHT22).
This plugin acts as an interface between a web endpoint and homebridge only. You will still need some dedicated hardware to expose the web endpoints with the temperature and humidity information. In my case, I used a simple NodeMCU board and a DHT11 (or DHT22). [Check my other repo for the NodeMCU code](https://github.com/lucacri/nodemcu-temperature-humidity-station).
35 changes: 23 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var request = require('sync-request');

var temperatureService;
var humidityService;
var url
var url
var humidity = 0;
var temperature = 0;

Expand All @@ -25,6 +25,7 @@ function HttpTemphum(log, config) {
this.manufacturer = config["manufacturer"] || "Luca Manufacturer";
this.model = config["model"] || "Luca Model";
this.serial = config["serial"] || "Luca Serial";
this.humidity = config["humidity"];
}

HttpTemphum.prototype = {
Expand All @@ -41,7 +42,7 @@ HttpTemphum.prototype = {
})
},

getStateHumidity: function(callback){
getStateHumidity: function(callback){
callback(null, this.humidity);
},

Expand All @@ -57,13 +58,15 @@ HttpTemphum.prototype = {
var info = JSON.parse(res.body);

temperatureService.setCharacteristic(Characteristic.CurrentTemperature, info.temperature);
humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity);
if(this.humidity !== false)
humidityService.setCharacteristic(Characteristic.CurrentRelativeHumidity, info.humidity);

this.log(res.body);
this.log(info);

this.temperature = info.temperature;
this.humidity = info.humidity;
if(this.humidity !== false)
this.humidity = info.humidity;

callback(null, this.temperature);
}
Expand All @@ -75,22 +78,30 @@ HttpTemphum.prototype = {
},

getServices: function () {
var informationService = new Service.AccessoryInformation();
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);

temperatureService = new Service.TemperatureSensor(this.name);
temperatureService
.getCharacteristic(Characteristic.CurrentTemperature)
.on('get', this.getState.bind(this));

humidityService = new Service.HumiditySensor(this.name);
humidityService
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.on('get', this.getStateHumidity.bind(this));

return [informationService, temperatureService, humidityService];
services.push(temperatureService);

if(this.humidity !== false){
humidityService = new Service.HumiditySensor(this.name);
humidityService
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.setProps({minValue: -100, maxValue: 100})
.on('get', this.getStateHumidity.bind(this));
services.push(humidityService);
}

return services;
}
};
3 changes: 2 additions & 1 deletion sample-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"accessory": "HttpTemphum",
"name": "Living Room Weather",
"url": "http://192.168.1.210/weather",
"http_method": "GET"
"http_method": "GET",
"humidity": true
}
]
}

0 comments on commit c5368e9

Please sign in to comment.