Skip to content

Instantly share code, notes, and snippets.

@Koenkk
Last active December 23, 2021 16:37
Show Gist options
  • Save Koenkk/fbe399801fe098280d90a65709ef5c5a to your computer and use it in GitHub Desktop.
Save Koenkk/fbe399801fe098280d90a65709ef5c5a to your computer and use it in GitHub Desktop.
TS0504B with white channel support
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const extend = require('zigbee-herdsman-converters/lib/extend');
const libColor = require('zigbee-herdsman-converters/lib/color');
const tzLocal = {
light_color_white: {
key: ['color'],
convertSet: async (entity, key, value, meta) => {
const color = libColor.Color.fromConverterArg(value);
console.log(color);
const enableWhite =
(color.isRGB() && (color.rgb.red === 1 && color.rgb.green === 1 && color.rgb.blue === 1)) ||
// Zigbee2MQTT frontend white value
(color.isXY() && (color.xy.x === 0.3125 || color.xy.y === 0.32894736842105265)) ||
// Home Assistant white color picker value
(color.isXY() && (color.xy.x === 0.323 || color.xy.y === 0.329));
if (enableWhite) {
await entity.command('lightingColorCtrl', 'tuyaRgbMode', {enable: false});
const newState = {color_mode: 'xy'};
if (color.isXY()) {
newState.color = color.xy;
} else {
newState.color = color.rgb.gammaCorrected().toXY().rounded(4);
}
return {state: libColor.syncColorState(newState, meta.state, entity, meta.options, meta.logger)};
} else {
return await tz.light_color.convertSet(entity, key, value, meta);
}
},
},
};
const toZigbee = extend.light_onoff_brightness_color().toZigbee;
toZigbee[toZigbee.indexOf(tz.light_color)] = tzLocal.light_color_white;
const definition = {
fingerprint: [{modelID: 'TS0504B', manufacturerName: '_TZ3000_ukuvyhaa'}],
model: 'TS0504B',
vendor: 'TuYa',
description: 'Zigbee RGBW light (CUSTOM)',
extend: extend.light_onoff_brightness_color(),
toZigbee: toZigbee,
meta: {applyRedFix: true},
};
module.exports = definition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment