Skip to content

Commit

Permalink
Added AutoLights
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilchaddha committed Dec 21, 2018
1 parent 4ca8d0c commit 1c45374
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ https://www.mi.com/us/mi-bedside-lamp/
| pollingInterval | number | Time in ms, for plugin to poll the light to update HomeKit characteristics | 15000|
| scenes | Array (Object) | Scenes | Required|
| rgb | Object (light ID: true/false) | Key-Value pair for light Ids you wish to use rgb pallete instead of hsv. | Optional|
| autoLights | Object (light ID: true/false) | Key-Value pair for light Ids to let Homekit automations set correct values. Homekit trumps Yeelight State | Optional|

### Scenes Config :

Expand Down
3 changes: 3 additions & 0 deletions config-advanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
],
"rgb": {
"0x0000000005429bb96": true
},
"autoLights": {
"0x000000000543dd83": true
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
"dependencies": {
"babel-eslint": "^8.2.6",
"color-convert": "^1.9.3",
"yeelight-platform": "^1.0.8"
"yeelight-platform": "^1.0.9"
}
}
35 changes: 33 additions & 2 deletions src/accessories/lightBulb.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ const LightBulb = class extends Accessory {
}

this.colorPalleteRGB = false
this.isAutoLight = false

if (baseConfig.rgb && baseConfig.rgb[this.name]) {
this.log('Setting Color Model to RGB : ', this.name)
this.colorPalleteRGB = true
this.log('Setting Color Model to RGB : ', baseConfig.rgb[this.name], this.name)
this.colorPalleteRGB = baseConfig.rgb[this.name]
}

if (baseConfig.autoLights && baseConfig.autoLights[this.name]) {
this.log('Setting Auto Light : ', baseConfig.autoLights[this.name], this.name)
this.isAutoLight = baseConfig.autoLights[this.name]
}

this.isOn = false
Expand Down Expand Up @@ -137,6 +143,9 @@ const LightBulb = class extends Accessory {
default:
break
}
if (this.isAutoLight) {
cmd = this.getAutoSceneCmd(cmd)
}

yeeService.sendCommand([this.light.id], cmd)
if (!this.isConnected) {
Expand All @@ -152,6 +161,28 @@ const LightBulb = class extends Accessory {
}
}

getAutoSceneCmd(cmd) {
var sceneCmd = {
id: -1,
}
sceneCmd.method = 'set_scene'
sceneCmd.params = []
if (cmd.method === 'set_ct_abx') {
sceneCmd.params.push('ct')
sceneCmd.params.push(Color.HKTToKCT(this.ct, this.light.model))
} else if (this.colorPalleteRGB) {
sceneCmd.params.push('color')
sceneCmd.params.push(Color.HSVToRGB(this.hue, this.saturation, this.brightness))
} else {
sceneCmd.params.push('hsv')
sceneCmd.params.push(this.hue)
sceneCmd.params.push(this.saturation)
}
sceneCmd.params.push(this.brightness)
this.log('Sending Automated Command to LightBulb' + this.name, sceneCmd)
return sceneCmd
}

deviceStateChanged(props) {
this.logMessage('Device Response', this.light.id, props)
if (props != null && props.id != null && props.id === 199 && props.result != null && props.result.length > 0) {
Expand Down

0 comments on commit 1c45374

Please sign in to comment.