Last active
January 22, 2024 16:10
-
-
Save 9zigen/75ae3f3d75685a486a3c6040b0111891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 extend = require('zigbee-herdsman-converters/lib/extend'); | |
const ota = require('zigbee-herdsman-converters/lib/ota'); | |
const {} = require('zigbee-herdsman-converters/lib/tuya'); | |
const utils = require('zigbee-herdsman-converters/lib/utils'); | |
const globalStore = require('zigbee-herdsman-converters/lib/store'); | |
const e = exposes.presets; | |
const ea = exposes.access; | |
function hasEndpoints(device, endpoints) { | |
const eps = device.endpoints.map((e) => e.ID); | |
for (const endpoint of endpoints) { | |
if (!eps.includes(endpoint)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
const fzLocal = { | |
input: { | |
cluster: 'genAnalogInput', | |
type: ['attributeReport', 'readResponse'], | |
convert: (model, msg, publish, options, meta) => { | |
const payload = {}; | |
payload['in' + (msg.endpoint.ID - 4)] = msg.data["presentValue"]; | |
return payload; | |
} | |
}, | |
switch: { | |
cluster: 'genOnOff', | |
type: ['attributeReport'], | |
convert: (model, msg, publish, options, meta) => { | |
const payload = {}; | |
payload['state_l' + (msg.endpoint.ID)] = msg.data["onOff"]? 'ON' : 'OFF'; | |
return payload; | |
} | |
} | |
} | |
const tzLocal = { | |
input: { | |
key: ['in1', 'in2', 'in3', 'in4'], | |
convertGet: async (entity, key, meta) => { | |
const epId = parseInt(key.substr(1, 2)); | |
if (hasEndpoints(meta.device, [epId])) { | |
const endpoint = meta.device.getEndpoint(epId); | |
await endpoint.read('genAnalogInput', ['presentValue']); | |
} | |
}, | |
}, | |
} | |
const definition = { | |
zigbeeModel: ['alab.switch'], | |
model: 'alab.switch', | |
vendor: 'Alab', | |
description: '[DiY Four Channels Relay Board](https://github.com/9zigen/)', | |
fromZigbee: [fz.on_off, fz.temperature, fzLocal.input, fzLocal.switch], | |
toZigbee: [tz.on_off, tzLocal.input], | |
endpoint: (device) => { | |
return { | |
l1: 1, l2: 2, l3: 3, l4: 4, in1: 5, in2: 6, in3: 7, in4: 8 | |
}; | |
}, | |
exposes: [ | |
e.switch().withEndpoint('l1'), | |
e.switch().withEndpoint('l2'), | |
e.switch().withEndpoint('l3'), | |
e.switch().withEndpoint('l4'), | |
exposes.numeric('in1', ea.ALL).withUnit('0/1').withDescription('Input 1 state'), | |
exposes.numeric('in2', ea.ALL).withUnit('0/1').withDescription('Input 2 state'), | |
exposes.numeric('in3', ea.ALL).withUnit('0/1').withDescription('Input 3 state'), | |
exposes.numeric('in4', ea.ALL).withUnit('0/1').withDescription('Input 4 state') | |
] | |
}; | |
module.exports = definition; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment