Skip to content

Instantly share code, notes, and snippets.

@Koenkk
Last active December 17, 2022 08:30
Show Gist options
  • Save Koenkk/864f435469f043ceb77383e0e0262613 to your computer and use it in GitHub Desktop.
Save Koenkk/864f435469f043ceb77383e0e0262613 to your computer and use it in GitHub Desktop.
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const ota = require('zigbee-herdsman-converters/lib/ota');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const utils = require('zigbee-herdsman-converters/lib/utils');
const globalStore = require('zigbee-herdsman-converters/lib/store');
const e = exposes.presets;
const ea = exposes.access;
const fzLocal = {
TS110E: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.hasOwnProperty('64515')) {
result['min_brightness'] = utils.mapNumberRange(msg.data['64515'], 0, 1000, 1, 255);
}
if (msg.data.hasOwnProperty('64516')) {
result['max_brightness'] = utils.mapNumberRange(msg.data['64516'], 0, 1000, 1, 255);
}
if (msg.data.hasOwnProperty('61440')) {
result['brightness'] = utils.mapNumberRange(msg.data['61440'], 0, 1000, 0, 254);
}
return result;
},
},
TS110E_light_type: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.hasOwnProperty('64514')) {
const lookup = {0: 'led', 1: 'incandescent', 2: 'halogen'};
result['light_type'] = lookup[msg.data['64514']];
}
return result;
},
},
TS110E_switch_type: {
cluster: 'genLevelCtrl',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result = {};
if (msg.data.hasOwnProperty('64514')) {
const lookup = {0: 'momentary', 1: 'toggle', 2: 'state'};
const propertyName = utils.postfixWithEndpointName('switch_type', msg, model, meta);
result[propertyName] = lookup[msg.data['64514']];
}
return result;
},
},
};
const tzLocal = {
TS110E_options: {
key: ['min_brightness', 'max_brightness', 'light_type', 'switch_type'],
convertSet: async (entity, key, value, meta) => {
let payload = null;
if (key === 'min_brightness' || key == 'max_brightness') {
const id = key === 'min_brightness' ? 64515 : 64516;
payload = {[id]: {value: utils.mapNumberRange(value, 1, 255, 0, 1000), type: 0x21}};
} else if (key === 'light_type' || key === 'switch_type') {
const lookup = key === 'light_type' ? {led: 0, incandescent: 1, halogen: 2} : {momentary: 0, toggle: 1, state: 2};
payload = {64514: {value: lookup[value], type: 0x20}};
}
await entity.write('genLevelCtrl', payload, utils.getOptions(meta.mapped, entity));
return {state: {[key]: value}};
},
convertGet: async (entity, key, meta) => {
let id = null;
if (key === 'min_brightness') id = 64515;
if (key === 'max_brightness') id = 64516;
if (key === 'light_type' || key === 'switch_type') id = 64514;
await entity.read('genLevelCtrl', [id]);
},
},
};
const definition = {
fingerprint: [{modelID: 'TS110E', manufacturerName: '_TZ3210_zxbtub8r'}],
model: 'TS110E_1gang_1',
vendor: 'TuYa',
description: '1 channel dimmer',
fromZigbee: extend.light_onoff_brightness({disablePowerOnBehavior: true, disableMoveStep: true, disableTransition: true})
.fromZigbee.concat([tuya.fz.power_on_behavior, fzLocal.TS110E_switch_type, fzLocal.TS110E]),
toZigbee: extend.light_onoff_brightness({disablePowerOnBehavior: true, disableMoveStep: true, disableTransition: true})
.toZigbee.concat([tuya.tz.power_on_behavior, tzLocal.TS110E_options]),
meta: {multiEndpoint: true},
exposes: [
e.light_brightness().withMinBrightness().withMaxBrightness(),
e.power_on_behavior(),
tuya.exposes.switchType(),
],
configure: async (device, coordinatorEndpoint, logger) => {
await tuya.configureMagicPacket(device, coordinatorEndpoint, logger);
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
await reporting.bind(device.getEndpoint(1), coordinatorEndpoint, ['genOnOff', 'genLevelCtrl']);
},
};
module.exports = definition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment