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

TS011F socket with Power metering #8836

Open
MakorKa opened this issue Feb 19, 2025 · 4 comments
Open

TS011F socket with Power metering #8836

MakorKa opened this issue Feb 19, 2025 · 4 comments

Comments

@MakorKa
Copy link

MakorKa commented Feb 19, 2025

I get one Tuya SOcket with power metering, that has missing data about Power.

After few tries, i was able to write new converter.

const m = require('zigbee-herdsman-converters/lib/modernExtend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const exposes = require('zigbee-herdsman-converters/lib/modernExtend');
const NS = 'zhc:tuya';
const {tuyaMagicPacket} = tuya.modernExtend;


const definition = {
    fingerprint: [{modelID: 'TS011F', manufacturerName: '_TZ3000_qlmnxmac'}],
    model: 'TS011F_2_gang_power',
    vendor: 'Tuya',
    description: '2 gang socket with power monitoring',
    extend: [
        tuyaMagicPacket(),
        m.deviceEndpoints({endpoints: {left: 1, right: 2}, multiEndpointSkip: ['current', 'voltage', 'power', 'energy']}),
        m.onOff({powerOnBehavior: false, endpointNames: ['left', 'right']}),
        m.identify(),
        m.electricityMeter(),
    ],
};

module.exports = definition;

Now it expose

{
    "backlight_mode": "high",
    "child_lock": "UNLOCK",
    "linkquality": 204,
    "power_on_behavior": "previous",
    "state_l1": "ON",
    "state_l2": "ON",
    "update": {
        "installed_version": -1,
        "latest_version": -1,
        "state": null
    },
    "current": 0,
    "energy": 43,
    "power": 0,
    "voltage": 228,
    "identify": null,
    "state_left": "ON",
    "state_right": "ON"
}

But i still have few issues and didnt know how to fix them.
First is energy: 43 should be too high, maybe 0.43 is correct. How to add divider?
Second - OTA now lost

And third:

[2025-02-19 17:10:17] debug: 	zh:controller:endpoint: Error: ZCL command 0xa4c138aef804068e/1 haElectricalMeasurement.read(["acPowerDivisor","acPowerMultiplier"], {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"reservedBits":0,"writeUndiv":false}) failed (Status 'UNSUPPORTED_ATTRIBUTE')
    at Endpoint.checkStatus (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:349:28)
    at Endpoint.zclCommand (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:954:26)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at runNextTicks (node:internal/process/task_queues:69:3)
    at processImmediate (node:internal/timers:459:9)
    at Endpoint.read (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:445:29)
    at result.configure (/app/node_modules/.pnpm/zigbee-herdsman-converters@21.31.0/node_modules/src/lib/modernExtend.ts:1944:37)
    at Object.configure (/app/node_modules/.pnpm/zigbee-herdsman-converters@21.31.0/node_modules/src/index.ts:272:21)
    at Configure.configure (/app/lib/extension/configure.ts:124:13)
    at Immediate.<anonymous> (/app/lib/extension/configure.ts:69:17)
[2025-02-19 17:10:17] error: 	z2m: Failed to configure '0xa4c138aef804068e', attempt 1 (Error: ZCL command 0xa4c138aef804068e/1 haElectricalMeasurement.read(["acPowerDivisor","acPowerMultiplier"], {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"reservedBits":0,"writeUndiv":false}) failed (Status 'UNSUPPORTED_ATTRIBUTE')
    at Endpoint.checkStatus (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:349:28)
    at Endpoint.zclCommand (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:954:26)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at runNextTicks (node:internal/process/task_queues:69:3)
    at processImmediate (node:internal/timers:459:9)
    at Endpoint.read (/app/node_modules/.pnpm/zigbee-herdsman@3.2.5/node_modules/zigbee-herdsman/src/controller/model/endpoint.ts:445:29)
    at result.configure (/app/node_modules/.pnpm/zigbee-herdsman-converters@21.31.0/node_modules/src/lib/modernExtend.ts:1944:37)
    at Object.configure (/app/node_modules/.pnpm/zigbee-herdsman-converters@21.31.0/node_modules/src/index.ts:272:21)
    at Configure.configure (/app/lib/extension/configure.ts:124:13)
    at Immediate.<anonymous> (/app/lib/extension/configure.ts:69:17))

How to fix this and make device fully functional?

@MakorKa
Copy link
Author

MakorKa commented Feb 19, 2025

After few more hours playing with it, i have this converter.

const m = require('zigbee-herdsman-converters/lib/modernExtend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const ota = require('zigbee-herdsman-converters/lib/ota');
const reporting = require('zigbee-herdsman-converters/lib/reporting');

const NS = 'zhc:tuya';
const { tuyaMagicPacket } = tuya.modernExtend;
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    fingerprint: [{ modelID: 'TS011F', manufacturerName: '_TZ3000_qlmnxmac' }],
    model: 'TS011F_2_gang_wall',
    vendor: 'Tuya',
    ota: true, //ota.zigbeeOTA,
    description: '2 gang socket with power monitoring',
    configure: async (device, coordinatorEndpoint) => {
        await tuya.configureMagicPacket(device, coordinatorEndpoint);
        const endpoint = device.getEndpoint(1);
        endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acCurrentDivisor: 1000, acCurrentMultiplier: 1, acPowerDivisor: 1, acPowerMultiplier: 1});
        endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 100, multiplier: 1});
        
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'haElectricalMeasurement', 'seMetering']);
        await reporting.rmsVoltage(endpoint, {change: 1});
        await reporting.rmsCurrent(endpoint, {change: 50});
        await reporting.activePower(endpoint, {change: 10});
        await reporting.currentSummDelivered(endpoint);
        
        device.save();
    },
    extend: [
        tuyaMagicPacket(),
        /*m.deviceEndpoints({
            endpoints: { 'l1': 1, 'l2': 2 },
            multiEndpointSkip: ['current', 'voltage', 'power', 'energy'],
        }),*/
        tuya.modernExtend.tuyaOnOff({
            backlightModeLowMediumHigh: true, 
            childLock: true, 
            endpoints: ['l1', 'l2'], 
            electricalMeasurements: true
        }),
        //m.electricityMeter(),
        //m.identify(),
    ],
    endpoint: (device) => {
        return {l1: 1, l2: 2};
    },
};

