Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.08k stars 1.68k forks source link

Request support Aqara ZNCZ15LM #8014

Closed z-x-f closed 3 years ago

z-x-f commented 3 years ago

Information about the device + link

Aqara smart plug (ZNCZ15LM; lumi.plug.macn01)

It has 3 parameters for customization:

Maximum Power (100-2500w) Power-off memory (on off) Turn off indicator light (on off)

https://www.aqara.com/cn/productDetail/d37 zncz15ml

data/database.db entry of the device

{"id":4,"type":"Router","ieeeAddr":"0x04cf8cdf3c82f5fe","nwkAddr":54031,"manufId":4447,"manufName":"LUMI","powerSource":"Mains (single phase)","modelId":"lumi.plug.macn01","epList":[1,242],"endpoints":{"1":{"profId":260,"epId":1,"devId":81,"inClusterList":[0,2,3,4,5,6,9,1794,2820],"outClusterList":[10,25],"clusters":{"genBasic":{"attributes":{"modelId":"lumi.plug.macn01","manufacturerName":"LUMI","powerSource":1,"zclVersion":3,"appVersion":31,"stackVersion":2,"hwVersion":1,"dateCode":"05-12-2020"}}},"binds":[{"cluster":6,"type":"endpoint","deviceIeeeAddress":"0x00124b00237b9e60","endpointID":1}],"configuredReportings":[{"cluster":6,"attrId":0,"minRepIntval":0,"maxRepIntval":3600,"repChange":0}],"meta":{}},"242":{"profId":41440,"epId":242,"devId":97,"inClusterList":[],"outClusterList":[33],"clusters":{},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":31,"stackVersion":2,"hwVersion":1,"dateCode":"05-12-2020","zclVersion":3,"interviewCompleted":true,"meta":{"configured":1466202208},"lastSeen":1625976508209}

Zigbee2mqtt pairing log

info Device '0x04cf8cdf3c82f5fe' joined
Info MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x04cf8cdf3c82f5fe","ieee_address":"0x04cf8cdf3c82f5fe"},"type":"device_joined"}'
Info Starting interview of '0x04cf8cdf3c82f5fe'
Info MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x04cf8cdf3c82f5fe","ieee_address":"0x04cf8cdf3c82f5fe","status":"started"},"type":"device_interview"}'
Debug Device '0x04cf8cdf3c82f5fe' announced itself
Info MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x04cf8cdf3c82f5fe","ieee_address":"0x04cf8cdf3c82f5fe"},"type":"device_announce"}'
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"modelId":"lumi.plug.macn01"}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"manufacturerName":"LUMI"}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"powerSource":1}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"zclVersion":3}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"appVersion":31}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"stackVersion":2}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"hwVersion":1}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{"dateCode":"05-12-2020"}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'readResponse', cluster 'genBasic', data '{}' from endpoint 1 with groupID 0
Debug Skipping message, definition is undefined and still interviewing
Info Successfully interviewed '0x04cf8cdf3c82f5fe', device has successfully been paired
Warning Device '0x04cf8cdf3c82f5fe' with Zigbee model 'lumi.plug.macn01' and manufacturer name 'LUMI' is NOT supported, please follow https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html
Info MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":null,"friendly_name":"0x04cf8cdf3c82f5fe","ieee_address":"0x04cf8cdf3c82f5fe","status":"successful","supported":false},"type":"device_interview"}'
Debug Received Zigbee message from '0x04cf8cdf3c82f5fe', type 'commandQueryNextImageRequest', cluster 'genOta', data '{"fieldControl":0,"fileVersion":31,"imageType":12,"manufacturerCode":4447}' from endpoint 1 with groupID 0
Warning Received message from unsupported device with Zigbee model 'lumi.plug.macn01' and manufacturer name 'LUMI'
Warning Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html.
Dump zigbee-packets with ZBOSS Sniffer and Wireshark [ZNCZ15LM.zip](https://github.com/Koenkk/zigbee2mqtt/files/6796582/ZNCZ15ML.zip) - encrypted pcapng-dump (Network Key for decryption entries: 23ec08029d40285b60f0912683cff67b) Recorded events in the dump: * device pairing * Report Plug in electrical appliances = true - Frame: 101 * Report Power - Frame: 113 * changing device settings * Turn on - Frame: 106 * Change Maximum Power = 2500W - Frame: 132 * Enable Power-off memory = true - Frame: 149 * Turn off indicator light = false - Frame: 163 Environment: * Plug Firmware Version: 0.0.0_0031 * Aqara Hub G3 (ZNSXJ13LM) Firmware Version: 3.27_0019.0004 * Aqara Home APP Version: 2.3.12
z-x-f commented 3 years ago

I tried the tutorial How to support new devices. But no useful logs are reported in the debug log.

z-x-f commented 3 years ago

Please help me.. @Koenkk

Koenkk commented 3 years ago

With the following external converter you should get power reading and be able to turn it on/off

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    zigbeeModel: ['lumi.plug.macn01'],
    model: 'ZNCZ15LM',
    vendor: 'Xiaomi',
    description: 'Aqara T1 plug',
    fromZigbee: [fz.on_off, fz.xiaomi_power, fz.xiaomi_switch_opple_basic],
    toZigbee: [tz.on_off, tz.xiaomi_power],
    exposes: [
        e.switch(), e.power().withAccess(ea.STATE_GET), e.energy(), e.temperature().withAccess(ea.STATE),
        e.voltage().withAccess(ea.STATE), e.current()],
};

module.exports = definition;

For other features like disabling led and power outage memory please provide a sniff when pairing this device with the Xiaomi gateway and enabling these features: https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html

z-x-f commented 3 years ago

Thanks for your help. on/off is work well. power can't get log:

Debug Received MQTT message on 'zigbee2mqtt/ZNCZ15LM/get' with data '{"power":""}'
Debug Publishing get 'get' 'power' to 'ZNCZ15LM'
Error Publish 'get' 'power' to 'ZNCZ15LM' failed: 'TypeError: Cannot read property 'read' of undefined'
Debug TypeError: Cannot read property 'read' of undefined at Object.convertGet (/opt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/converters/toZigbee.js:1727:28) at EntityPublish.onMQTTMessage (/opt/zigbee2mqtt/lib/extension/publish.js:276:37) at Controller.callExtensionMethod (/opt/zigbee2mqtt/lib/controller.js:397:44) at process._tickCallback (internal/process/next_tick.js:68:7)
Debug Received Zigbee message from 'ZNCZ15LM', type 'attributeReport', cluster 'seMetering', data '{"currentSummDelivered":[0,40]}' from endpoint 1 with groupID 0
Debug No converter available for 'ZNCZ15LM' with cluster 'seMetering' and type 'attributeReport' and data '{"currentSummDelivered":[0,40]}'
Debug Received Zigbee message from 'ZNCZ15LM', type 'attributeReport', cluster 'haElectricalMeasurement', data '{"activePower":43}' from endpoint 1 with groupID 0
Debug No converter available for 'ZNCZ15LM' with cluster 'haElectricalMeasurement' and type 'attributeReport' and data '{"activePower":43}'

I used device_tempure to get the temperature normally.

power outage memory used xiaomi_switch_power_outage_memory is work fine.

disabing led can't work.

The sniffed packet is already provided above.

Thanks again!

z-x-f commented 3 years ago
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    zigbeeModel: ['lumi.plug.macn01'],
    model: 'ZNCZ15LM',
    vendor: 'Xiaomi',
    description: 'Aqara T1 power plug',
    fromZigbee: [fz.on_off, fz.xiaomi_power, fz.xiaomi_switch_opple_basic],
    toZigbee: [tz.on_off, tz.xiaomi_power, tz.xiaomi_switch_power_outage_memory, tz.xiaomi_led_disabled_night],
    exposes: [e.switch(), e.power().withAccess(ea.STATE_GET), e.energy(), e.temperature().withAccess(ea.STATE), e.voltage().withAccess(ea.STATE), e.current(), e.consumer_connected().withAccess(ea.STATE), e.power_outage_memory(), e.led_disabled_night().withAccess(ea.STATE_SET),],
    configure: async (device, coordinatorEndpoint, logger) => {
        await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f});
        },
};

module.exports = definition;

The above code, most of the functions are normal, but power can only wait for the report to be updated, and the active acquisition will report an error :

Debug Received MQTT message on 'zigbee2mqtt/ZNCZ15LM/get' with data '{"power":""}'
Debug Publishing get 'get' 'power' to 'ZNCZ15LM'
Error Publish 'get' 'power' to 'ZNCZ15LM' failed: 'TypeError: Cannot read property 'read' of undefined'
Debug TypeError: Cannot read property 'read' of undefined at Object.convertGet (/opt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/converters/toZigbee.js:1727:28) at EntityPublish.onMQTTMessage (/opt/zigbee2mqtt/lib/extension/publish.js:276:37) at Controller.callExtensionMethod (/opt/zigbee2mqtt/lib/controller.js:397:44) at process._tickCallback (internal/process/next_tick.js:68:7)

Can you help me fix this error?

Koenkk commented 3 years ago
Screenshot 2021-07-20 at 21 51 42
z-x-f commented 3 years ago
Koenkk commented 3 years ago

UPDATE : When I delete this one and restart zigbee2mqtt, it still runs very well. I don’t understand why. When I didn’t add it at the beginning, most of the status of my device could not be obtained normally. After I added it, most of the status became normal. Now I delete it and it still works well.

You will need to try after factor resetting the device.

I can't read of the genAnalogInput attribute presentValue via the frontend, this will return an error:

Looks that reading power is not supported then.

Once you are done please create a pull request.

z-x-f commented 3 years ago

Wow, when I re-pair the device, if there is no await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f}), then many states cannot be read, and then I re-add await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f}) and re-pair the device, many states can be displayed normally, but every time zigbee2mqtt is restarted, an error will be reported 3 times :

error 2021-07-22 01:26:41: Failed to configure '0x04cf8cdf3c82f5fe', attempt 1 (Error: Write 0x04cf8cdf3c82f5fe/1 aqaraOpple({"mode":1}, {"sendWhenActive":false,"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Timeout - 8273 - 1 - 13 - 64704 - 4 after 10000ms)
    at Timeout.waiter.timer.setTimeout [as _onTimeout] (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/dist/utils/waitress.js:37:35)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10))
error 2021-07-22 01:27:04: Failed to configure '0x04cf8cdf3c82f5fe', attempt 2 (Error: Write 0x04cf8cdf3c82f5fe/1 aqaraOpple({"mode":1}, {"sendWhenActive":false,"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Timeout - 8273 - 1 - 14 - 64704 - 4 after 10000ms)
    at Timeout.waiter.timer.setTimeout [as _onTimeout] (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/dist/utils/waitress.js:37:35)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10))
error 2021-07-22 01:27:28: Failed to configure '0x04cf8cdf3c82f5fe', attempt 3 (Error: Write 0x04cf8cdf3c82f5fe/1 aqaraOpple({"mode":1}, {"sendWhenActive":false,"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":4447,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Timeout - 8273 - 1 - 20 - 64704 - 4 after 10000ms)
    at Timeout.waiter.timer.setTimeout [as _onTimeout] (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/dist/utils/waitress.js:37:35)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10))

PS: Sorry for my bad English, translated from Google.

Koenkk commented 3 years ago

Try changing to await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f, disableResponse: true})