Skip to content

Instantly share code, notes, and snippets.

@Koenkk

Koenkk/ext.js Secret

Created June 10, 2024 19:19
Show Gist options
  • Save Koenkk/a7a69ac8ef4294e2122217443449d9af to your computer and use it in GitHub Desktop.
Save Koenkk/a7a69ac8ef4294e2122217443449d9af 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 tuya = require('zigbee-herdsman-converters/lib/tuya');
const e = exposes.presets;
const ea = exposes.access;
const legacy = require('zigbee-herdsman-converters/lib/legacy');
const utils = require('zigbee-herdsman-converters/lib/utils');
const { Buffer } = require('node:buffer');
const definition = {
fingerprint: tuya.fingerprint('TS0601', ['_TZE204_dzuqwsyg']),
model: 'TYBAC-006',
vendor: 'Tuya',
description: 'Wall-mount thermostat for 2-pipe fan-coil unit',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
onEvent: tuya.onEventSetLocalTime,
configure: tuya.configureMagicPacket,
exposes: [
e.binary('state', ea.STATE_SET, 'ON', 'OFF').withDescription('Turn the thermostat ON/OFF'),
e.child_lock(),
e.climate()
.withLocalTemperature(ea.STATE)
.withSetpoint('current_heating_setpoint', 5, 35, 1, ea.STATE_SET)
.withSystemMode(['cool', 'heat', 'fan_only'], ea.STATE_SET)
.withFanMode(['low', 'medium', 'high', 'auto'], ea.STATE_SET)
.withLocalTemperatureCalibration(-5, 5, 0.5, ea.STATE_SET),
e.min_temperature().withValueMin(5).withValueMax(15),
e.max_temperature().withValueMin(15).withValueMax(45),
e.binary('eco_mode', ea.STATE_SET, 'ON', 'OFF').withDescription('ECO mode ON/OFF'),
e.max_temperature_limit().withDescription('ECO Heating energy-saving temperature (default: 20 ºC)').withValueMin(15).withValueMax(30),
e.min_temperature_limit().withDescription('ECO Cooling energy-saving temperature (default: 26 ºC)').withValueMin(15).withValueMax(30),
e.deadzone_temperature().withValueMin(0).withValueMax(5).withValueStep(1),
e.binary('valve', ea.STATE, 'OPEN', 'CLOSE').withDescription('3-Way Valve State'),
e.binary('manual_mode', ea.STATE_SET, 'ON', 'OFF').withDescription('Manual = ON or Schedule = OFF'),
...tuya.exposes.scheduleAllDays(ea.STATE_SET, 'HH:MM/C HH:MM/C HH:MM/C HH:MM/C HH:MM/C HH:MM/C'),
],
meta: {
tuyaDatapoints:
[
[1, 'state', tuya.valueConverter.onOff],
[null, 'system_mode', {
// Extend system_mode to support 'off' in addition to 'cool', 'heat' and 'fan_only'
to: async (v, meta) => {
const entity = meta.device.endpoints[0];
// Power State
await tuya.sendDataPointBool(entity, 1, v !== 'off', 'dataRequest', 1);
switch (v) {
case 'cool':
await tuya.sendDataPointEnum(entity, 2, 0, 'dataRequest', 1);
break;
case 'heat':
await tuya.sendDataPointEnum(entity, 2, 1, 'dataRequest', 1);
break;
case 'fan_only':
await tuya.sendDataPointEnum(entity, 2, 2, 'dataRequest', 1);
break;
}
},
}],
[2, null, {
// Map system_mode back to both 'state' and 'system_mode'
from: (v, meta) => {
const modes = ['cool', 'heat', 'fan_only'];
return {
system_mode: modes[v],
system_mode_device: modes[v],
};
},
}],
[4, 'eco_mode', tuya.valueConverter.onOff],
[16, 'current_heating_setpoint', tuya.valueConverter.divideBy10],
[19, 'max_temperature', tuya.valueConverter.divideBy10],
[24, 'local_temperature', tuya.valueConverter.divideBy10],
[26, 'min_temperature', tuya.valueConverter.divideBy10],
[27, 'local_temperature_calibration', tuya.valueConverter.localTemperatureCalibration],
[28, 'fan_mode', tuya.valueConverterBasic.lookup(
{'low': tuya.enum(0), 'medium': tuya.enum(1), 'high': tuya.enum(2), 'auto': tuya.enum(3)})],
[36, 'valve', tuya.valueConverterBasic.lookup({'OPEN': 0, 'CLOSE': 1})],
[40, 'child_lock', tuya.valueConverter.lockUnlock],
[103, 'deadzone_temperature', tuya.valueConverter.raw],
[104, 'min_temperature_limit', tuya.valueConverter.divideBy10],
[105, 'max_temperature_limit', tuya.valueConverter.divideBy10],
[106, 'schedule_sunday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(7)],
[107, 'schedule_saturday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(6)],
[108, 'schedule_friday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(5)],
[109, 'schedule_thursday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(4)],
[110, 'schedule_wednesday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(3)],
[111, 'schedule_tuesday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(2)],
[112, 'schedule_monday', tuya.valueConverter.thermostatScheduleDayMultiDPWithDayNumber(1)],
[101, 'manual_mode', tuya.valueConverter.onOff],
],
},
};
module.exports = definition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment