Skip to content

Instantly share code, notes, and snippets.

@9zigen
Last active January 22, 2024 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9zigen/d4baf2128eb2a4bee71dc3b11ebd2ad9 to your computer and use it in GitHub Desktop.
Save 9zigen/d4baf2128eb2a4bee71dc3b11ebd2ad9 to your computer and use it in GitHub Desktop.
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;
}
}
}
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: ['ptvo.switch'],
model: 'ptvo.switch',
vendor: 'Alab',
description: '[DiY Four Channels Relay Board](https://github.com/9zigen/)',
fromZigbee: [fz.on_off, fz.temperature, fzLocal.input],
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