diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index 9f9564e33f112..33a76f4ca7bef 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -4758,6 +4758,22 @@ const converters = { return payload; }, }, + tuya_switch_power_outage_memory: { + cluster: 'genOnOff', + type: ['attributeReport', 'readResponse'], + convert: (model, msg, publish, options, meta) => { + const property = 0x8002; + + if (msg.data.hasOwnProperty(property)) { + const dict = {0x00: 'off', 0x01: 'on', 0x02: 'restore'}; + const value = msg.data[property]; + + if (dict.hasOwnProperty(value)) { + return {[postfixWithEndpointName('power_outage_memory', msg, model)]: dict[value]}; + } + } + }, + }, // #endregion // #region Ignore converters (these message dont need parsing). diff --git a/converters/toZigbee.js b/converters/toZigbee.js index cd5d78177d71d..2279b5ee70095 100644 --- a/converters/toZigbee.js +++ b/converters/toZigbee.js @@ -4299,6 +4299,21 @@ const converters = { } }, }, + tuya_switch_power_outage_memory: { + key: ['power_outage_memory'], + convertSet: async (entity, key, value, meta) => { + const dict = {'off': 0x00, 'on': 0x01, 'restore': 0x02}; + value = value && value.toString().toLowerCase(); + + if (value && dict.hasOwnProperty(value) === false) { + throw new Error(`${value} not supported, supported values: 'on', 'off', 'restore'`); + } + + const payload = dict[value]; + await entity.write('genOnOff', {0x8002: {value: payload, type: 0x30}}); + return {state: {power_outage_memory: value}}; + }, + }, // Not a converter, can be used by tests to clear the store. __clearStore__: () => { diff --git a/devices.js b/devices.js index c0a40df5d6d9c..11ad8516ff754 100755 --- a/devices.js +++ b/devices.js @@ -1390,8 +1390,8 @@ const devices = [ description: '10A UK or 16A EU smart plug', whiteLabel: [{vendor: 'BlitzWolf', model: 'BW-SHP13'}], vendor: 'TuYa', - fromZigbee: [fz.on_off, fz.electrical_measurement, fz.metering, fz.ignore_basic_report], - toZigbee: [tz.on_off], + fromZigbee: [fz.on_off, fz.electrical_measurement, fz.metering, fz.ignore_basic_report, fz.tuya_switch_power_outage_memory], + toZigbee: [tz.on_off, tz.tuya_switch_power_outage_memory], meta: {configureKey: 1}, configure: async (device, coordinatorEndpoint) => { const endpoint = device.getEndpoint(1); @@ -1404,6 +1404,9 @@ const devices = [ }, // This device doesn't support reporting correctly. // https://github.com/Koenkk/zigbee-herdsman-converters/pull/1270 + exposes: [e.switch(), e.power(), e.current(), e.voltage(), e.energy(), + exposes.enum('power_outage_memory', exposes.access.STATE_SET, ['on', 'off', 'restore']) + .withDescription('Recover state after power outage')], onEvent: (type, data, device, options) => { const endpoint = device.getEndpoint(1); if (type === 'stop') { @@ -1418,7 +1421,6 @@ const devices = [ globalStore.putValue(device, 'interval', interval); } }, - exposes: [e.switch(), e.power(), e.current(), e.voltage(), e.energy()], }, { zigbeeModel: ['mcdj3aq', 'mcdj3aq\u0000'],