I’ve been using some holiday time to get up to speed on how exactly SmartThings works with groovy more in depth, and specially the Zigbee protocol.
This took me into a heavy journey of reading the ZCL standard, the ST groovy docs, groovy, and re-visiting java and data types.
The Device handler is now written in the latest Zigbee groovy code (zigbee.something()), and I heavily commented it for anyone to understand how a Zigbee device handler works, and other things. Also removed most of the debugs, added some info events, and removed the tiles code, which is no longer needed in the new app.
TL;DR: It now fully works under the new App, Temperature works (measurements are ugly, has an offset setting), Power works, Energy usage works.
Edited Note: DTH not only works with ZNCZ02LM (CN/AU/NZ/AR), but it should also work with ZNCZ04LM (EU), ZNCZ03LM (TAIWAN), ZNCZ12LM (US). (If someone can test it and let me know how it goes it would be awesome )
Notes for ZNCZ02LM:
- Setting the power outage memory can be achieved by getting a Xiaomi gateway v3, setting it in mainland china, adding the outlet, saetting the power outage memory, and re-adding it to SmartThings. (SmartThings doesn’t like Zigbee DataTypes that are of variable length (STRING_OCTET), so I’m still having issues parsing the value needed to set it properly, so I’m waiting for a CC2531 to see if I can sniff the command data, as I already know which attribute needs to be modified)
- I’ve managed to reset the kWh energy value in the zigbee attribute memory, but it seems the outlet keeps a separate memory that not even the xiaomi gateway is able to erase, so I haven’t found a way yet around the logic of it → this means the kWh reading will always show the max value ever registered.
Current Version: 1.5 (Feb 10, 2021)
V1.1 (Jan 10, 2021):
- Fix for correct encoding data type
V1.2 (Jan 12, 2021):
- Add health check capability
- more and more comments and learnings
- added data refresh poll setting
- added automatic data poll refresh every X minutes just in case some zigbee message is not reported even if set by configureReporting for any reason
- reorganized code structure so native/non-native methods are understood
Update 1.3 (Jan 15, 2021):
- Cleaned up code
- Removed method for custom on/off
- Changed logic order, and added ability to parse natively via zigbee.getEvent
- Added notes on how exactly Xiaomi does its Zigbee reports via a custom attribute ID which is 0xFF01 or 0xFF02, and how to understand them
- Modified value type from decimal to number for temperature offset, as it was breaking the reading to 0 degrees (not fully tested)
Update 1.4 (Jan 22, 2021):
- Enable/disable debug and trace as a setting of the device
- Cleared up attributions in comments
- Fixed missing import physicalgraph.zigbee.zcl.DataType to process DataType class
- Fixed logic around scheduled refreshes as per engineering comments sent by @nayeliz (doesnt work yet, seems like a SmartThings bug)
- Added the Xiaomi custom parsing for the reporting attribute FF01
- Reports now properly happen via Xiaomi’s custom report attribute (kWh, power usage, Temperature), even if runEveryXXMinutes() doesnt work.
- Default for temperature offset is now 6 degrees, as its the ‘sweet spot’ I seem to found with ZNCZ02LM.
Update 1.5 (Feb 10, 2021):
- Experimental support for ZNCZ04LM (EU), ZNCZ03LM (TAIWAN), ZNCZ12LM (US)
- more ST behaviour comments
- handle null in log.info on the updated() method
- change ping() behavior to do refresh()
- changed configure() behavior logic, and added multi-model support
- Added ‘missing features’ in the comments section.
Update 1.6 (Feb 22, 2021):
- Experimental support for QBCZ11LM, SP-EUC01
- Added more logic for the experimental models
- Added experimental version of the power outage memory setting (02 and 04 model)
- Reorganized code for better readability
- Added more comments
- Added extra missing logic for non 02 or 04 models
Device Handler Code: Xioami Zigbee Smart Outlet DTH :
How to install the device handler:
1.- go into the SmartThings Groovy IDE: SmartThings IDE
2.- go into the tab 'device handlers’
3.- Click on the upper right button '+ Create New Device Handler’
4.- Select the tab ‘From code’
5.- Copy the previous link’s code in there.
6.- Click on the ‘create’ button.
7.- on the upper right corner, click on the ‘save’ button, and then, click on the ‘publish’ button, and select ‘for me’
That’s it!, now adding the Xiaomi Zigbee Smart Outlet should be automatically recognized