Skip to content

Instantly share code, notes, and snippets.

@itsmepetrov
Created December 12, 2018 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmepetrov/79ae4aef70cce328d2c93ea1334af07f to your computer and use it in GitHub Desktop.
Save itsmepetrov/79ae4aef70cce328d2c93ea1334af07f to your computer and use it in GitHub Desktop.
const HomeKitDevice = require('../HomeKitDevice')
class AqaraTunableWhiteBulb extends HomeKitDevice {
static get description() {
return {
model: 'lumi.light.aqcn02',
manufacturer: 'LUMI',
name: 'Aqara Bulb',
}
}
getAvailbleServices() {
return [{
name: 'Bulb',
type: 'Lightbulb',
}]
}
onDeviceReady() {
const lightingColorCtrlAttrs = this.zigbee.endpoint(1).clusters.lightingColorCtrl.attrs
this.brightnessTimeout = null
const onCharacteristic = this.getServiceCharacteristic('Bulb', 'On')
const colorTemperature = this.getServiceCharacteristic('Bulb', 'ColorTemperature')
const brightnessCharacteristic = this.getServiceCharacteristic('Bulb', 'Brightness')
colorTemperature.setProps({
minValue: lightingColorCtrlAttrs.colorTempPhysicalMin,
maxValue: lightingColorCtrlAttrs.colorTempPhysicalMax,
})
onCharacteristic.on('set', (value) => {
this.clearTimeout(this.brightnessTimeout)
if (value) {
this.brightnessTimeout = this.setTimeout(() => {
brightnessCharacteristic.setValue(brightnessCharacteristic.value)
}, 500)
}
})
this.mountServiceCharacteristic({
endpoint: 1,
cluster: 'genOnOff',
service: 'Bulb',
characteristic: 'On',
reportMinInt: 1,
reportMaxInt: 300,
reportChange: 1,
parser: 'onOff',
})
this.mountServiceCharacteristic({
endpoint: 1,
cluster: 'genLevelCtrl',
service: 'Bulb',
characteristic: 'Brightness',
reportMinInt: 1,
reportMaxInt: 300,
reportChange: 1,
parser: 'dim',
})
this.mountServiceCharacteristic({
endpoint: 1,
cluster: 'lightingColorCtrl',
service: 'Bulb',
characteristic: 'ColorTemperature',
reportMinInt: 1,
reportMaxInt: 300,
reportChange: 1,
parser: 'colorTemperature',
reportParser: value => Math.round(value),
getParser: value => Math.round(value),
setParser: value => ({
colortemp: Math.round(value),
transtime: 5,
}),
})
}
}
module.exports = AqaraTunableWhiteBulb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment