Open pcxnet opened 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
night_light_mode
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.
Is anyone able to help with this please?
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.
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
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
Power Usage:
and then the basic switch functionality that would be amazing.