Skip to content

Commit

Permalink
Fixed air purifier modes.
Browse files Browse the repository at this point in the history
Added humidity values.
  • Loading branch information
seikan committed May 20, 2017
1 parent c444f68 commit e35bfec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
# homebridge-mi-air-purifier

This is Xiaomi Mi Air Purifier plugin for [Homebridge](https://github.com/nfarina/homebridge).
This is Xiaomi Mi Air Purifier plugin for [Homebridge](https://github.com/nfarina/homebridge). Since Apple Homekit is not supporting air purifier device yet, this plugin will add the air purifier as **Fan** and **Air Quality Sensor** to your Home app.

![mi-air-purifier](https://cloud.githubusercontent.com/assets/73107/26249685/1d0ae78c-3cda-11e7-8b64-71e8d4323a3e.jpg)

### Features

* Switch on/off.
* Control modes: `idle`, `silent`, `low`, `medium`.
* Get air quality.
* Switch on / off.

* Control modes:

- `Idle / Off`: Lift fan speed to 0% from Home app.

- `Auto`: Lift fan speed between 1 - 60%.

- `Silent`: Lift fan speed between 61 - 80%.

- `Favorite / High`: Lift fan speed great than 80%.

**Notes:** Alternatively, you can ask Siri to change the fan speed within the range to adjust the air purifier mode. Example:

```
Hey Siri, change the air purifier speed to 100.
```


* Display humidity within the **Fan** device.

* Display air quality as a separated device **Air Quality Sensor**.




Expand Down
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ function MiAirPurifier(log, config) {
this.name = config.name || 'Air Purifier';

this.modes = [
[0, 'idle'], [40, 'silent'], [60, 'auto'], [80, 'low'], [100, 'medium']
[0, 'idle'], [60, 'auto'], [80, 'silent'], [100, 'favorite']
];

// Air purifier is not available in Homekit yet, use as fan for now
this.fanService = new Service.Fan(this.name);

// Register another service as air quality sensor
this.airQualitySensorService = new Service.AirQualitySensor(this.name);
this.airQualitySensorService = new Service.AirQualitySensor('Air Quality Sensor');

this.serviceInfo = new Service.AccessoryInformation();

this.serviceInfo
.setCharacteristic(Characteristic.Manufacturer, 'Xiaomi')
.setCharacteristic(Characteristic.Model, 'Air Purifier');

this.fanService
.getCharacteristic(Characteristic.On)
.on('get', this.getOn.bind(this))
Expand All @@ -37,6 +41,10 @@ function MiAirPurifier(log, config) {
.on('get', this.getRotationSpeed.bind(this))
.on('set', this.setRotationSpeed.bind(this));

this.fanService
.addCharacteristic(Characteristic.CurrentRelativeHumidity)
.on('get', this.getCurrentRelativeHumidity.bind(this));

this.airQualitySensorService
.getCharacteristic(Characteristic.AirQuality)
.on('get', this.getAirQuality.bind(this));
Expand Down Expand Up @@ -66,11 +74,6 @@ MiAirPurifier.prototype = {
devices[reg.id] = device;
accessory.device = device;

accessory.serviceInfo
.setCharacteristic(Characteristic.Manufacturer, 'Xiao Mi')
.setCharacteristic(Characteristic.Model, device.model)
.setCharacteristic(Characteristic.SerialNumber, device.id);

log.debug('Discovered "%s" (ID: %s) on %s:%s.', reg.hostname, device.id, device.address, device.port);
});
});
Expand Down Expand Up @@ -104,13 +107,16 @@ MiAirPurifier.prototype = {

this.device.setPower(powerOn)
.then(function(state){
accessory.getRotationSpeed(accessory);
callback(null, state);
});

callback();
},

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

getRotationSpeed: function(callback) {
for(var item of this.modes){
if(this.device.mode == item[1]){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-mi-air-purifier",
"version": "1.0.1",
"version": "1.0.2",
"description": "Xiaomi Mi air purifier plugin for Homebridge.",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit e35bfec

Please sign in to comment.