Skip to content
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

Add operation_mode and action for Niko Switches #4061

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Changes from all 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
71 changes: 67 additions & 4 deletions devices/niko.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,60 @@ const reporting = require('../lib/reporting');
const e = exposes.presets;
const ea = exposes.access;

const fzLocal = {
fz: {
switch_operation_mode: {
cluster: 'manuSpecificNikoSwitchSetup',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const state = {};
if (msg.data.hasOwnProperty('operationMode')) {
const operationModeProperty = `operation_mode${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`;
const operationModeMap = {0x02: 'control_relay', 0x01: 'decoupled', 0x00: 'unknown'};
state[operationModeProperty] = operationModeMap[msg.data.operationMode];
}
return state;
},
},
switch_action: {
cluster: 'manuSpecificNikoSwitch',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const state = {};

if (msg.data.hasOwnProperty('action')) {
// NOTE: a single press = two seperate values reported, 16 followed by 64
// a hold/release cyle = three seperate values, 16, 32, and 48
const actionProperty = `action${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`;
const actionMap = {16: null, 64: 'single', 32: 'hold', 48: 'release'};
state[actionProperty] = actionMap[msg.data.action];
}
return state;
},
},
},
tz: {
switch_operation_mode: {
key: ['operation_mode'],
convertSet: async (entity, key, value, meta) => {
// WARN: while we can technically write 0x00 to the operationMode attribute
// this seems to brick the device and it will need to be rejoined
const operationModeLookup = {control_relay: 0x02, decoupled: 0x01};
if (!operationModeLookup.hasOwnProperty(value)) {
throw new Error(`operation_mode was called with an invalid value (${value})`);
} else {
const operationModeProperty = `operation_mode${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`;
await entity.write('manuSpecificNikoSwitchSetup', {'operationMode': operationModeLookup[value]});
return {state: {[operationModeProperty]: value.toLowerCase()}};
}
},
convertGet: async (entity, key, meta) => {
await entity.read('manuSpecificNikoSwitchSetup', ['operationMode']);
},
},
},
};

module.exports = [
{
zigbeeModel: ['Connected socket outlet'],
Expand Down Expand Up @@ -80,24 +134,27 @@ module.exports = [
model: '552-721X1',
vendor: 'Niko',
description: 'Single connectable switch',
fromZigbee: [fz.on_off],
toZigbee: [tz.on_off],
fromZigbee: [fz.on_off, fzLocal.fz.switch_operation_mode, fzLocal.fz.switch_action],
toZigbee: [tz.on_off, fzLocal.tz.switch_operation_mode],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
await reporting.onOff(endpoint);
await endpoint.read('manuSpecificNikoSwitchSetup', ['operationMode']);
},
exposes: [
e.switch(),
e.action(['single', 'hold', 'release']),
exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled']),
],
},
{
zigbeeModel: ['Double connectable switch,10A'],
model: '552-721X2',
vendor: 'Niko',
description: 'Double connectable switch',
fromZigbee: [fz.on_off],
toZigbee: [tz.on_off],
fromZigbee: [fz.on_off, fzLocal.fz.switch_operation_mode, fzLocal.fz.switch_action],
toZigbee: [tz.on_off, fzLocal.tz.switch_operation_mode],
endpoint: (device) => {
return {'l1': 1, 'l2': 2};
},
Expand All @@ -109,9 +166,15 @@ module.exports = [
await reporting.bind(ep2, coordinatorEndpoint, ['genOnOff']);
await reporting.onOff(ep1);
await reporting.onOff(ep2);
await ep1.read('manuSpecificNikoSwitchSetup', ['operationMode']);
await ep2.read('manuSpecificNikoSwitchSetup', ['operationMode']);
},
exposes: [
e.switch().withEndpoint('l1'), e.switch().withEndpoint('l2'),
e.action(['single', 'hold', 'release']).withEndpoint('l1'),
e.action(['single', 'hold', 'release']).withEndpoint('l2'),
exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled']).withEndpoint('l1'),
exposes.enum('operation_mode', ea.ALL, ['control_relay', 'decoupled']).withEndpoint('l2'),
],
},
];