module.exports = definition;

And now it returns

{
    "backlight_mode": "high",
    "child_lock": "UNLOCK",
    "current": 6.3,
    "energy": 0.52,
    "linkquality": 208,
    "power": 1493,
    "power_on_behavior": "previous",
    "power_on_behavior_l1": "previous",
    "state": "ON",
    "state_l1": "ON",
    "state_l2": "ON",
    "update": {
        "installed_version": 192,
        "latest_version": 192,
        "state": "idle"
    },
    "voltage": 231
}

But i have power_on_behavior_l1 that is not expected.

@AlexanderLeporiday
Copy link
Contributor

AlexanderLeporiday commented Feb 20, 2025

This device is already in a converter by fingerprint here
You might be able to add the missing functionality to the existing converter rather than create a new converter just for your vendor.
I'm not sure if model names need to be unique or not between converters.

There's also a 2 gang socket with power monitoring (and USB ports) here

{
	fingerprint: tuya.fingerprint('TS011F', [
		'_TZ3000_mvn6jl7x',
		'_TZ3000_raviyuvk',
		'_TYZB01_hlla45kx',
		'_TZ3000_92qd4sqa',
		'_TZ3000_zwaadvus',
		'_TZ3000_k6fvknrr',
		'_TZ3000_6s5dc9lx',
		'_TZ3000_helyqdvs',
		'_TZ3000_rgpqqmbj',
		'_TZ3000_8nyaanzb',
		'_TZ3000_iy2c3n6p',
		'_TZ3000_qlmnxmac',
		'_TZ3000_sgb0xhwn',
	]),
	model: 'TS011F_2_gang_wall',
	vendor: 'Tuya',
	description: '2 gang wall outlet',
	ota: true,
	extend: [tuya.modernExtend.tuyaOnOff({backlightModeLowMediumHigh: true, childLock: true, endpoints: ['l1', 'l2']})],
	whiteLabel: [
		tuya.whitelabel('ClickSmart+', 'CMA30036', '2 gang socket outlet', ['_TYZB01_hlla45kx']),
		tuya.whitelabel('Rylike', 'RY-WS02Z', '2 gang socket outlet AU', ['_TZ3000_rgpqqmbj', '_TZ3000_8nyaanzb', '_TZ3000_iy2c3n6p']),
		tuya.whitelabel('Nova Digital', 'NT-S2', '2 gang socket outlet BR', ['_TZ3000_sgb0xhwn']),
	],
	endpoint: (device) => {
		return {l1: 1, l2: 2};
	},
	meta: {multiEndpoint: true, multiEndpointSkip: ['power_on_behavior']},
	configure: tuya.configureMagicPacket,
}

@MakorKa
Copy link
Author

MakorKa commented Feb 20, 2025

@AlexanderLeporiday later yesterday i found that model TS011F_2_gang_wall for _TZ3000_qlmnxmac is not correctly added.

It is same as

fingerprint: tuya.fingerprint('TS011F', ['_TZ3000_dd8wwzcy']),
model: 'MG-AUZG01',
vendor: 'MakeGood',

only difference is that MG-AUZG01 is AU socket, _TZ3000_qlmnxmac is EU socket.

@AlexanderLeporiday
Copy link
Contributor

Is your device MakeGood branded?
Otherwise this should probably be moved to the Tuya converter and both devices listed via the whiteLabel field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants