From b241a2285dbdbb3fad9abb9170183f905c0b8142 Mon Sep 17 00:00:00 2001 From: Ilya Kirov Date: Thu, 18 Jan 2024 20:46:09 +0300 Subject: [PATCH 1/4] Aqara wall outlet H2 --- src/devices/xiaomi.ts | 43 ++++++++++++++++++++++++++++-- src/lib/xiaomi.ts | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/devices/xiaomi.ts b/src/devices/xiaomi.ts index c41a5e77f2801..57f3243b1d323 100644 --- a/src/devices/xiaomi.ts +++ b/src/devices/xiaomi.ts @@ -8,7 +8,7 @@ import extend from '../lib/extend'; import { light, numeric, binary, enumLookup, forceDeviceType, temperature, humidity, forcePowerSource, quirkAddEndpointCluster, - quirkCheckinInterval, + quirkCheckinInterval, onOff, } from '../lib/modernExtend'; const e = exposes.presets; const ea = exposes.access; @@ -17,7 +17,8 @@ import * as xiaomi from '../lib/xiaomi'; const { xiaomiAction, xiaomiOperationMode, xiaomiPowerOnBehavior, xiaomiZigbeeOTA, xiaomiSwitchType, aqaraAirQuality, aqaraVoc, aqaraDisplayUnit, xiaomiLight, - xiaomiOutageCountRestoreBindReporting, + xiaomiOutageCountRestoreBindReporting, xiaomiElectricityMeter, xiaomiPower, + xiaomiOverloadProtection, xiaomiDoNotDisturb, xiaomiButtonLock, } = xiaomi.modernExtend; import * as utils from '../lib/utils'; import {Definition, OnEvent, Fz, KeyValue, Tz} from '../lib/types'; @@ -3435,6 +3436,44 @@ const definitions: Definition[] = [ }, extend: [xiaomiZigbeeOTA()], }, + { + zigbeeModel: ['lumi.plug.aeu001'], + model: 'WP-P01D', + vendor: 'Aqara', + description: 'Aqara wall outlet H2', + extend: [ + xiaomiZigbeeOTA(), + onOff({powerOnBehavior: false}), + xiaomiPowerOnBehavior(), + xiaomiPower(), + xiaomiElectricityMeter(), + xiaomiOverloadProtection(), + xiaomiDoNotDisturb(), + xiaomiButtonLock(), + binary({ + name: 'charging_protection', + cluster: 'aqaraOpple', + attribute: {ID: 0x0202, type: 0x10}, + valueOn: ['ON', 1], + valueOff: ['OFF', 0], + description: 'Turn off the outlet if the power is below the set limit for half an hour', + access: 'ALL', + zigbeeCommandOptions: {manufacturerCode}, + }), + numeric({ + name: 'charging_limit', + cluster: 'aqaraOpple', + attribute: {ID: 0x0206, type: 0x39}, + valueMin: 0.1, + valueMax: 2, + valueStep: 0.1, + unit: "W", + description: 'Charging protection power limit', + access: 'ALL', + zigbeeCommandOptions: {manufacturerCode}, + }), + ], + }, ]; export default definitions; diff --git a/src/lib/xiaomi.ts b/src/lib/xiaomi.ts index 61ba6b76458d9..2ff7f30cc4c51 100644 --- a/src/lib/xiaomi.ts +++ b/src/lib/xiaomi.ts @@ -1468,6 +1468,68 @@ export const xiaomiModernExtend = { result.ota = ota.zigbeeOTA; return result; }, + xiaomiPower: (args?: Partial) => modernExtend.numeric({ + name: 'power', + cluster: 'genAnalogInput', + attribute: 'presentValue', + reporting: {min: '10_SECONDS', max: '1_HOUR', change: 5}, + description: 'Instantaneous measured power', + unit: 'W', + access: 'STATE', + zigbeeCommandOptions: {manufacturerCode}, + ...args, + }), + xiaomiElectricityMeter: (): ModernExtend => { + const exposes = [ + e.energy(), + e.voltage(), + e.current(), + e.device_temperature(), + ]; + const fromZigbee: Fz.Converter[] = [{ + cluster: 'aqaraOpple', + type: ['attributeReport', 'readResponse'], + convert: async (model, msg, publish, options, meta) => { + return await numericAttributes2Payload(msg, meta, model, options, msg.data); + }, + }]; + + return {exposes, fromZigbee, isModernExtend: true}; + }, + xiaomiOverloadProtection: (args?: Partial) => modernExtend.numeric({ + name: 'overload_protection', + cluster: 'aqaraOpple', + attribute: {ID: 0x020b, type: 0x39}, + description: 'Maximum allowed load, turns off if exceeded', + valueMin: 100, + valueMax: 3840, + unit: 'W', + access: 'ALL', + zigbeeCommandOptions: {manufacturerCode}, + ...args, + }), + xiaomiDoNotDisturb: (args? :Partial) => modernExtend.binary({ + name: 'do_not_disturb', + cluster: 'aqaraOpple', + attribute: {ID: 0x0203, type: 0x10}, + valueOn: ['ON', 0], + valueOff: ['OFF', 1], + description: 'Do not disturb mode, when enabled this function will keep the light OFF after a power outage', + access: 'ALL', + zigbeeCommandOptions: {manufacturerCode}, + ...args, + }), + xiaomiButtonLock: (args? :Partial) => modernExtend.binary({ + name: 'button_lock', + cluster: 'aqaraOpple', + attribute: {ID: 0x0200, type: 0x20}, + valueOn: ['ON', 0], + valueOff: ['OFF', 1], + description: 'Disables the physical switch button', + access: 'ALL', + zigbeeCommandOptions: {manufacturerCode}, + ...args, + }), }; export {xiaomiModernExtend as modernExtend}; From 6f52054cd869e6046c066345a6d689b0c4be6fcf Mon Sep 17 00:00:00 2001 From: Ilya Kirov Date: Thu, 18 Jan 2024 20:49:26 +0300 Subject: [PATCH 2/4] lint --- src/devices/xiaomi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/xiaomi.ts b/src/devices/xiaomi.ts index 57f3243b1d323..d3788fc42cdce 100644 --- a/src/devices/xiaomi.ts +++ b/src/devices/xiaomi.ts @@ -3467,7 +3467,7 @@ const definitions: Definition[] = [ valueMin: 0.1, valueMax: 2, valueStep: 0.1, - unit: "W", + unit: 'W', description: 'Charging protection power limit', access: 'ALL', zigbeeCommandOptions: {manufacturerCode}, From 5a94b2d2f395e36a43629c301bfdcbf506161f44 Mon Sep 17 00:00:00 2001 From: Ilya Kirov Date: Fri, 19 Jan 2024 09:06:54 +0300 Subject: [PATCH 3/4] fix description --- src/lib/xiaomi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/xiaomi.ts b/src/lib/xiaomi.ts index 2ff7f30cc4c51..8583de041ac1f 100644 --- a/src/lib/xiaomi.ts +++ b/src/lib/xiaomi.ts @@ -1514,7 +1514,7 @@ export const xiaomiModernExtend = { attribute: {ID: 0x0203, type: 0x10}, valueOn: ['ON', 0], valueOff: ['OFF', 1], - description: 'Do not disturb mode, when enabled this function will keep the light OFF after a power outage', + description: 'Do not disturb mode. Disabling built-in indicator', access: 'ALL', zigbeeCommandOptions: {manufacturerCode}, ...args, From 6edca6ccfd81acb49c74b499d257a552524245d8 Mon Sep 17 00:00:00 2001 From: Ilya Kirov Date: Sat, 20 Jan 2024 09:34:35 +0300 Subject: [PATCH 4/4] Rename --- src/devices/xiaomi.ts | 4 ++-- src/lib/xiaomi.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/devices/xiaomi.ts b/src/devices/xiaomi.ts index d3788fc42cdce..30047192df7d2 100644 --- a/src/devices/xiaomi.ts +++ b/src/devices/xiaomi.ts @@ -18,7 +18,7 @@ const { xiaomiAction, xiaomiOperationMode, xiaomiPowerOnBehavior, xiaomiZigbeeOTA, xiaomiSwitchType, aqaraAirQuality, aqaraVoc, aqaraDisplayUnit, xiaomiLight, xiaomiOutageCountRestoreBindReporting, xiaomiElectricityMeter, xiaomiPower, - xiaomiOverloadProtection, xiaomiDoNotDisturb, xiaomiButtonLock, + xiaomiOverloadProtection, xiaomiLedIndicator, xiaomiButtonLock, } = xiaomi.modernExtend; import * as utils from '../lib/utils'; import {Definition, OnEvent, Fz, KeyValue, Tz} from '../lib/types'; @@ -3448,7 +3448,7 @@ const definitions: Definition[] = [ xiaomiPower(), xiaomiElectricityMeter(), xiaomiOverloadProtection(), - xiaomiDoNotDisturb(), + xiaomiLedIndicator(), xiaomiButtonLock(), binary({ name: 'charging_protection', diff --git a/src/lib/xiaomi.ts b/src/lib/xiaomi.ts index 8583de041ac1f..a150c33e072c4 100644 --- a/src/lib/xiaomi.ts +++ b/src/lib/xiaomi.ts @@ -1508,13 +1508,13 @@ export const xiaomiModernExtend = { zigbeeCommandOptions: {manufacturerCode}, ...args, }), - xiaomiDoNotDisturb: (args? :Partial) => modernExtend.binary({ - name: 'do_not_disturb', + xiaomiLedIndicator: (args? :Partial) => modernExtend.binary({ + name: 'led_indicator', cluster: 'aqaraOpple', attribute: {ID: 0x0203, type: 0x10}, - valueOn: ['ON', 0], - valueOff: ['OFF', 1], - description: 'Do not disturb mode. Disabling built-in indicator', + valueOn: ['ON', 1], + valueOff: ['OFF', 0], + description: 'LED indicator', access: 'ALL', zigbeeCommandOptions: {manufacturerCode}, ...args,