Skip to content

Improve ZNCLBL01LM support #5104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,18 @@ const converters = {
}
},
},
xiaomi_curtain_battery_voltage: {
key: ['voltage'],
convertGet: async (entity, key, meta) => {
switch (meta.mapped.model) {
case 'ZNCLBL01LM':
await entity.read('aqaraOpple', [0x040B], manufacturerOptions.xiaomi);
break;
default:
throw new Error(`xiaomi_curtain_battery_voltage - unsupported model: ${meta.mapped.model}`);
}
},
},
xiaomi_curtain_acn002_charging_status: {
key: ['charging_status'],
convertGet: async (entity, key, meta) => {
Expand Down Expand Up @@ -6513,10 +6525,11 @@ const converters = {
}
},
},
ZNCLBL01LM_battery_voltage: {
key: ['voltage'],
convertGet: async (entity, key, meta) => {
await entity.read('aqaraOpple', [0x040B], manufacturerOptions.xiaomi);
ZNCLBL01LM_hooks_action: {
key: ['hooks_action'],
convertSet: async (entity, key, value, meta) => {
const lookup = {'unlock': 0, 'lock': 1};
await entity.write('aqaraOpple', {0x0427: {value: lookup[value], type: 0x20}}, manufacturerOptions.xiaomi);
},
},
ZNCLBL01LM_hooks_state: {
Expand All @@ -6525,6 +6538,32 @@ const converters = {
await entity.read('aqaraOpple', [0x0428], manufacturerOptions.xiaomi);
},
},
ZNCLBL01LM_hand_open: {
key: ['hand_open'],
convertSet: async (entity, key, value, meta) => {
await entity.write('aqaraOpple', {0x0401: {value: !value, type: 0x10}}, manufacturerOptions.xiaomi);
},
convertGet: async (entity, key, meta) => {
await entity.read('aqaraOpple', [0x0401], manufacturerOptions.xiaomi);
},
},
ZNCLBL01LM_limits_calibration: {
key: ['limits_calibration'],
convertSet: async (entity, key, value, meta) => {
switch (value) {
case 'start':
await entity.write('aqaraOpple', {0x0407: {value: 0x01, type: 0x20}}, manufacturerOptions.xiaomi);
break;
case 'end':
await entity.write('aqaraOpple', {0x0407: {value: 0x02, type: 0x20}}, manufacturerOptions.xiaomi);
break;
case 'reset':
await entity.write('aqaraOpple', {0x0407: {value: 0x00, type: 0x20}}, manufacturerOptions.xiaomi);
// also? await entity.write('aqaraOpple', {0x0402: {value: 0x00, type: 0x10}}, manufacturerOptions.xiaomi);
break;
}
},
},
wiser_vact_calibrate_valve: {
key: ['calibrate_valve'],
convertSet: async (entity, key, value, meta) => {
Expand Down
38 changes: 27 additions & 11 deletions devices/xiaomi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1875,22 +1875,38 @@ module.exports = [
vendor: 'Xiaomi',
whiteLabel: [{vendor: 'Xiaomi', model: 'CM-M01'}],
description: 'Aqara curtain driver E1',
fromZigbee: [fz.battery, fz.xiaomi_curtain_position_tilt, fz.aqara_opple, fz.power_source],
toZigbee: [tz.xiaomi_curtain_position_state, tz.ZNCLBL01LM_battery_voltage, tz.ZNCLBL01LM_hooks_state,
tz.power_source, tz.battery_percentage_remaining],
exposes: [e.cover_position().setAccess('state', ea.ALL), e.battery().withAccess(ea.STATE_GET),
fromZigbee: [
fz.battery,
fz.xiaomi_curtain_position_tilt,
fz.aqara_opple,
fz.power_source,
],
toZigbee: [
tz.xiaomi_curtain_position_state,
tz.xiaomi_curtain_battery_voltage,
tz.ZNCLBL01LM_hooks_action,
tz.ZNCLBL01LM_hooks_state,
tz.ZNCLBL01LM_hand_open,
tz.ZNCLBL01LM_limits_calibration,
tz.power_source,
tz.battery_percentage_remaining,
],
exposes: [
e.cover_position().setAccess('state', ea.ALL),
exposes.binary('hand_open', ea.ALL, true, false).withDescription('Pulling curtains by hand starts the motor'),
exposes.enum('limits_calibration', ea.SET, ['start', 'end', 'reset']).withDescription('Calibrate the position limits'),
e.battery().withAccess(ea.STATE_GET),
e.battery_voltage().withAccess(ea.STATE_GET),
e.device_temperature(),
e.action(['manual_open', 'manual_close']),
exposes.enum('motor_state', ea.STATE, ['stopped', 'opening', 'closing', 'pause'])
.withDescription('Motor state'),
exposes.binary('running', ea.STATE, true, false)
.withDescription('Whether the motor is moving or not'),
exposes.enum('hooks_state', ea.STATE_GET, ['unlocked', 'locked', 'locking', 'unlocking'])
.withDescription('Hooks state'),
exposes.enum('motor_state', ea.STATE, ['stopped', 'opening', 'closing', 'pause']).withDescription('Motor state'),
exposes.binary('running', ea.STATE, true, false).withDescription('Whether the motor is moving or not'),
exposes.enum('hooks_action', ea.SET, ['unlock', 'lock']).withDescription('Hooks action'),
Copy link
Owner

@Koenkk Koenkk Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change this to action and rename the unlock/lock to hooks_unlock/hooks_lock

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that collide somehow with the existing read-only field also called action?

Skärmavbild 2022-12-09 kl  01 51 18

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since action is not a state (something that has to be persisted).

exposes.enum('hooks_state', ea.STATE_GET, ['unlocked', 'locked', 'locking', 'unlocking']).withDescription('Hooks state'),
exposes.numeric('target_position', ea.STATE).withUnit('%').withDescription('Target position'),
exposes.enum('power_source', ea.STATE_GET, ['battery', 'dc_source']).withDescription('The current power source'),
exposes.binary('charging', ea.STATE_GET, true, false).withDescription('The current charging state')],
exposes.binary('charging', ea.STATE_GET, true, false).withDescription('The current charging state'),
],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await endpoint.read('genPowerCfg', ['batteryPercentageRemaining']);
Expand Down
18 changes: 14 additions & 4 deletions lib/xiaomi.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,15 @@ const numericAttributes2Payload = (msg, meta, model, options, dataObject) => {
payload.button_switch_mode = value === 1 ? 'relay_and_usb' : 'relay';
break;
case '1025':
payload.options = {...payload.options, // next values update only when curtain finished initial setup and knows current position
reverse_direction: value[2] == '\u0001',
hand_open: value[5] == '\u0000',
};
if (['ZNCLBL01LM'].includes(model.model)) {
payload.hand_open = !value;
} else {
// next values update only when curtain finished initial setup and knows current position
payload.options = {...payload.options,
reverse_direction: value[2] == '\u0001',
hand_open: value[5] == '\u0000',
};
}
break;
case '1028':
payload = {...payload,
Expand Down Expand Up @@ -597,6 +602,11 @@ const numericAttributes2Payload = (msg, meta, model, options, dataObject) => {
{1: 'manual_open', 2: 'manual_close'})[value];
}
break;
case '1063':
if (['ZNCLBL01LM'].includes(model.model)) {
payload.hooks_action = {0: 'unlock', 1: 'lock'}[value];
}
break;
case '1064':
if (['ZNCLBL01LM'].includes(model.model)) {
payload.hooks_state = {0: 'unlocked', 1: 'locked', 2: 'locking', 3: 'unlocking'}[value];
Expand Down