local device = {} device.model = "TS0726_4_gang_2_scene" device.vendor = "Tuya" device.description = "4 gang switch + 2 scene with backlight" device.fingerprint = { { model = "TS0726", manufacturer = "_TZ300A_1owxkmsd" }, } -- All endpoints share the same descriptor (genOnOff + 0xE001), so the cluster -- fallback cannot tell relays from scene keys and exposes every endpoint as a -- switch. EP1-4 drive relays; EP5-6 are scene-only keys. -- Backlight and power-on behavior are not wired up yet. device.exposes = { { type = "switch", endpoint = "l1", features = { { type = "binary", name = "state", property = "state_l1", access = 7, value_on = "ON", value_off = "OFF", description = "On/off state of the switch", endpoint = "l1", }, }, }, { type = "switch", endpoint = "l2", features = { { type = "binary", name = "state", property = "state_l2", access = 7, value_on = "ON", value_off = "OFF", description = "On/off state of the switch", endpoint = "l2", }, }, }, { type = "switch", endpoint = "l3", features = { { type = "binary", name = "state", property = "state_l3", access = 7, value_on = "ON", value_off = "OFF", description = "On/off state of the switch", endpoint = "l3", }, }, }, { type = "switch", endpoint = "l4", features = { { type = "binary", name = "state", property = "state_l4", access = 7, value_on = "ON", value_off = "OFF", description = "On/off state of the switch", endpoint = "l4", }, }, }, { type = "enum", name = "switch_mode", property = "switch_mode_l1", access = 3, values = { "switch", "scene" }, description = "switch: key toggles the relay; scene: key only sends an action", category = "config", endpoint = "l1", }, { type = "enum", name = "switch_mode", property = "switch_mode_l2", access = 3, values = { "switch", "scene" }, description = "switch: key toggles the relay; scene: key only sends an action", category = "config", endpoint = "l2", }, { type = "enum", name = "switch_mode", property = "switch_mode_l3", access = 3, values = { "switch", "scene" }, description = "switch: key toggles the relay; scene: key only sends an action", category = "config", endpoint = "l3", }, { type = "enum", name = "switch_mode", property = "switch_mode_l4", access = 3, values = { "switch", "scene" }, description = "switch: key toggles the relay; scene: key only sends an action", category = "config", endpoint = "l4", }, { type = "enum", name = "action", property = "action", access = 1, values = { "scene_1", "scene_2", "scene_3", "scene_4", "scene_5", "scene_6" }, description = "Triggered action (e.g. a button click)", category = "diagnostic", }, } device.tuya = { magicPacket = true } local SWITCH_MODE = { switch = 0, scene = 1 } -- Scene keys, and relay keys in switch_mode "scene", send the Tuya-specific -- genOnOff command 0xFD instead of toggling. Report it as scene_. device.fromZigbee = { "on_off", { cluster = 0x0006, type = "command", convert = function(msg) if msg.is_attribute or msg.cmd_or_attr_id ~= 0xFD then return nil end return { action = "scene_" .. msg.endpoint } end, }, } device.toZigbee = { "on_off", { key = "switch_mode", convert = function(value, endpoint) local mode = SWITCH_MODE[value] if mode == nil then return nil end -- manuSpecificTuya3 (0xE001) switchMode attr 0xD020 (ENUM8), per endpoint. return { cluster = 0xE001, endpoint = endpoint, isAttribute = true, attrId = 0xD020, attrType = 0x30, payload = { mode } } end, }, } device.endpoint = { l1 = 1, l2 = 2, l3 = 3, l4 = 4, } device.configure = { bind = { "genOnOff" }, reporting = { { cluster = "genOnOff", attribute = "onOff", min = 0, max = 3600, change = 0, }, }, } device.meta = { multiEndpoint = true } return device