Skip to content

[External Converter] TS0502B from _TZ3210_ksqwlz9v #10580

@alexsotoaguilera

Description

@alexsotoaguilera

This is my external converter for TS0502B from _TZ3210_ksqwlz9v
software_build_id: undefined
date_code: ``
endpoints:

{"1":{"clusters":{"input":["genIdentify","genGroups","genScenes","genOnOff","touchlink","genLevelCtrl","lightingColorCtrl","manuSpecificTuya","genBasic"],"output":["genOta","genTime"]}},"242":{"clusters":{"input":[],"output":["greenPower"]}}}

What works / what doesn't?

Inverts color temp

Converter

// Tuya TS0502B custom converter - _TZ3210_ksqwlz9v
// Fixes inverted color temperature, stable brightness states, and ensures state reflects physical ON/OFF

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 e = exposes.presets;

module.exports = [
    {
        fingerprint: [{ modelID: 'TS0502B', manufacturerName: '_TZ3210_ksqwlz9v' }],
        model: 'TS0502B',
        vendor: 'Tuya',
        description: 'CCT LED controller (fixed color temperature inversion and stable brightness reflecting physical state)',

        fromZigbee: [
            {
                ...fz.on_off,
                convert: (model, msg, publish, options, meta) => {
                    if (!msg || !msg.data) return {};
                    const base = fz.on_off.convert(model, msg, publish, options, meta);
                    const result = base ? { ...base } : {};
                    return result; // leave ON/OFF as-is; brightness converter will correct if needed
                },
            },
            {
                ...fz.brightness,
                convert: (model, msg, publish, options, meta) => {
                    if (!msg || !msg.data) return {};
                    const base = fz.brightness.convert(model, msg, publish, options, meta);
                    const result = base ? { ...base } : {};
                    const level = msg.data.currentLevel;

                    if ('onoff' in msg.data) {
                        const onoff = msg.data.onoff;
                        if (onoff === 0 || level === 0) {
                            result.state = 'OFF';
                            result.brightness = 0;
                        } else if (onoff === 1) {
                            result.state = 'ON';
                            result.brightness = level !== undefined ? Math.max(level, 1) : 1;
                        }
                    } else if (level !== undefined) {
                        result.brightness = level;
                        result.state = level > 0 ? 'ON' : 'OFF';
                    }

                    return result;
                },
            },
            {
                ...fz.color_colortemp,
                convert: (model, msg, publish, options, meta) => {
                    if (!msg || !msg.data) return {};
                    const result = fz.color_colortemp.convert(model, msg, publish, options, meta);
                    if (result && result.color_temp !== undefined)
                        result.color_temp = 653 - result.color_temp;
                    return result || {};
                },
            },
        ],

        toZigbee: [
            tz.light_onoff_brightness,
            {
                ...tz.light_colortemp,
                key: ['color_temp'],
                convertSet: async (entity, key, value, meta) => {
                    if (value !== undefined) {
                        const newValue = 653 - value;
                        await tz.light_colortemp.convertSet(entity, key, newValue, meta);
                    }
                },
            },
            { key: ['color_temp_startup'], convertSet: async () => {} },
        ],

        exposes: [
            e.light().withBrightness().withColorTemp(150, 500)
                .withDescription('Brightness and color temperature control (inverted color_temp, OFF if brightness=0)'),
        ],
    },
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions