Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk authored Aug 24, 2020
2 parents 10501a5 + a365081 commit 3eb66bd
Show file tree
Hide file tree
Showing 8 changed files with 1,123 additions and 570 deletions.
27 changes: 27 additions & 0 deletions converters/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ const TuyaThermostatSystemModes = {
5: 'boost',
6: 'complex',
};
const TuyaThermostatPresets = {
0: 'away',
1: 'schedule',
2: 'manual',
3: 'comfort',
4: 'eco',
5: 'boost',
6: 'complex',
};

const TuyaThermostatSystemModes2 = {
0: 'auto',
1: 'cool',
2: 'heat',
3: 'dry',
4: 'fan',
};

const TuyaFanModes = {
0: 'low',
1: 'medium',
2: 'high',
3: 'auto',
};

const TuyaThermostatWeekFormat = {
0: '5+2',
Expand Down Expand Up @@ -104,6 +128,9 @@ module.exports = {
TuyaThermostatSystemModes,
TuyaThermostatWeekFormat,
TuyaThermostatForceMode,
TuyaThermostatPresets,
lockSourceName,
armMode,
TuyaFanModes,
TuyaThermostatSystemModes2,
};
105 changes: 83 additions & 22 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ const tuyaThermostat = (model, msg, publish, options, meta) => {
switch (dp) {
case 104: // 0x6800 window params
return {
window_detection: data[0] ? 'ON' : 'OFF',
window_detection_params: {
valve: data[0] ? 'ON' : 'OFF',
// valve: data[0] ? 'ON' : 'OFF',
temperature: data[1],
minutes: data[2],
},
Expand Down Expand Up @@ -307,17 +308,27 @@ const tuyaThermostat = (model, msg, publish, options, meta) => {
return {eco_temperature: dataAsDecNumber};
case 621: // 0x6d02 valve position
return {position: dataAsDecNumber};
case 626: // 0x7202 preset temp ?
return {preset_temperature: dataAsDecNumber};
case 629: // 0x7502 preset ?
return {preset: dataAsDecNumber};
case 1028: // 0x0404 Mode changed
if (common.TuyaThermostatSystemModes.hasOwnProperty(dataAsDecNumber)) {
return {system_mode: common.TuyaThermostatSystemModes[dataAsDecNumber]};
case 626: // 0x7202 away preset temperature
return {away_preset_temperature: dataAsDecNumber};
case 629: // 0x7502 away preset number of days
return {away_preset_days: dataAsDecNumber};
case 1028: {// 0x0404 Preset changed
const ret = {};
const presetOk = utils.getMetaValue(msg.endpoint, model, 'tuyaThermostatPreset').hasOwnProperty(dataAsDecNumber);
const modeOk = utils.getMetaValue(msg.endpoint, model, 'tuyaThermostatSystemMode').hasOwnProperty(dataAsDecNumber);
if (presetOk) {
ret.preset = utils.getMetaValue(msg.endpoint, model, 'tuyaThermostatPreset')[dataAsDecNumber];
}
if (modeOk) {
ret.system_mode = utils.getMetaValue(msg.endpoint, model, 'tuyaThermostatSystemMode')[dataAsDecNumber];
} else {
console.log(`TRV system mode ${dataAsDecNumber} is not recognized.`);
console.log(`TRV preset/mode ${dataAsDecNumber} is not recognized.`);
return;
}
return ret;
}
case 1029: // fan mode 0 - low , 1 - medium , 2 - high , 3 - auto ( tested on 6dfgetq TUYA zigbee module )
return {fan_mode: common.TuyaFanModes[dataAsDecNumber]};
case 1130: // 0x6a04 force mode 0 - normal, 1 - open, 2 - close
return {force: common.TuyaThermostatForceMode[dataAsDecNumber]};
case 1135: // Week select 0 - 5 days, 1 - 6 days, 2 - 7 days
Expand Down Expand Up @@ -440,7 +451,7 @@ const converters = {
// Deprecated: voltage is = mV now but should be V
payload.voltage = msg.data['batteryVoltage'] * 100;

if (model.meta && model.meta.batery && model.meta.battery.voltageToPercentage) {
if (model.meta && model.meta.battery && model.meta.battery.voltageToPercentage) {
if (model.meta.battery.voltageToPercentage === 'CR2032') {
payload.battery = toPercentageCR2032(payload.voltage);
}
Expand Down Expand Up @@ -515,6 +526,13 @@ const converters = {
return {pressure: calibrateAndPrecisionRoundOptions(pressure, options, 'pressure')};
},
},
co2: {
cluster: 'msCO2',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
return {co2: Math.floor(msg.data.measuredValue * 1000000)};
},
},
occupancy: {
// This is for occupancy sensor that send motion start AND stop messages
cluster: 'msOccupancySensing',
Expand Down Expand Up @@ -591,7 +609,13 @@ const converters = {
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('currentLevel')) {
const property = postfixWithEndpointName('brightness', msg, model);
return {[property]: msg.data['currentLevel']};
let value = msg.data['currentLevel'];

if (meta.state && meta.state.state === 'OFF') {
value = 0;
}

return {[property]: value};
}
},
},
Expand Down Expand Up @@ -1073,6 +1097,22 @@ const converters = {
return payload;
},
},
command_on_state: {
cluster: 'genOnOff',
type: 'commandOn',
convert: (model, msg, publish, options, meta) => {
const property = postfixWithEndpointName('state', msg, model);
return {[property]: 'ON'};
},
},
command_off_state: {
cluster: 'genOnOff',
type: 'commandOff',
convert: (model, msg, publish, options, meta) => {
const property = postfixWithEndpointName('state', msg, model);
return {[property]: 'OFF'};
},
},
identify: {
cluster: 'genIdentify',
type: ['attributeReport', 'readResponse'],
Expand Down Expand Up @@ -1130,7 +1170,7 @@ const converters = {
cluster: 'genOnOff',
type: ['attributeReport'],
convert: (model, msg, publish, options, meta) => {
if (['QBKG04LM', 'QBKG11LM', 'QBKG21LM', 'QBKG03LM', 'QBKG12LM', 'QBKG22LM'].includes(model.model) && !msg.data['61440']) {
if (['QBKG04LM', 'QBKG11LM', 'QBKG21LM', 'QBKG03LM', 'QBKG12LM', 'QBKG22LM'].includes(model.model) && msg.data['61440']) {
return;
}

Expand Down Expand Up @@ -2440,13 +2480,19 @@ const converters = {
convert: (model, msg, publish, options, meta) => {
if (msg.data['65281']) {
const data = msg.data['65281'];
return {
const payload = {
state: data['100'] === 1 ? 'ON' : 'OFF',
power: precisionRound(data['152'], 2),
voltage: precisionRound(data['150'] * 0.1, 1),
consumption: precisionRound(data['149'], 2),
temperature: calibrateAndPrecisionRoundOptions(data['3'], options, 'temperature'),
};

if (data.hasOwnProperty('150')) {
// Not all support voltage: https://github.com/Koenkk/zigbee2mqtt/issues/4092
payload.voltage = precisionRound(data['150'] * 0.1, 1);
}

return payload;
}
},
},
Expand Down Expand Up @@ -3477,11 +3523,13 @@ const converters = {
type: 'commandStep',
convert: (model, msg, publish, options, meta) => {
const direction = msg.data.stepmode === 1 ? 'down' : 'up';
return {
const payload = {
action: `brightness_${direction}_click`,
step_size: msg.data.stepsize,
transition_time: msg.data.transtime,
};
addActionGroup(payload, msg, model);
return payload;
},
},
tint404011_brightness_updown_hold: {
Expand All @@ -3497,10 +3545,12 @@ const converters = {
}
store[deviceID].movemode = direction;

return {
const payload = {
action: `brightness_${direction}_hold`,
rate: msg.data.rate,
};
addActionGroup(payload, msg, model);
return payload;
},
},
tint404011_brightness_updown_release: {
Expand All @@ -3513,9 +3563,9 @@ const converters = {
}

const direction = store[deviceID].movemode;
return {
action: `brightness_${direction}_release`,
};
const payload = {action: `brightness_${direction}_release`};
addActionGroup(payload, msg, model);
return payload;
},
},
SA003_on_off: {
Expand Down Expand Up @@ -3546,32 +3596,38 @@ const converters = {
cluster: 'genBasic',
type: 'write',
convert: (model, msg, publish, options, meta) => {
return {action: `scene_${msg.data['16389']}`};
const payload = {action: `scene_${msg.data['16389']}`};
addActionGroup(payload, msg, model);
return payload;
},
},
tint404011_move_to_color_temp: {
cluster: 'lightingColorCtrl',
type: 'commandMoveToColorTemp',
convert: (model, msg, publish, options, meta) => {
return {
const payload = {
action: `color_temp`,
action_color_temperature: msg.data.colortemp,
transition_time: msg.data.transtime,
};
addActionGroup(payload, msg, model);
return payload;
},
},
tint404011_move_to_color: {
cluster: 'lightingColorCtrl',
type: 'commandMoveToColor',
convert: (model, msg, publish, options, meta) => {
return {
const payload = {
action_color: {
x: precisionRound(msg.data.colorx / 65535, 3),
y: precisionRound(msg.data.colory / 65535, 3),
},
action: 'color_wheel',
transition_time: msg.data.transtime,
};
addActionGroup(payload, msg, model);
return payload;
},
},
E1524_E1810_toggle: {
Expand Down Expand Up @@ -5172,6 +5228,11 @@ const converters = {
type: 'commandGetData',
convert: tuyaThermostat,
},
tuya_fan_mode: {
cluster: 'manuSpecificTuyaDimmer',
type: 'commandGetData',
convert: tuyaThermostat,
},
tuya_switch: {
cluster: 'manuSpecificTuyaDimmer',
type: 'raw',
Expand Down
Loading

0 comments on commit 3eb66bd

Please sign in to comment.