Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.08k stars 1.68k forks source link

[New device support]: Tuya bidirectional energy meter TS0601 / _TZE204_kpg9hpb0 #23716

Open M66B opened 2 months ago

M66B commented 2 months ago

Link

https://aliexpress.com/item/1005007268370253.html

Database entry

{"id":41,"type":"Router","ieeeAddr":"0xa4c1381013698826","nwkAddr":17772,"manufId":4417,"manufName":"_TZE204_kpg9hpb0","powerSource":"Mains (single phase)","modelId":"TS0601","epList":[1,242],"endpoints":{"1":{"profId":260,"epId":1,"devId":81,"inClusterList":[4,5,61184,0],"outClusterList":[25,10],"clusters":{"genBasic":{"attributes":{"65503":"n\u0006\u0000\u0000in\u0006\u0000\u0000i","65506":56,"65508":0,"65534":0,"modelId":"TS0601","manufacturerName":"_TZE204_kpg9hpb0","powerSource":1,"zclVersion":3,"appVersion":74,"stackVersion":0,"hwVersion":1,"dateCode":""}}},"binds":[],"configuredReportings":[],"meta":{}},"242":{"profId":41440,"epId":242,"devId":97,"inClusterList":[],"outClusterList":[33],"clusters":{},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":74,"stackVersion":0,"hwVersion":1,"dateCode":"","zclVersion":3,"interviewCompleted":true,"meta":{"configured":332242049},"lastSeen":1724432476431}

Comments

This is a partial implementation because I needed power measurements only. Switching on/off works, and voltage/current/power measurements too, but there are a number of other features as well. Perhaps somebody else can continue with this.

Datapoints seen

[2024-08-23 19:37:25] debug:    zhc:tuya: Datapoint 1 not defined for '_TZE204_kpg9hpb0' with value 0
[2024-08-23 19:37:29] debug:    zhc:tuya: Datapoint 11 not defined for '_TZE204_kpg9hpb0' with value false
[2024-08-23 19:37:29] debug:    zhc:tuya: Datapoint 13 not defined for '_TZE204_kpg9hpb0' with value 0
[2024-08-23 19:36:53] debug:    zhc:tuya: Datapoint 15 not defined for '_TZE204_kpg9hpb0' with value 0
[2024-08-23 19:35:32] debug:    zhc:tuya: Datapoint 17 not defined for '_TZE204_kpg9hpb0' with value 2P
[2024-08-23 19:36:45] debug:    zhc:tuya: Datapoint 18 not defined for '_TZE204_kpg9hpb0' with value v�
[2024-08-23 19:35:36] debug:    zhc:tuya: Datapoint 102 not defined for '_TZE204_kpg9hpb0' with value 5
[2024-08-23 19:35:37] debug:    zhc:tuya: Datapoint 104 not defined for '_TZE204_kpg9hpb0' with value true
[2024-08-23 19:36:46] debug:    zhc:tuya: Datapoint 107 not defined for '_TZE204_kpg9hpb0' with value 10
[2024-08-23 19:37:29] debug:    zhc:tuya: Datapoint 110 not defined for '_TZE204_kpg9hpb0' with value 139
[2024-08-23 19:35:40] debug:    zhc:tuya: Datapoint 127 not defined for '_TZE204_kpg9hpb0' with value 2
[2024-08-23 19:35:37] debug:    zhc:tuya: Datapoint 134 not defined for '_TZE204_kpg9hpb0' with value 2

External definition

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const modernExtend = require('zigbee-herdsman-converters/lib/modernExtend');
const e = exposes.presets;
const ea = exposes.access;
const tuya = require('zigbee-herdsman-converters/lib/tuya');

const definition = {
    fingerprint: [
        {
            modelID: 'TS0601',
            manufacturerName: '_TZE204_kpg9hpb0',
        },
    ],
    model: 'ZBN-JLS-63',
    vendor: 'Tuya',
    description: 'Bidirectional energy meter',
    fromZigbee: [tuya.fz.datapoints],
    toZigbee: [tuya.tz.datapoints],
    configure: tuya.configureMagicPacket,
    exposes: [
            tuya.exposes.switch(),
            e.voltage(),
            e.power(),
            e.current(),
    ],
    meta: {
            tuyaDatapoints: [
                [16, 'state', tuya.valueConverter.onOff],
                [
                    6,
                    null,
                    {
                        from: (v) => {
                            return {
                                voltage: v.readUint16BE(0) / 10,
                                current: ((v.readUint8(2) << 16) + (v.readUint8(3) << 8) + v.readUint8(4)) / 1000,
                                power: (v.readUint8(5) << 16) + (v.readUint8(6) << 8) + v.readUint8(7),
                            };
                        },
                    },
                ],
                [6, 'voltage', tuya.valueConverter.raw],
                [6, 'current', tuya.valueConverter.raw],
                [6, 'power', tuya.valueConverter.raw],
            ],
    },
    extend: [
    ],
};

module.exports = definition;
M66B commented 2 months ago

Probably same/similar device as #23613 #23502

Koenkk commented 2 months ago

Could you check if the device works when changing all occurrences of _TZE204_kpg9hpb0 to: _TZE200_lsanae15 or _TZE200_rhblgy0z or _TZE204_l6llgoxq or _TZE204_q22avxbv

M66B commented 2 months ago

@Koenkk the mentioned devices are similar in some aspects, but all missing:

[110, 'reverse_energy', tuya.valueConverter.divideBy100]

This type of device is new because formerly there were no devices on AliExpress that could measure bidirectional, targeted at solar panels, etc.

Koenkk commented 2 months ago

I see, feel free to make a PR for this device by clicking here