Skip to content

Commit

Permalink
Rely on power measurements reporting instead of polling for Lidl HG08…
Browse files Browse the repository at this point in the history
…673-FR (#4791)

* Lidl: use Tuya TS011F basis for HG08673-FR

* Lidl: use Tuya TS011F basis for HG08673-FR

* Lidl: use Tuya TS011F basis for HG08673-FR (fix lint issues)
  • Loading branch information
nathan-gs committed Oct 30, 2022
1 parent c93c8d9 commit a1f9265
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions devices/lidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const e = exposes.presets;
const ea = exposes.access;
const tuya = require('../lib/tuya');
const globalStore = require('../lib/store');
const ota = require('../lib/ota');
const utils = require('../lib/utils');

const tuyaLocal = {
dataPoints: {
Expand Down Expand Up @@ -140,6 +142,20 @@ const fzLocal = {
}
},
},
metering_skip_duplicate: {
...fz.metering,
convert: (model, msg, publish, options, meta) => {
if (utils.hasAlreadyProcessedMessage(msg)) return;
return fz.metering.convert(model, msg, publish, options, meta);
},
},
electrical_measurement_skip_duplicate: {
...fz.electrical_measurement,
convert: (model, msg, publish, options, meta) => {
if (utils.hasAlreadyProcessedMessage(msg)) return;
return fz.electrical_measurement.convert(model, msg, publish, options, meta);
},
},
};
const tzLocal = {
zs_thermostat_child_lock: {
Expand Down Expand Up @@ -383,22 +399,27 @@ module.exports = [
model: 'HG08673-FR',
vendor: 'Lidl',
description: 'Silvercrest smart plug FR with power monitoring',
fromZigbee: [fz.on_off, fz.electrical_measurement, fz.metering, fz.ignore_basic_report, fz.tuya_switch_power_outage_memory],
toZigbee: [tz.on_off, tz.tuya_switch_power_outage_memory],
exposes: [e.switch(), e.power(), e.current(), e.voltage().withAccess(ea.STATE),
e.energy(), exposes.enum('power_outage_memory', ea.ALL, ['on', 'off', 'restore'])
.withDescription('Recover state after power outage')],
ota: ota.zigbeeOTA, // Even though it's a Lidl Device it supports Tuya OTA
fromZigbee: [fz.on_off, fzLocal.electrical_measurement_skip_duplicate, fzLocal.metering_skip_duplicate, fz.ignore_basic_report,
fz.tuya_switch_power_outage_memory, fz.ts011f_plug_indicator_mode, fz.ts011f_plug_child_mode],
toZigbee: [tz.on_off, tz.tuya_switch_power_outage_memory, tz.ts011f_plug_indicator_mode, tz.ts011f_plug_child_mode],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'haElectricalMeasurement']);
await endpoint.read('genBasic', ['manufacturerName', 'zclVersion', 'appVersion', 'modelId', 'powerSource', 0xfffe]);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'haElectricalMeasurement', 'seMetering']);
await reporting.rmsVoltage(endpoint, {change: 5});
await reporting.rmsCurrent(endpoint, {change: 50});
await reporting.activePower(endpoint, {change: 10});
await reporting.currentSummDelivered(endpoint);
endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acCurrentDivisor: 1000, acCurrentMultiplier: 1});
endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 100, multiplier: 1});
endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {
acVoltageMultiplier: 1, acVoltageDivisor: 1, acCurrentMultiplier: 1, acCurrentDivisor: 1000, acPowerMultiplier: 1,
acPowerDivisor: 1,
});
device.save();
},
options: [exposes.options.measurement_poll_interval()],
onEvent: tuya.onEventMeasurementPoll,
exposes: [e.switch(), e.power(), e.current(), e.voltage().withAccess(ea.STATE),
e.energy(), exposes.enum('power_outage_memory', ea.ALL, ['on', 'off', 'restore'])
.withDescription('Recover state after power outage'),
exposes.enum('indicator_mode', ea.ALL, ['off', 'off/on', 'on/off', 'on'])
.withDescription('Plug LED indicator mode'), e.child_lock()],
},
{
fingerprint: [{modelID: 'TS004F', manufacturerName: '_TZ3000_rco1yzb1'}],
Expand Down

0 comments on commit a1f9265

Please sign in to comment.