Skip to content

Instantly share code, notes, and snippets.

@ov1d1u
Last active May 17, 2022 19:30
Show Gist options
  • Save ov1d1u/c4b9bc96180cdab1f97db671b8696d82 to your computer and use it in GitHub Desktop.
Save ov1d1u/c4b9bc96180cdab1f97db671b8696d82 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 e = exposes.presets;
const ea = exposes.access;
const tuya = require("zigbee-herdsman-converters/lib/tuya");
const definition = {
// Since a lot of Tuya devices use the same modelID, but use different data points
// it's usually necessary to provide a fingerprint instead of a zigbeeModel
fingerprint: [
{
// The model ID from: Device with modelID 'TS0601' is not supported
// You may need to add \u0000 at the end of the name in some cases
modelID: 'TS0601',
// The manufacturer name from: Device with modelID 'TS0601' is not supported.
manufacturerName: '_TZE200_u319yc66'
},
],
model: 'Zigbee-818',
vendor: 'Tuya',
description: 'Smart Gas Leakage Detector',
fromZigbee: [
{
cluster: 'manuSpecificTuya',
type: ['commandSetDataResponse', 'commandDataReport', 'commandDataResponse'],
convert: (model, msg, publish, options, meta) => {
const dp = msg.data.dp;
// meta.logger.error(`From Zigbee: ${dp}: ${JSON.stringify(msg.data)}`);
const result = {};
for (const dpValue of msg.data.dpValues) {
const dp = dpValue.dp;
const value = tuya.getDataValue(dpValue);
const result_lookup = {
0: 'checking',
1: 'check_success',
2: 'check_failure',
3: 'others'
}
switch (dp) {
case tuya.dataPoints.state:
return {gas: value === 0 ? true : false};
case 8:
return {self_test: value === true ? 'ON' : 'OFF'};
// case 9:
// return {checking_result: result_lookup[value]}
case 16:
return {muffling: value === true ? 'ON' : 'OFF'}
default:
meta.logger.error(`zigbee-herdsman-converters:tuya_gas: Unrecognized DP #${
dp} with data ${JSON.stringify(msg.data)}`);
}
}
return result;
}
}
],
toZigbee: [
tz.tuya_data_point_test, // Another debug converter
{
key: ['self_test'],
convertSet: async (entity, key, value, meta) => {
await tuya.sendDataPointBool(entity, 8, value === 'ON');
},
},
{
key: ['muffling'],
convertSet: async (entity, key, value, meta) => {
await tuya.sendDataPointBool(entity, 16, value === 'ON');
}
}
],
onEvent: tuya.setTime, // Add this if you are getting no converter for 'commandSetTimeRequest'
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genBasic']);
},
exposes: [
e.gas(), exposes.binary('self_test', ea.STATE_SET, 'ON', 'OFF'), exposes.binary('muffling', ea.STATE_SET, 'ON', 'OFF')
],
};
module.exports = definition;
@ben8p
Copy link

ben8p commented Mar 23, 2022

Thanks for this!
You made my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment