Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update frient powermeter led 2 #8044

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/converters/fromZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ const converters1 = {
convert: (model, msg, publish, options, meta) => {
if (utils.hasAlreadyProcessedMessage(msg, model)) return;
const payload: KeyValueAny = {};
const multiplier = msg.endpoint.getClusterAttributeValue('seMetering', 'multiplier') as number;
const divisor = msg.endpoint.getClusterAttributeValue('seMetering', 'divisor') as number;
const multiplier = (msg.endpoint.getClusterAttributeValue('seMetering', 'multiplier') ?? 1) as number;
const divisor = (msg.endpoint.getClusterAttributeValue('seMetering', 'divisor') ?? 1000) as number;
const factor = multiplier && divisor ? multiplier / divisor : null;

if (msg.data.instantaneousDemand !== undefined) {
Expand Down
27 changes: 17 additions & 10 deletions src/devices/frient.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import fz from '../converters/fromZigbee';
import * as exposes from '../lib/exposes';
import {electricityMeter, onOff, ota} from '../lib/modernExtend';
import {develcoModernExtend} from '../lib/develco';
import {battery, electricityMeter, onOff, ota} from '../lib/modernExtend';
import * as reporting from '../lib/reporting';
import {DefinitionWithExtend} from '../lib/types';

const e = exposes.presets;
// NOTE! Develco and Frient is the same company, therefore we use develco specific things in here.

const definitions: DefinitionWithExtend[] = [
{
zigbeeModel: ['EMIZB-141'],
model: 'EMIZB-141',
vendor: 'Frient',
description: 'Smart powermeter Zigbee bridge',
fromZigbee: [fz.metering, fz.battery],
toZigbee: [],
extend: [ota()],
exposes: [e.battery(), e.power(), e.energy()],
configure: async (device, coordinatorEndpoint) => {
description: 'frient Electricity Meter Interface 2 LED',
extend: [
ota(),
electricityMeter({cluster: 'metering', power: {divisor: 1000, multiplier: 1}, energy: {divisor: 1000, multiplier: 1}}),
battery(),
develcoModernExtend.addCustomClusterManuSpecificDevelcoGenBasic(),
develcoModernExtend.readGenBasicPrimaryVersions(),
develcoModernExtend.pulse_configuration(),
develcoModernExtend.current_summation(),
],

configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(2);
await reporting.bind(endpoint, coordinatorEndpoint, ['seMetering', 'genPowerCfg']);
await reporting.instantaneousDemand(endpoint);
await reporting.readMeteringMultiplierDivisor(endpoint);
},
},
{
Expand Down
60 changes: 59 additions & 1 deletion src/lib/develco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Zcl} from 'zigbee-herdsman';

import {presets as e, access as ea} from './exposes';
import {deviceAddCustomCluster, deviceTemperature, numeric, NumericArgs, temperature} from './modernExtend';
import {Configure, Fz, ModernExtend} from './types';
import {Configure, Fz, ModernExtend, Tz} from './types';
import {getOptions, postfixWithEndpointName} from './utils';

const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.DEVELCO};

Expand Down Expand Up @@ -170,4 +171,61 @@ export const develcoModernExtend = {
valueIgnore: [0xffff, -0x8000],
...args,
}),
current_summation: () =>
({
isModernExtend: true,
toZigbee: [
{
key: ['current_summation'],
convertSet: async (entity, key, value, meta) => {
await entity.write('seMetering', {develcoCurrentSummation: value}, getOptions(meta.mapped, entity));
return {state: {current_summation: value}};
},
} satisfies Tz.Converter,
],
exposes: [
e
.numeric('current_summation', ea.SET)
.withDescription('Current summation value sent to the display. e.g. 570 = 0,570 kWh')
.withValueMin(0)
.withValueMax(268435455),
],
}) satisfies ModernExtend,
pulse_configuration: () =>
({
isModernExtend: true,
fromZigbee: [
{
cluster: 'seMetering',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: Record<string, unknown> = {};
if (msg.data?.develcoPulseConfiguration) {
result[postfixWithEndpointName('pulse_configuration', msg, model, meta)] = msg.data['develcoPulseConfiguration'];
}

return result;
},
} satisfies Fz.Converter,
],
toZigbee: [
{
key: ['pulse_configuration'],
convertSet: async (entity, key, value, meta) => {
await entity.write('seMetering', {develcoPulseConfiguration: value}, getOptions(meta.mapped, entity));
return {readAfterWriteTime: 200, state: {pulse_configuration: value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('seMetering', ['develcoPulseConfiguration'], manufacturerOptions);
},
} satisfies Tz.Converter,
],
exposes: [
e
.numeric('pulse_configuration', ea.ALL)
.withValueMin(0)
.withValueMax(65535)
.withDescription('Pulses per kwh. Default 1000 imp/kWh. Range 0 to 65535'),
],
}) satisfies ModernExtend,
};
Loading