Skip to content

[External Converter]: TS0001 from _TZ3000_5rpu3r0d (ASTHome Zigbee light switch)Β #30440

@slippery-carrot

Description

@slippery-carrot

Link

https://asthome.com.au/products/1-4-gang-zigbee-no-neutral-smart-switch-glass-saa-approved-for-australia-black-or-white?variant=41705026158775

Database entry

            "friendly_name": "Master Bedroom Light Switch",                 "ieee_address": "0xa4c138ea612640e4",                 "interview_completed": true,                 "interview_state": "SUCCESSFUL",                 "interviewing": false,                 "manufacturer": "_TZ3000_5rpu3r0d",                 "model_id": "TS0001",                 "network_address": 60820,                 "power_source": "Mains (single phase)",                 "supported": true,                 "type": "Router"

Zigbee2MQTT version

2.7.2 (unknown)

External converter

// /config/zigbee2mqtt/external_converters/ts0001_tz3000_5rpu3r0d_backlight.mjs

import reporting from "zigbee-herdsman-converters/lib/reporting";
import tuya from "zigbee-herdsman-converters/lib/tuya";
import {presets, access} from "zigbee-herdsman-converters/lib/exposes";

const e = presets;
const ea = access;

// Custom fromZigbee: convert the manufacturer-specific attribute into a nice ON/OFF
const fzBacklightMode = {
    cluster: "genOnOff",
    type: ["attributeReport", "readResponse"],
    convert: (model, msg) => {
        if (msg.data && msg.data.tuyaBacklightMode !== undefined) {
            return {backlight_mode: msg.data.tuyaBacklightMode === 2 ? "ON" : "OFF"};
        }
        return {};
    },
};

// Custom toZigbee: write exactly what the dev console shows
const tzBacklightMode = {
    key: ["backlight_mode"],
    convertSet: async (entity, key, value) => {
        // Accept: "ON"/"OFF", true/false, 1/2
        const on =
            value === "ON" || value === "on" || value === true || value === 2 || value === "2";

        const tuyaValue = on ? 2 : 1;

        // This matches the log: wrote {"tuyaBacklightMode":2} to genOnOff
        await entity.write("genOnOff", {tuyaBacklightMode: tuyaValue});

        return {state: {backlight_mode: on ? "ON" : "OFF"}};
    },
    convertGet: async (entity) => {
        await entity.read("genOnOff", ["tuyaBacklightMode"]);
    },
};

export default {
    fingerprint: tuya.fingerprint("TS0001", ["_TZ3000_5rpu3r0d"]),
    model: "TS0001_switch_1_gang_backlight_5rpu3r0d",
    vendor: "Tuya",
    description: "1-gang switch with backlight (_TZ3000_5rpu3r0d)",

    // Keep the standard Tuya on/off + power-on behaviour support
    extend: [
        tuya.modernExtend.tuyaOnOff({
            powerOnBehavior2: true,
            // IMPORTANT: do NOT enable backlightModeOffOn here; we are overriding it ourselves.
            // backlightModeOffOn: true,
        }),
    ],

    fromZigbee: [fzBacklightMode],
    toZigbee: [tzBacklightMode],

    exposes: [
        // modernExtend already exposes the main relay + power_on_behavior;
        // we add an extra expose for backlight.
        e.binary("backlight_mode", ea.ALL, "ON", "OFF").withDescription("Mode of the backlight"),
    ],

    configure: async (device, coordinatorEndpoint) => {
        await tuya.configureMagicPacket(device, coordinatorEndpoint);
        await reporting.bind(device.getEndpoint(1), coordinatorEndpoint, ["genOnOff"]);
    },
};

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

What works
Turning the switch on/off
Switch backlight
Power on behaviour

Notes

Forgive the code in advance, my background is embedded C (of which I'm OK, not great). I had a lot of help with GhatGPT 5.2 with this one.

I am not sure if there are other features that can be used with this switch, I'm pretty sure there are existing converters that will work with this device. I based it off the TS0001_switch_1_gang and TS0001_1_gang_switch converters in the tuya.ts file.

I also can't seem to find my database file, so hopefully what I've added is fine

software_build_id: undefined
date_code: ``
endpoints:

{"1":{"clusters":{"input":["genIdentify","genGroups","genScenes","genOnOff","57344","manuSpecificTuya3","genBasic"],"output":["genOta","genTime"]}},"242":{"clusters":{"input":[],"output":["greenPower"]}}}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions