diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index ae1341d0fb075..e69b097273aae 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -5912,6 +5912,46 @@ const definitions: Definition[] = [ ], }, }, + { + fingerprint: tuya.fingerprint('TS0601', ['_TZE204_81yrt3lo']), + model: 'PJ-1203A', + vendor: 'TuYa', + description: 'Bidirectional energy meter with 80A current clamp', + fromZigbee: [tuya.fz.datapoints], + toZigbee: [tuya.tz.datapoints], + onEvent: tuya.onEventSetTime, + configure: tuya.configureMagicPacket, + exposes: [ + e.ac_frequency(), e.voltage(), + tuya.exposes.powerWithPhase('a'), tuya.exposes.powerWithPhase('b'), tuya.exposes.powerWithPhase('ab'), + tuya.exposes.currentWithPhase('a'), tuya.exposes.currentWithPhase('b'), + tuya.exposes.powerFactorWithPhase('a'), tuya.exposes.powerFactorWithPhase('b'), + tuya.exposes.energyFlowWithPhase('a'), tuya.exposes.energyFlowWithPhase('b'), + tuya.exposes.energyWithPhase('a'), tuya.exposes.energyWithPhase('b'), + tuya.exposes.energyProducedWithPhase('a'), tuya.exposes.energyProducedWithPhase('b'), + e.numeric('update_frequency', ea.STATE).withUnit('s').withDescription('Update frequency'), + ], + meta: { + tuyaDatapoints: [ + [111, 'ac_frequency', tuya.valueConverter.divideBy100], + [101, 'power_a', tuya.valueConverter.divideBy10], + [105, 'power_b', tuya.valueConverter.divideBy10], + [115, 'power_ab', tuya.valueConverter.divideBy10], + [112, 'voltage', tuya.valueConverter.divideBy10], + [113, 'current_a', tuya.valueConverter.divideBy1000], + [114, 'current_b', tuya.valueConverter.divideBy1000], + [110, 'power_factor_a', tuya.valueConverter.divideBy100], + [121, 'power_factor_b', tuya.valueConverter.divideBy100], + [102, 'energy_flow_a', tuya.valueConverterBasic.lookup({'consuming': 0, 'producing': 1})], + [104, 'energy_flow_b', tuya.valueConverterBasic.lookup({'consuming': 0, 'producing': 1})], + [106, 'energy_a', tuya.valueConverter.divideBy100], + [108, 'energy_b', tuya.valueConverter.divideBy100], + [107, 'energy_produced_A', tuya.valueConverter.divideBy100], + [109, 'energy_produced_B', tuya.valueConverter.divideBy100], + [129, 'update_frequency', tuya.valueConverter.raw], + ], + }, + }, ]; module.exports = definitions; diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index 29457dfcc6a93..a08f6b9c49da4 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -254,6 +254,10 @@ const tuyaExposes = { gasValue: () => e.numeric('gas_value', ea.STATE).withDescription('Measured gas concentration'), energyWithPhase: (phase: string) => e.numeric(`energy_${phase}`, ea.STATE).withUnit('kWh') .withDescription(`Sum of consumed energy (phase ${phase.toUpperCase()})`), + energyProducedWithPhase: (phase: string) => e.numeric(`energy_${phase}`, ea.STATE).withUnit('kWh') + .withDescription(`Sum of produced energy (phase ${phase.toUpperCase()})`), + energyFlowWithPhase: (phase: string) => e.enum(`energy_flow_${phase}`, ea.STATE, ['consuming', 'producing']) + .withDescription(`Direction of energy (phase ${phase.toUpperCase()})`), voltageWithPhase: (phase: string) => e.numeric(`voltage_${phase}`, ea.STATE).withUnit('V') .withDescription(`Measured electrical potential value (phase ${phase.toUpperCase()})`), powerWithPhase: (phase: string) => e.numeric(`power_${phase}`, ea.STATE).withUnit('W')