-
-
Save Koenkk/004d651c9bf3d79f844279d3eaab424e 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 utils = require('zigbee-herdsman-converters/lib/utils'); | |
const ota = require('zigbee-herdsman-converters/lib/ota'); | |
const tuya = require('zigbee-herdsman-converters/lib/tuya'); | |
const e = exposes.presets; | |
const ea = exposes.access; | |
const valueConverter = { | |
phaseA: { | |
from: (v) => { | |
return {current: ((v[4] | v[3] << 8) / 1000), voltage: ((v[1] | v[0] << 8) / 10), power: ((v[7] | v[6] << 8))} | |
}, | |
}, | |
threshold: { | |
from: (v) => { | |
const lookup = {0: 'not_set', 1: 'over_current', 3: 'over_voltage'}; | |
return { | |
threshold_1: lookup[v[0]], | |
threshold_1_value : (value[3] | value[2] << 8), | |
threshold_2: lookup[value[4]], | |
threshold_2_value : (value[7] | value[6] << 8), | |
}; | |
}, | |
}, | |
alarm: tuya.valueConverterBasic.lookup({'clear': 0, 'over_current': 1, 'over_power': 2, 'over_voltage': 4, 'wrong_frequency': 8}), | |
}; | |
const tuyaExposes = { | |
threshold: (l) => exposes.enum(`threshold_${l}`, ea.STATE, ['not_set', 'over_current', 'over_voltage']) | |
.withDescription(`Treshold ${l} state`), | |
tresholdValue: (l) => exposes.numeric(`threshold_${l}_value`, ea.STATE) | |
.withDescription(`Treshold ${l} value`), | |
alarm: () => exposes.enum(`alarm`, ea.STATE, ['clear', 'over_current', 'over_voltage', 'over_power', 'wrong_frequency']) | |
.withDescription(`Alarm state`), | |
}; | |
const definition = { | |
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_eaac7dkw']), | |
model: 'TS0601_din_2', | |
vendor: 'TuYa', | |
description: 'Zigbee DIN energy meter', | |
fromZigbee: [tuya.fzDataPoints], | |
toZigbee: [tuya.tzDataPoints], | |
configure: tuya.configureMagicPacket, | |
exposes: [tuya.exposes.switch(), e.energy(), e.power(), e.voltage(), e.current(), | |
tuyaExposes.threshold('1'), tuyaExposes.threshold('2'), tuyaExposes.tresholdValue('1'), tuyaExposes.tresholdValue('2'), | |
tuyaExposes.alarm()], | |
meta: { | |
tuyaDatapoints: [ | |
[1, 'energy', tuya.valueConverter.divideBy100], | |
[6, null, valueConverter.phaseA], // voltage, power and current | |
[10, 'alarm', valueConverter.alarm], | |
[16, 'state', tuya.valueConverter.onOff], | |
[17, null, valueConverter.threshold], | |
], | |
}, | |
}; | |
module.exports = definition; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment