local device = {} device.model = "TS0601_din_3" device.vendor = "Tuya" device.description = "Zigbee DIN energy 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 = "energy", property = "energy", access = 1, unit = "kWh", description = "Sum of consumed energy", }, { type = "numeric", name = "produced_energy", property = "produced_energy", access = 1, unit = "kWh", description = "Sum of produced energy", }, { type = "numeric", name = "power", property = "power", access = 1, unit = "W", description = "Instantaneous measured power", }, { 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 = "enum", name = "fault", property = "fault", access = 1, description = "Fault status of the device (clear = nothing)", values = { "clear", "over_current_threshold", "over_power_threshold", "over_voltage threshold", "wrong_frequency_threshold" }, }, { type = "enum", name = "threshold_1", property = "threshold_1", access = 1, description = "State of threshold_1", values = { "not_set", "over_current_threshold", "over_voltage_threshold" }, }, { type = "binary", name = "threshold_1_protection", property = "threshold_1_protection", access = 1, value_on = "ON", value_off = "OFF", description = "OFF - alarm only, ON - relay will be off when threshold reached", }, { type = "numeric", name = "threshold_1_value", property = "threshold_1_value", access = 1, description = "Can be in Volt or Ampere depending on threshold setting. Setup the value on the device", }, { type = "enum", name = "threshold_2", property = "threshold_2", access = 1, description = "State of threshold_2", values = { "not_set", "over_current_threshold", "over_voltage_threshold" }, }, { type = "binary", name = "threshold_2_protection", property = "threshold_2_protection", access = 1, value_on = "ON", value_off = "OFF", description = "OFF - alarm only, ON - relay will be off when threshold reached", }, { type = "numeric", name = "threshold_2_value", property = "threshold_2_value", access = 1, description = "Setup value on the device", }, { type = "binary", name = "clear_fault", property = "clear_fault", access = 3, value_on = "ON", value_off = "OFF", description = "Turn ON to clear last the fault", }, { type = "text", name = "meter_id", property = "meter_id", access = 1, description = "Meter ID (ID of device)", }, } device.fromZigbee = { "metering", "electrical" } device.tuyaDatapoints = { { dp = 1, name = "energy", converter = "divideBy100" }, { dp = 2, name = "produced_energy", converter = "divideBy100" }, { dp = 10, name = "fault", converter = "lookup", lookup = { clear = 0, over_current_threshold = 1, over_power_threshold = 2, over_voltage_threshold = 4, wrong_frequency_threshold = 8 } }, { dp = 16, name = "state", converter = "onOff" }, { dp = 18, name = "meter_id", converter = "raw" }, { dp = 20, name = "clear_fault", converter = "onOff" }, } device.configure = { bind = { "seMetering", "haElectricalMeasurement" }, reporting = { { cluster = "seMetering", attribute = "currentSummDelivered", min = 5, max = 3600, change = 1, }, { 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_rhblgy0z", }, { model = "TS0601", manufacturer = "_TZE204_rhblgy0z", }, } return device