[OBSOLETE] Xiaomi Zigbee Smart Outlet device handler

Heya All!

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.

So my first challenge was to make @ArstenA’s DTH for the Xiaomi Zigbee outlets work with the newer ST App and groovy code (Thanks for the previous work @ArstenA! ).

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/AR), but it should also work with ZNCZ04LM (EU), ZNCZ03LM (TAIWAN), ZNCZ12LM (US), QBCZ11LM (CN/AR), SP-EUC01 (EU). (If someone can test it and let me know how it goes it would be awesome :slight_smile:)


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.7.2 (Aug 8, 2021)

Changelog:

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

Update 1.7 (Aug 5, 2021):

  • Enhance experimental support for SP-EUC01
  • Add experimental support for cluster 0B04 (Power)
  • fixed cluster 0702 definition (was energy, not power)
  • changed code to reflect native zigbee.x methods for power/energy (clusters 0B04 and 0702)
  • 1.7.1 update: mixed 0B04 with 0702 due to bad documentation from smartthings
  • 1.7.2 update: removed local execution flags, as they are known to provoke issues in custom DTHs.

Screenshots:


Device Handler Code: Xioami Zigbee Smart Outlet DTH :

https://raw.githubusercontent.com/cristianhares/smartthings/main/devicetypes/chares/xiaomi-zigbee-smart-outlet.src/xiaomi-zigbee-smart-outlet.groovy

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 :slight_smile:

If you like it and/or find it useful, and If you can of course, get me a coffee so I can keep programming :smiley: : Ko-Fi / Buymeacoffee

3 Likes

Thanks for the great work I just recall though xiaomi outlet is not well known for being a good zigbee repeater is that still an issue ? I still have an unused xiaomi outlet and eager to try if it works well as a repeater

1 Like

Heya,

I’ve got 3 of them, and until now I haven’t seen any issues (I was using bspranger’s one), most of my zigbee devices are SmartThings, a few heiman (owon), and some xiaomi’s.

I’ve heard of the same comment, but at least in my case haven’t seen any problems (yet). I wonder what kind of behavior would be seen as an unstable zigbee network.

Edit: just seen the previous comment, so it happens when one repeats another, interesting, at least 1 of mine is repeating another, and haven’t seen that kind of problems (yet).

UPDATE: I’ve also updated the code, as the data type for the report config interval was wrong (its a Float4 for power/energy, and INT16 for temp).

That sounds promising I will try later even I got 2 ST outlet already

1 Like

Just updated it to v1.2, Here’s the changelog:

  • 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

As I added an extra setting to that anyone can set the refresh interval for data polling just in case a zigbee message is not sent, you may need to clear the App cache before reopening the app after updating the handler.

I’ve also added LOTS of learned lessons and details, behaviour lessons, etc. in the comments :smiley:

Enjoy :slight_smile:

Updated it to V1.3 :slight_smile:

  • Removed method for custom on/off (unused)
  • 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)

FYI All,

I’ve been working for days+hours on V1.4, asides from some fixes (like temperature offset working properly) I’ve tackled the ugly 0xFF01/0xFF02 Xiaomi’s custom reported multi-value attribute logic in SmartThings (I’ve now got power/energy/temperature/state/NWK/RSSI/LQI on xiaomi-speak working right now).

As soon as I figure out why the sendEvent is not triggering for the reported values (got an idea why) I’ll upload the new version :slight_smile:

Now to get some hours of sleep :stuck_out_tongue:

v1.4 released! Enjoy :slight_smile:

Note: It’s ironic that Xiaomi’s custom report attribute is a ‘fix’ for the fact that runEveryXXMinutes() doesn’t properly work.

FYI to all, talked to some of my contacts in Shenzhen and it appears that the ZNCZ02LM is no longer manufactured (in favor of the ZNCZ07 model, which is bluetooth). What you find in stock is what is out there right now.

Hi from Romania, can you help me please with a handler for Mi Smart Plug GMR4014GL? Regards, Stefan

I can see from China xiaomi web site the Bluetooth version of outlet is released together with a Bluetooth version of Windows door sensor with light sensor
Not sure if xaomi is moving away from zigbee

https://m.mi.com/commodity/detail/12777

https://m.mi.com/commodity/detail/12665

Hi Stefan, that’s basically the zncz04lm, try this handler from johnconstantelo :
https://raw.githubusercontent.com/jsconstantelos/SmartThings/master/devicetypes/jsconstantelos/my-xiaomi-zncz04lm-mini-home-smart-socket.src/my-xiaomi-zncz04lm-mini-home-smart-socket.groovy

@nychan I don’t fully believe so as they did add newer versions of the zncz04lm for the european market an other things, but yes they are focusing more and more on bluetooth mesh technology. I don’t blame them, the licensing and the technology is definitely cheaper and easier to understand-ish.

1 Like

Trank You Very Much. I tried the handler and the only thing that doesn’t work is Energy Consumption. On your handler doesn’t work energy consumption and temperature.

Mine’s not designed for your zncz04lm, as the zigbee clusters for the messages are different, the on/off most likely would work as it is standard (even the SmartThigns Zigbee generic one), and some other secondary functions might or might not, as Xiaomi has the problem of constantly breaking the standard.

1 Like

Realesed 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.

Enjoy :slight_smile:

2 Likes

I Finally got my hands on a Xiaomi Gateway 3 and found that the ZNCZ02LM has extra settings! (Now I need my CC debugger delivered to see if I can see the commands sent to the plug :stuck_out_tongue: ).

  • The obvious one: power outage memory.
  • turn off the led between 9PM to 9AM! (this is great, it was annoying me like crazy when close to it in the dark)
  • charging protection! (if power is less than 2W for 30m, turn off) (it seems its a zigbee command setting on its own and not a automation)
2 Likes

Hi there from Germany, I"m new to ST and just bought a V3. Now I also bought a simple Xiaomi Mi motion sensor, just to get started. However this is all extremely frustrating… I installed the device handle but then the problem began with pairing… there is just no way at all that I can get the sensor to pair with the ST V3…
Any ideas?
Thanks A LOT in advance!
BR, Wim

Hey and welcome,

There’s a dedicated forum thread for the Xiaomi motion sensor DTH, this one is for the smart outlet. (Have you checked the motion sensor is a zigbee one, and not a wifi/bluetooth one?)

Thanks for the link! And yes, it is a zigbee sensor, not wifi.
I will read the material and get back in case I have questions.

Thanks again!

Great work with the DTH but i have a question what might be the problem since i have SP-EUC01 model… pairing works without flaw, i can change the status of the outlet ON/OFF from the new ST app OK… only problem i seem to have is all power values and temp are always zero ?

I followed from Smartthings IDE live logging and there are no outlet related messages/reporting (tried also to change from outlet settings debug trace etc ON… no change)

I wonder did i forget something or there’s something weird going on with the DTH (yes from the change log its mentioned so far experimental support for SP-EUC01)… is there something i could do to help debug this problem ?