Koenkk / zigbee2mqtt

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

[New device support]: Tuya TS0601 / _TZE204_5lc9gpx3 #23856

Open pcxnet opened 2 months ago

pcxnet commented 2 months ago

Link

https://nolink

Database entry

{"id":32,"type":"Router","ieeeAddr":"0xa4c1384b5c4f60a6","nwkAddr":37589,"manufId":4417,"manufName":"_TZE204_5lc9gpx3","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":"��l.\u0017��l.\u0013ël.eīl.\u0012","65506":56,"65508":0,"65534":0,"stackVersion":0,"dateCode":"","manufacturerName":"_TZE204_5lc9gpx3","zclVersion":3,"appVersion":74,"modelId":"TS0601","powerSource":1}}},"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":1725522730904}

Comments

This is a light switch which has customizable backlight LED colours, as well as power reporting.

I got all the endpoint codes, but the instructions say the "Event Details" are garbage, but mine are all actual data, like colours and power usage. Screenshot 2024-09-05 174846

These are the "Code" from the Tuya website Switch 1 Master Switch 13 Restart Status 14 Indicator Status 15 Backlight Switch 16 Add Electircity 20 Current Current 21 Current Power 22 Current Voltage 23 Voltage Coefficient 25 Electric Coefficient 26 Power Coefficient 27 Electricity Coefficient 28 Restart Status 29 Backlight 102 On Colour 103 Off Colour 104

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 legacy = require('zigbee-herdsman-converters/lib/legacy');
const ota = require('zigbee-herdsman-converters/lib/ota');
const modernExtend = require('zigbee-herdsman-converters/lib/modernExtend');
const utils = require('zigbee-herdsman-converters/lib/utils');
const globalStore = require('zigbee-herdsman-converters/lib/store');
const e = exposes.presets;
const ea = exposes.access;
const tuya = require('zigbee-herdsman-converters/lib/tuya');

const definition = {
    fingerprint: [
        {
            // The model ID from: Device with modelID 'TS0601' is not supported
            // You may need to add \u0000 at the end of the name in some cases
            modelID: 'TS0601',
            // The manufacturer name from: Device with modelID 'TS0601' is not supported.
            manufacturerName: '_TZE204_5lc9gpx3',
        },
    ],
    model: 'TS0601',
    vendor: 'TuYa',
    description: '1 Gang Custom Color Light Switch',
    fromZigbee: [tuya.fz.datapoints],
    toZigbee: [tuya.tz.datapoints],
    onEvent: tuya.onEventSetTime, // Add this if you are getting no converter for 'commandMcuSyncTime'
    configure: tuya.configureMagicPacket,
    exposes: [
        // Here you should put all functionality that your device exposes
    ],
    meta: {
        // All datapoints go in here
        tuyaDatapoints: [],
    },
    extend: [
        // A preferred new way of extending functionality.
    ],
};

module.exports = definition;

What does/doesn't work with the external definition?

I got the basic parts in, but I feel this is a bit complex and I'm not sure where to start. The automatic JS code to paste in the console window didn't work, so i got these codes from each of the network dev tool "code" values, hopefully its right.

If someone could tell me what I need to do to get all the colours image

Power Usage: image

and then the basic switch functionality that would be amazing.

pcxnet commented 2 months ago

I have most of it working except setting the colors `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 e = exposes.presets; const ea = exposes.access; const tuya = require('zigbee-herdsman-converters/lib/tuya');

const colorOptions = [ 'Red', 'Blue', 'Green', 'White', 'Yellow', 'Magenta', 'Cyan', 'WarmWhite', 'WarmYellow' ];

const definition = { fingerprint: tuya.fingerprint('TS0601', ['_TZE204_5lc9gpx3']), model: 'PCX 1 Gang Custom Light Switches', vendor: 'Tuya', description: '1 gang switch with power meter and custom lights', fromZigbee: [tuya.fz.datapoints], toZigbee: [tuya.tz.datapoints], configure: tuya.configureMagicPacket, exposes: [ e.switch().withEndpoint('l1').setAccess('state', ea.STATE_SET), e.voltage(), e.current(), e.power(), e.enum('power_on_behavior', ea.STATE_SET, ['Off', 'On', 'Previous']) .withDescription('Controls the behavior when the device is powered on'), e.binary('backlight', ea.STATE_SET, 'On', 'Off') .withDescription('Enable/disable the backlight'), e.numeric('backlight_brightness', ea.STATE_SET).withValueMin(0).withValueMax(100) .withDescription('Brightness of the backlight'), e.enum('on_color', ea.STATE_SET, colorOptions) .withDescription('Color when the switch is on'), e.enum('off_color', ea.STATE_SET, colorOptions) .withDescription('Color when the switch is off'), ], meta: { tuyaDatapoints: [ [1, 'state', tuya.valueConverter.onOff], [21, 'current', tuya.valueConverter.divideBy1000], [22, 'power', tuya.valueConverter.divideBy10], [23, 'voltage', tuya.valueConverter.divideBy10], [14, 'power_on_behavior', tuya.valueConverter.powerOnBehavior], [16, 'backlight', tuya.valueConverter.onOff], [102, 'backlight_brightness', tuya.valueConverter.raw], [103, 'on_color', { from: (value) => value.toString().charAt(0).toUpperCase() + value.toString().slice(1).toLowerCase(), to: (value) => value.toString().charAt(0).toUpperCase() + value.toString().slice(1).toLowerCase(), }], [104, 'off_color', { from: (value) => value.toString().charAt(0).toUpperCase() + value.toString().slice(1).toLowerCase(), to: (value) => value.toString().charAt(0).toUpperCase() + value.toString().slice(1).toLowerCase(), }], ], }, endpoint: (device) => { return {l1: 1}; }, };

module.exports = definition;`

However every time i change something i get an error error 2024-09-05 23:55:36z2m: EventBus error 'Publish/mqttMessage': Cannot read properties of undefined (reading 'some')

Also, digging deeper into Tuya, the colors are set with night_light_color image

night_light_mode image

I've tried sending "Red", "red" , "RED" to the endpoint for the color but they dont seem to work. the logs show the color name so not sure what I'm missing. I have 1,2,3, and 4 gangs of these so once I have done them I can make all 4 files.

image

pcxnet commented 1 month ago

Is anyone able to help with this please?