Skip to content

Instantly share code, notes, and snippets.

@d3v2a
Last active November 15, 2021 16:37
Show Gist options
  • Save d3v2a/1a7944f60815809df3c58f37e631dcfe to your computer and use it in GitHub Desktop.
Save d3v2a/1a7944f60815809df3c58f37e631dcfe to your computer and use it in GitHub Desktop.
zigbee2mqtt ZLinky TIC
const fz = require("zigbee-herdsman-converters/converters/fromZigbee");
const exposes = require("zigbee-herdsman-converters/lib/exposes");
const constants = require("zigbee-herdsman-converters/lib/constants");
const e = exposes.presets;
const ea = exposes.access;
let option_standard = () => exposes.binary(`standard`, ea.SET, true, false).withDescription(`Compteur avec la TIC en mode standard`)
let option_triphase = () => exposes.binary(`triphase`, ea.SET, true, false).withDescription(`Compteur triphase`)
let option_production = () => exposes.binary(`production`, ea.SET, true, false).withDescription(`Compteur avec de la production`)
const fromzb = {
metering: {
cluster: "seMetering",
type: ["attributeReport", "readResponse"],
convert: (model, msg, publish, options, meta) => {
const payload = {};
let energy = 0;
let value = 0;
if (msg.data.hasOwnProperty("currentTier1SummDelivered")) {
value = msg.data["currentTier1SummDelivered"];
energy += value;
payload.energy_hc = value;
}
if (msg.data.hasOwnProperty("32")) {
value = msg.data["32"];
payload.ptec = value.replace('..', '');
}
if (msg.data.hasOwnProperty("currentTier2SummDelivered")) {
value = msg.data["currentTier2SummDelivered"];
energy += value;
payload.energy_hp = value;
}
if (msg.data.hasOwnProperty("currentSummDelivered")) {
if (msg.data.hasOwnProperty("currentSummDelivered")) {
value = msg.data["currentSummDelivered"];
energy += value;
payload.energy = value;
}
}
payload.energy_total = energy
return payload;
},
},
electrical_measurement: {
cluster: "haElectricalMeasurement",
type: ["attributeReport", "readResponse"],
convert: (model, msg, publish, options, meta) => {
msg.endpoint.read('seMetering', ['currentTier1SummDelivered', 'currentTier2SummDelivered',0x0020]);
const lookup = [{
key: "apparentPower",
name: "power",
factor: "acPower",
},
{
key: "rmsCurrent",
name: "current",
factor: "acCurrent",
},
];
const payload = {};
for (const entry of lookup) {
if (msg.data.hasOwnProperty(entry.key)) {
const property = entry.name;
payload[property] = msg.data[entry.key];
}
}
return payload;
},
},
};
const definition = {
zigbeeModel: ["ZLinky_TIC\u0000"],
model: "ZLinky_TIC",
vendor: "LiXee",
description: "Linky",
fromZigbee: [fromzb.metering, fz.identify, fromzb.electrical_measurement],
toZigbee: [],
configure: async (device, coordinatorEndpoint, logger) => {
try {
let endpoint = device.getEndpoint(1);
await endpoint.configureReporting(
"haElectricalMeasurement",
[{
attribute: "rmsCurrent",
minimumReportInterval: 10,
maximumReportInterval: constants.repInterval.MINUTES_5,
reportableChange: 1,
},
{
attribute: "apparentPower",
minimumReportInterval: 10,
maximumReportInterval: constants.repInterval.MINUTES_5,
reportableChange: 1,
} ]
);
} catch (error) {
logger.error(error);
}
},
options: [exposes.options.measurement_poll_interval(), option_standard(), option_triphase() ,option_production()],
exposes: [
exposes.numeric('energy_total', ea.STATE).withUnit('Wh').withDescription('Somme de la consommation total'),
exposes.numeric('energy_hc', ea.STATE).withUnit('Wh').withDescription('Somme de la consommation heure creuse'),
exposes.numeric('energy_hp', ea.STATE).withUnit('Wh').withDescription('Somme de la consommation heure creuse'),
exposes.numeric('ptec', ea.STATE).withDescription('Periode tarifaire en cours'),
e.energy().withUnit('Wh').withDescription('Somme de la consommation base'),
e.power(),
e.current()
],
};
module.exports = definition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment