Il y a pas mal de tutos pour les convertisseurs externes, mais en résumé il faut faire ça :
- Créer un fichier pour le convertisseur externe.
Je l’ai nommé « ExtConverter_TankLevelMonitor.js »
- Editer le fichier et y coller ce code :
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 {} = require("zigbee-herdsman-converters/lib/modernExtend");
const e = exposes.presets;
const ea = exposes.access;
const tuya = require("zigbee-herdsman-converters/lib/tuya");
const utils = require("zigbee-herdsman-converters/lib/utils");
const dp = {
instalationHeight: 19,
liquidDepthMax: 21,
maxSet: 7,
miniSet: 8,
};
const tzdatapoints = {
key: [
"installation_height",
"liquid_depth_max",
"max_set",
"mini_set",
],
convertSet: async (entity, key, value, meta) => {
switch (key) {
case "installation_height": {
await tuya.sendDataPointValue(entity, dp.instalationHeight, value);
break;
}
case "liquid_depth_max": {
await tuya.sendDataPointValue(entity, dp.liquidDepthMax, value);
break;
}
case "max_set": {
await tuya.sendDataPointValue(entity, dp.maxSet, value);
break;
}
case "mini_set": {
await tuya.sendDataPointValue(entity, dp.miniSet, value);
break;
}
}
},
};
const definition = {
// Since a lot of TuYa devices use the same modelID, but use different datapoints
// it's 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_lvkk0hdg",
},
],
model: "TS0601_tlc2206zb",
vendor: "TuYa",
whiteLabel: [
{
vendor: "EPTTECH",
model: "TLC2206-ZB",
},
],
description: "EPTTECH Tank Level Monitor Zigbee",
fromZigbee: [tuya.fz.datapoints],
// toZigbee: [tuya.tz.datapoints],
toZigbee: [tzdatapoints],
onEvent: tuya.onEventSetTime, // Add this if you are getting no converter for 'commandMcuSyncTime'
configure: tuya.configureMagicPacket,
exposes: [
// Here you should put all functionality that your device exposes
e
.numeric("liquid_level_percent", ea.STATE)
.withUnit("%")
.withDescription("Liquid level percentage"),
e
.numeric("liquid_depth", ea.STATE)
.withUnit("m")
.withDescription("Liquid Depth"),
e
.enum("liquid_state", ea.STATE, ["low", "normal", "high"])
.withDescription("Liquid State"),
e
.numeric("installation_height", ea.STATE_SET)
.withUnit("mm")
.withDescription("Height from sensor to tank bottom")
.withValueMin(100)
.withValueMax(3000)
.withValueStep(1),
e
.numeric("mini_set", ea.STATE_SET)
.withUnit("%")
.withDescription("Liquid minimal percentage")
.withValueMin(0)
.withValueMax(100)
.withValueStep(1),
e
.numeric("max_set", ea.STATE_SET)
.withUnit("%")
.withDescription("Liquid max percentage")
.withValueMin(0)
.withValueMax(100)
.withValueStep(1),
e
.numeric("liquid_depth_max", ea.STATE_SET)
.withUnit("mm")
.withDescription("Height from sensor to liquid level")
.withValueMin(100)
.withValueMax(2000)
.withValueStep(1),
],
meta: {
// All datapoints go in here
tuyaDatapoints: [
[22, "liquid_level_percent", tuya.valueConverter.raw],
[2, "liquid_depth", tuya.valueConverter.divideBy100],
[
1,
"liquid_state",
tuya.valueConverterBasic.lookup({ low: 1, normal: 0, high: 2 }),
],
[19, "installation_height", tuya.valueConverter.raw],
[7, "max_set", tuya.valueConverter.raw],
[8, "mini_set", tuya.valueConverter.raw],
[21, "liquid_depth_max", tuya.valueConverter.raw],
],
},
extend: [
// A preferred new way of extending functionality.
],
};
module.exports = definition;
- Déposer ce fichier dans le dossier de Z2M ou dans un sous-dossier dédié.
J’ai tous mes convertisseurs dans « /config/zigbee2mqtt/external_converters »
- Editer le « configuration.yaml » de Z2M (pas celui de Home Assistant), y ajouter la rubrique pour les convertisseurs et le chemin vers ton fichier.
Chez moi :
external_converters:
- external_converters/ExtConverter_TankLevelMonitor.js
- Redémarrer Z2M