Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added night mode with 1% #26

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.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

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# 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

# dotenv environment variables file
.env

# next.js build output
.next

108 changes: 60 additions & 48 deletions Devices/MiPhilipsCeilingLamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ const miio = require('miio');
var Accessory, PlatformAccessory, Service, Characteristic, UUIDGen;
MiPhilipsCeilingLamp = function(platform, config) {
this.init(platform, config);

Accessory = platform.Accessory;
PlatformAccessory = platform.PlatformAccessory;
Service = platform.Service;
Characteristic = platform.Characteristic;
UUIDGen = platform.UUIDGen;

this.device = new miio.Device({
address: this.config['ip'],
token: this.config['token']
});

this.accessories = {};
if(this.config['lightName'] && this.config['lightName'] != "") {
this.accessories['LightAccessory'] = new MiPhilipsCeilingLampLight(this);
}
var accessoriesArr = this.obj2array(this.accessories);

this.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]Initializing " + this.config["type"] + " device: " + this.config["ip"] + ", accessories size: " + accessoriesArr.length);


return accessoriesArr;
}
inherits(MiPhilipsCeilingLamp, Base);
Expand Down Expand Up @@ -58,16 +58,16 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() {
.setCharacteristic(Characteristic.Model, "Philips Ceiling Lamp")
.setCharacteristic(Characteristic.SerialNumber, tokensan);
services.push(infoService);

var CeilingLampService = this.Lampservice = new Service.Lightbulb(this.name, "MiPhilipsCeilingLamp");
var CeilingLampOnCharacteristic = CeilingLampService.getCharacteristic(Characteristic.On);
CeilingLampService
.addCharacteristic(Characteristic.ColorTemperature)
.setProps({
minValue: 50,
maxValue: 400,
minStep: 1
});
// CeilingLampService
// .addCharacteristic(Characteristic.ColorTemperature)
// .setProps({
// minValue: 50,
// maxValue: 400,
// minStep: 1
// });
CeilingLampOnCharacteristic
.on('get', function(callback) {
this.device.call("get_prop", ["power"]).then(result => {
Expand Down Expand Up @@ -103,7 +103,19 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() {
});
}.bind(this))
.on('set', function(value, callback) {
if(value > 0) {
if(value == 1) {
this.device.call("set_bricct", [0,0]).then(result => {
that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - activating night mode: " + result);
if(result[0] === "ok") {
callback(null);
} else {
callback(new Error(result[0]));
}
}).catch(function(err) {
that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - activating night mode Error: " + err);
callback(err);
});
} else if(value > 0) {
this.device.call("set_bright", [value]).then(result => {
that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setBrightness Result: " + result);
if(result[0] === "ok") {
Expand All @@ -112,44 +124,44 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() {
callback(new Error(result[0]));
}
}).catch(function(err) {
that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setBrightness Error: " + err);
callback(err);
that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setBrightness Error: " + err);
callback(err);
});
} else {
callback(null);
}
}.bind(this));
CeilingLampService
.getCharacteristic(Characteristic.ColorTemperature)
.on('get', function(callback) {
this.device.call("get_prop", ["cct"]).then(result => {
that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - getColorTemperature: " + result);
callback(null, result[0] * 350);
}).catch(function(err) {
that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - getColorTemperature Error: " + err);
callback(err);
});
}.bind(this))
.on('set', function(value,callback) {
value = value - 50;
value = value / 350 * 100;
value = Math.round(100 - value);
if(value == 0) {
value = 1;
}
that.platform.log.debug("[MiPhilipsLightPlatform]MiPhilipsCeilingLamp - setColorTemperature : " + value + "%");
this.device.call("set_cct", [value]).then(result => {
that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setColorTemperature Result: " + result);
if(result[0] === "ok") {
callback(null);
} else {
callback(new Error(result[0]));
}
}).catch(function(err) {
that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setColorTemperature Error: " + err);
callback(err);
});
}.bind(this));
// CeilingLampService
// .getCharacteristic(Characteristic.ColorTemperature)
// .on('get', function(callback) {
// this.device.call("get_prop", ["cct"]).then(result => {
// that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - getColorTemperature: " + result);
// callback(null, result[0] * 350);
// }).catch(function(err) {
// that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - getColorTemperature Error: " + err);
// callback(err);
// });
// }.bind(this))
// .on('set', function(value,callback) {
// value = value - 50;
// value = value / 350 * 100;
// value = Math.round(100 - value);
// if(value == 0) {
// value = 1;
// }
// that.platform.log.debug("[MiPhilipsLightPlatform]MiPhilipsCeilingLamp - setColorTemperature : " + value + "%");
// this.device.call("set_cct", [value]).then(result => {
// that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setColorTemperature Result: " + result);
// if(result[0] === "ok") {
// callback(null);
// } else {
// callback(new Error(result[0]));
// }
// }).catch(function(err) {
// that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setColorTemperature Error: " + err);
// callback(err);
// });
// }.bind(this));
services.push(CeilingLampService);
return services;
}
Expand Down
88 changes: 5 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,10 @@
# homebridge-mi-philips-light
[![npm version](https://badge.fury.io/js/homebridge-mi-philips-light.svg)](https://badge.fury.io/js/homebridge-mi-philips-light)

XiaoMi Philips light plugins for HomeBridge.

Thanks for [nfarina](https://github.com/nfarina)(the author of [homebridge](https://github.com/nfarina/homebridge)), [OpenMiHome](https://github.com/OpenMiHome/mihome-binary-protocol), [aholstenson](https://github.com/aholstenson)(the author of [miio](https://github.com/aholstenson/miio)), [Zzm317](https://github.com/Zzm317), all other developer and testers.

**Note: I have only a part of these devices, so some devices don't have tested. If you find bugs, please submit them to [issues](https://github.com/YinHangCode/homebridge-mi-philips-light/issues) or [QQ Group: 107927710](//shang.qq.com/wpa/qunwpa?idkey=8b9566598f40dd68412065ada24184ef72c6bddaa11525ca26c4e1536a8f2a3d).**

![](https://raw.githubusercontent.com/YinHangCode/homebridge-mi-philips-light/master/images/SmartBulb.jpg)
![](https://raw.githubusercontent.com/YinHangCode/homebridge-mi-philips-light/master/images/TableLamp2.jpg)
![](https://raw.githubusercontent.com/YinHangCode/homebridge-mi-philips-light/master/images/CeilingLamp.jpg)

## Supported Devices
1.MiPhilipsSmartBulb(米家飞利浦智睿球泡灯)
2.MiPhilipsTableLamp2(米家飞利浦智睿台灯二代)
3.MiPhilipsCeilingLamp(米家飞利浦智睿吸顶灯)

## Installation
1. Install HomeBridge, please follow it's [README](https://github.com/nfarina/homebridge/blob/master/README.md).
If you are using Raspberry Pi, please read [Running-HomeBridge-on-a-Raspberry-Pi](https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi).
2. Make sure you can see HomeBridge in your iOS devices, if not, please go back to step 1.
3. Install packages.
```
npm install -g homebridge-mi-philips-light
```
## Configuration
```
"platforms": [{
"platform": "MiPhilipsLightPlatform",
"deviceCfgs": [{
"type": "MiPhilipsSmartBulb",
"ip": "192.168.88.xx",
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"lightName": "living room bulb",
"lightDisable": false
}, {
"type": "MiPhilipsTableLamp2",
"ip": "192.168.88.xx",
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"mainLightName": "living room table lamp",
"secondLightName": "living room table lamp amb",
"secondLightDisable": false,
"eyecareSwitchName": "living room table lamp eyecare model",
"eyecareSwitchDisable": false
}, {
"type": "MiPhilipsCeilingLamp",
"ip": "192.168.88.xx",
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"lightName": "living room ceiling lamp",
"lightDisable": false,
"updatetimer": false,
"interval": 3
}]
}]
```
## Get token
### Get token by miio2.db
setup MiJia(MiHome) app in your android device or android virtual machine.
open MiJia(MiHome) app and login your account.
refresh device list and make sure device display in the device list.
get miio2.db(path: /data/data/com.xiaomi.smarthome/databases/miio2.db) file from your android device or android virtual machine.
open website [[Get MiIo Tokens By DataBase File](http://miio2.yinhh.com/)], upload miio2.db file and submit.
### Get token by network
Open command prompt or terminal. Run following command:
```
miio --discover
```
Wait until you get output similar to this:
```
Device ID: xxxxxxxx
Model info: Unknown
Address: 192.168.88.xx
Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx via auto-token
Support: Unknown
```
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" is token.
If token is "???", then reset device and connect device created Wi-Fi hotspot.
Run following command:
```
miio --discover --sync
```
Wait until you get output.
For more information about token, please refer to [OpenMiHome](https://github.com/OpenMiHome/mihome-binary-protocol) and [miio](https://github.com/aholstenson/miio).
This is a fork of https://github.com/YinHangCode/homebridge-mi-philips-light with added night mode for Philips Ceiling lamps.
## Version Logs
### 0.2.9 (2018-5-06 @RandomMetalhead Fork)
1.Updated dependencies
### 0.2.4 (2018-5-06 @RandomMetalhead Fork)
1.added night mode for Philips Ceiling lamp, when set to 1%.
### 0.2.3 (2018-02-10)
1.update 'package.json'.
### 0.2.2 (2017-11-18)
Expand Down
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
{
"name": "homebridge-mi-philips-light",
"version": "0.2.3",
"description": "XiaoMi Philips light plugins for HomeBridge(https://github.com/nfarina/homebridge).",
"name": "homebridge-mi-philips-light-fork",
"version": "0.2.9",
"description": "XiaoMi Philips light RandomMetalhead Fork",
"keywords": [
"homebridge-plugin",
"xiaomi",
"mi",
"philips",
"light",
"bulb",
"lamp",
"ceiling"
"philips"
],
"author": "YinHang",
"homepage": "https://github.com/YinHangCode/homebridge-mi-philips-light",
"author": "RandomMetalhead",
"homepage": "https://github.com/RandomMetalhead/homebridge-mi-philips-light",
"repository": {
"type": "git",
"url": "https://github.com/YinHangCode/homebridge-mi-philips-light"
"url": "git+https://github.com/RandomMetalhead/homebridge-mi-philips-light.git"
},
"bugs": {
"url": "https://github.com/YinHangCode/homebridge-mi-philips-light/issues"
"url": "https://github.com/RandomMetalhead/homebridge-mi-philips-light/issues"
},
"engines": {
"node": ">=7.0.0",
"homebridge": ">=0.4.1"
"homebridge": ">=0.4.30",
"node": ">=7.6.0"
},
"dependencies": {
"miio": "0.14.1"
"miio": "0.14.1",
"npm": "^6.0.0"
},
"main": "index.js",
"devDependencies": {
"homebridge": ">=0.4.30"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
}