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

Added Zigbee to RS485 controller support #8222

Merged
merged 5 commits into from
Oct 31, 2024
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
166 changes: 165 additions & 1 deletion src/devices/easyiot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as iconv from 'iconv-lite';

import * as exposes from '../lib/exposes';
import {logger} from '../lib/logger';
import {DefinitionWithExtend, Fz, Tz} from '../lib/types';
import {deviceEndpoints, electricityMeter, onOff, windowCovering} from '../lib/modernExtend';
import * as reporting from '../lib/reporting';
import {DefinitionWithExtend, Fz, KeyValueAny, Tz} from '../lib/types';

const NS = 'zhc:easyiot';
const ea = exposes.access;
Expand Down Expand Up @@ -30,6 +32,7 @@ const fzLocal = {
return {last_received_status: hexString};
},
} satisfies Fz.Converter,

easyiot_sp1000_recv_status: {
cluster: 'tunneling',
type: ['commandTransferDataResp'],
Expand All @@ -43,6 +46,27 @@ const fzLocal = {
}
},
} satisfies Fz.Converter,

easyiot_action: {
cluster: 'genOnOff',
type: ['commandOn', 'commandOff', 'commandToggle'],
convert: (model, msg, publish, options, meta) => {
const lookup: KeyValueAny = {commandToggle: 'single', commandOn: 'double', commandOff: 'long'};
let buttonMapping: KeyValueAny = null;
if (model.model === 'ZB-SW01') {
buttonMapping = {1: '1'};
} else if (model.model === 'ZB-WB02') {
buttonMapping = {1: '1', 2: '2'};
} else if (model.model === 'ZB-WB03') {
buttonMapping = {1: '1', 2: '2', 3: '3'};
} else if (model.model === 'ZB-WB08') {
buttonMapping = {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8'};
}

const button = buttonMapping ? `${buttonMapping[msg.endpoint.ID]}_` : '';
return {action: `${button}${lookup[msg.type]}`};
},
} satisfies Fz.Converter,
};

const tzLocal = {
Expand Down Expand Up @@ -192,6 +216,146 @@ const definitions: DefinitionWithExtend[] = [
e.text('last_received_status', ea.STATE).withDescription('status'),
],
},
{
fingerprint: [{modelID: 'ZB-RS485', manufacturerName: 'easyiot'}],
model: 'RS485',
vendor: 'easyiot',
description: 'Zigbee to RS485 controller',
fromZigbee: [fzLocal.easyiot_ir_recv_command],
toZigbee: [tzLocal.easyiot_ir_send_command],
exposes: [
e.text('last_received_command', ea.STATE).withDescription('Received data'),
e.text('send_command', ea.SET).withDescription('Send data'),
],
},
{
zigbeeModel: ['ZB-PM01'],
model: 'ZB-PM01',
vendor: 'easyiot',
description: 'Smart circuit breaker with Metering',
extend: [onOff({powerOnBehavior: false}), electricityMeter()],
},
{
zigbeeModel: ['ZB-WC01'],
model: 'ZB-WC01',
vendor: 'easyiot',
description: 'Curtain motor',
extend: [windowCovering({controls: ['lift'], configureReporting: false})],
},
{
zigbeeModel: ['ZB-WB01'],
model: 'ZB-WB01',
vendor: 'easyiot',
description: '1-button remote control',
fromZigbee: [fzLocal.easyiot_action],
toZigbee: [],
exposes: [e.action(['1_single', '1_double', '1_long']), e.battery()],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint, {min: 30, max: 1800, change: 1});
},
},
{
zigbeeModel: ['ZB-WB02'],
model: 'ZB-WB02',
vendor: 'easyiot',
description: '2-button remote control',
fromZigbee: [fzLocal.easyiot_action],
toZigbee: [],
exposes: [e.action(['1_single', '1_double', '1_long', '2_single', '2_double', '2_long']), e.battery()],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint, {min: 30, max: 1800, change: 1});
await reporting.bind(device.getEndpoint(2), coordinatorEndpoint, ['genOnOff']);
},
},
{
zigbeeModel: ['ZB-WB03'],
model: 'ZB-WB03',
vendor: 'easyiot',
description: '3-button remote control',
fromZigbee: [fzLocal.easyiot_action],
toZigbee: [],
exposes: [e.action(['1_single', '1_double', '1_long', '2_single', '2_double', '2_long', '3_single', '3_double', '3_long']), e.battery()],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint, {min: 30, max: 1800, change: 1});
await reporting.bind(device.getEndpoint(2), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(3), coordinatorEndpoint, ['genOnOff']);
},
},
{
zigbeeModel: ['ZB-WB08'],
model: 'ZB-WB08',
vendor: 'easyiot',
description: '8-button remote control',
fromZigbee: [fzLocal.easyiot_action],
toZigbee: [],
exposes: [
e.action([
'1_single',
'1_double',
'1_long',
'2_single',
'2_double',
'2_long',
'3_single',
'3_double',
'3_long',
'4_single',
'4_double',
'4_long',
'5_single',
'5_double',
'5_long',
'6_single',
'6_double',
'6_long',
'7_single',
'7_double',
'7_long',
'8_single',
'8_double',
'8_long',
]),
e.battery(),
],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']);
await reporting.batteryPercentageRemaining(endpoint, {min: 30, max: 1800, change: 1});
await reporting.bind(device.getEndpoint(2), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(3), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(4), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(5), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(6), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(7), coordinatorEndpoint, ['genOnOff']);
await reporting.bind(device.getEndpoint(8), coordinatorEndpoint, ['genOnOff']);
},
},
{
fingerprint: [{modelID: 'ZB-PSW04', manufacturerName: 'easyiot'}],
model: 'ZB-PSW04',
vendor: 'easyiot',
description: 'Zigbee 4-channel relay',
extend: [
deviceEndpoints({endpoints: {l1: 1, l2: 2, l3: 3, l4: 4}}),
onOff({endpointNames: ['l1', 'l2', 'l3', 'l4'], configureReporting: false, powerOnBehavior: false}),
],
},
{
fingerprint: [{modelID: 'ZB-SW08', manufacturerName: 'easyiot'}],
model: 'ZB-SW08',
vendor: 'easyiot',
description: 'Zigbee 8-channel relay',
extend: [
deviceEndpoints({endpoints: {l1: 1, l2: 2, l3: 3, l4: 4, l5: 5, l6: 6, l7: 7, l8: 8}}),
onOff({endpointNames: ['l1', 'l2', 'l3', 'l4', 'l5', 'l6', 'l7', 'l8'], configureReporting: false, powerOnBehavior: false}),
],
},
];

export default definitions;
Expand Down
Loading