diff --git a/README.md b/README.md index 147a4c8..73aa51b 100644 --- a/README.md +++ b/README.md @@ -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 : diff --git a/config-advanced.json b/config-advanced.json index 3236fe4..df726d3 100644 --- a/config-advanced.json +++ b/config-advanced.json @@ -27,6 +27,9 @@ ], "rgb": { "0x0000000005429bb96": true + }, + "autoLights": { + "0x000000000543dd83": true } } ] diff --git a/package-lock.json b/package-lock.json index 6ef1187..bd34907 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1747,9 +1747,9 @@ } }, "yeelight-platform": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/yeelight-platform/-/yeelight-platform-1.0.8.tgz", - "integrity": "sha512-Ud7F97ytqP043oUbuNJl0H/mlRWm2AOdGrzTnqhVKlBJFx7i0oGU/GQ3FD6MQj//DxZ12hn4CsgkGjN0gYaenw==", + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/yeelight-platform/-/yeelight-platform-1.0.9.tgz", + "integrity": "sha512-+Q6b5iPW95Sg9dLwDi/xkH+ZNKpg+kZm8/VvOTNleaYcgRFKGx62p4bNr4rL363QOJTRd0qE49sd0Pe+QuS04g==", "requires": { "babel-eslint": "^8.2.6" } diff --git a/package.json b/package.json index a1d0673..82fc1e6 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/accessories/lightBulb.js b/src/accessories/lightBulb.js index e4ea651..58bf033 100644 --- a/src/accessories/lightBulb.js +++ b/src/accessories/lightBulb.js @@ -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 @@ -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) { @@ -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) {