local device = {} device.model = "MG-ZG01W" device.vendor = "Tuya" device.description = "1 gang switch with power meter" device.exposes = { { type = "switch", features = { { type = "binary", name = "state", property = "state", access = 3, value_on = "ON", value_off = "OFF", description = "On/off state of the switch", }, }, }, { type = "numeric", name = "countdown", property = "countdown", access = 3, unit = "s", min = 0, max = 43200, value_step = 1, description = "Countdown to turn device off after a certain time", }, { type = "numeric", name = "voltage", property = "voltage", access = 1, unit = "V", description = "Measured electrical potential value", }, { type = "numeric", name = "current", property = "current", access = 1, unit = "A", description = "Instantaneous measured electrical current", }, { type = "numeric", name = "power", property = "power", access = 1, unit = "W", description = "Instantaneous measured power", }, { type = "enum", name = "power_on_behavior", property = "power_on_behavior", access = 3, description = "Controls the behavior when the device is powered on after power loss", category = "config", values = { "off", "previous", "on" }, }, { type = "binary", name = "backlight_mode", property = "backlight_mode", access = 3, value_on = "ON", value_off = "OFF", description = "Mode of the backlight", category = "config", }, } device.fromZigbee = { "electrical" } device.tuyaDatapoints = { { dp = 1, name = "state", converter = "onOff" }, { dp = 7, name = "countdown", converter = "countdown" }, { dp = 14, name = "power_on_behavior", converter = "powerOnBehavior" }, { dp = 16, name = "backlight_mode", converter = "onOff" }, { dp = 21, name = "current", converter = "divideBy1000" }, { dp = 22, name = "power", converter = "divideBy10" }, { dp = 23, name = "voltage", converter = "divideBy10" }, } device.configure = { bind = { "haElectricalMeasurement" }, reporting = { { cluster = "haElectricalMeasurement", attribute = "activePower", min = 5, max = 3600, change = 1, }, { cluster = "haElectricalMeasurement", attribute = "rmsVoltage", min = 5, max = 3600, change = 5, }, { cluster = "haElectricalMeasurement", attribute = "rmsCurrent", min = 5, max = 3600, change = 100, }, }, } device.fingerprint = { { model = "TS0601", manufacturer = "_TZE200_gbagoilo", }, { model = "TS0601", manufacturer = "_TZE284_xnwxmj8z", }, } return device