Skip to content

Commit

Permalink
feat: ptvo.switch: expose DC power metering (#7390)
Browse files Browse the repository at this point in the history
* Added fields for DC power metering.

* Update for the PTVO device to use standard clusters for DC and AC power metering, and CO2.

* Formatting fix

* Formatting fixes

---------

Co-authored-by: ptvoinfo <xagga@ya.ru>
  • Loading branch information
ptvoinfo and ptvoinfo committed Apr 13, 2024
1 parent 04198e0 commit be49ef4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/converters/fromZigbee.ts
Expand Up @@ -772,6 +772,9 @@ const converters1 = {
{key: 'rmsVoltagePhB', name: 'voltage_phase_b', factor: 'acVoltage'},
{key: 'rmsVoltagePhC', name: 'voltage_phase_c', factor: 'acVoltage'},
{key: 'acFrequency', name: 'ac_frequency', factor: 'acFrequency'},
{key: 'dcPower', name: 'power', factor: 'dcPower'},
{key: 'dcCurrent', name: 'current', factor: 'dcCurrent'},
{key: 'dcVoltage', name: 'voltage', factor: 'dcVoltage'},
];

const payload: KeyValueAny = {};
Expand Down
15 changes: 14 additions & 1 deletion src/devices/custom_devices_diy.ts
Expand Up @@ -219,6 +219,10 @@ function ptvoAddStandardExposes(endpoint: Zh.Endpoint, expose: Expose[], options
if (endpoint.supportsInputCluster('genPowerCfg')) {
deviceOptions['expose_battery'] = true;
}
if (endpoint.supportsInputCluster('msCO2')) {
expose.push(e.co2().withEndpoint(epName));
deviceOptions['exposed_co2'] = true;
}
if (endpoint.supportsInputCluster('genMultistateInput') || endpoint.supportsOutputCluster('genMultistateInput')) {
deviceOptions['expose_action'] = true;
}
Expand Down Expand Up @@ -276,7 +280,7 @@ const definitions: Definition[] = [
description: 'Multi-functional device',
fromZigbee: [fz.battery, fz.on_off, fz.ptvo_multistate_action, legacy.fz.ptvo_switch_buttons, fz.ptvo_switch_uart,
fz.ptvo_switch_analog_input, fz.brightness, fz.ignore_basic_report, fz.temperature,
fzLocal.humidity2, fzLocal.pressure2, fzLocal.illuminance2],
fzLocal.humidity2, fzLocal.pressure2, fzLocal.illuminance2, fz.electrical_measurement, fz.metering, fz.co2],
toZigbee: [tz.ptvo_switch_trigger, tz.ptvo_switch_uart, tz.ptvo_switch_analog_input, tz.ptvo_switch_light_brightness, tzLocal.ptvo_on_off],
exposes: (device, options) => {
const expose: Expose[] = [];
Expand Down Expand Up @@ -489,6 +493,15 @@ const definitions: Definition[] = [
}
} catch (err) {/* do nothing */}
}
for (const endpoint of device.endpoints) {
if (endpoint.supportsInputCluster('haElectricalMeasurement')) {
endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {dcCurrentDivisor: 1000, dcCurrentMultiplier: 1,
dcPowerDivisor: 10, dcPowerMultiplier: 1, dcVoltageDivisor: 100, dcVoltageMultiplier: 1});
}
if (endpoint.supportsInputCluster('seMetering')) {
endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 100, multiplier: 1});
}
}
}
},
},
Expand Down

0 comments on commit be49ef4

Please sign in to comment.