Xiaomi Mi Smart Plug (New Model) Device Handler

Hi everyone!

Does anyone know if there is a device handler for the relatively new Xiaomi Outlet (Model ZNCZ04LM)? I just bought it to do automations based on the power consumption but the device handlers that I have found just work for switch control (i.e. basic on/off).

Would really appreciate someone pointing me in the right direction or adding support on one of the Xiaomi Device handlers that are already out there!

Thanks!

1 Like

What DTH have you tried already? Try these too:

SmartPower Outlet
ZigBee Switch Power

Thank you for your reply @johnconstantelo !

I have now tried the following:

I can control the switch with all of them but Iā€™m getting no power readings which is the only reason I bought this particular model. In fact, the switch is not intended to change at all. If I can only get power reading, that would be enough.

1 Like

Ok, letā€™s see if we can figure this out. Can you let me know what the deviceā€™s Raw Description and Data sections have in them? It should look similar to this format:

(your model should show as lumi.plug.mmeu01 I believe)

1 Like

Thatā€™s correct. Here they are:

Data

  • zigbeeNodeType: ROUTER
  • application: 16
  • endpointId: 01
  • manufacturer: LUMI
  • model: lumi.plug.mmeu01
  • divisor: 10

Raw Description
01 0104 0051 01 09 0000 0002 0003 0004 0005 0006 0009 0702 0B04 02 000A 0019

Cool, I have an idea for you to try, so give me a bit? Iā€™ve got got some things to do around the house first, but I think I can help.

Out of curiosity, after trying the Zigbee Switch Power or Zigbee Metering Plug, did you see how it looks in the Classic app? Sometimes changing handlers doesnā€™t always update in the new app until you force stop and clear cache.

Cool. Thank you so much for your help!

Yeah. The UI for the device changed in the Classic App immediately after changing handlers but it still read zero watts.

Ok, ready for some testing? Since I donā€™t have one of these, Iā€™ll rely on you for a lot of help.

Create your own DTH using this code:

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

Before using this, start Live Logging so we can catch any errors.

This should work in both apps. In the Classic app you will see more tiles than you will in the new app. Most notably will be Configure. Since thatā€™s not available in the new app, I created a preference/setting that does nothing but trip configure every time itā€™s toggled.

To be honest, Iā€™d prefer we test with the Classic app until weā€™re sure this is working, but Iā€™ll leave that decision up to you.

Once you edit your device to use this DTH, it should initiate configuration, so keep an eye on your live logs for all that, including any errors.

Iā€™ve included a lot of live logging events, so make sure to turn on/off the device, as well as tapping on the Refresh tile (or pull down in the new app). If you donā€™t see power reporting (watts), tap on the Configure, or if using the new app, go to device setting and toggle it once. Youā€™ll see those events in Live Logging, similar to this:

image

Can you give this DTH a try and let me know how it goes?

If energy doesnā€™t show up, donā€™t worry about that yet. This device reports energy usage over time since it first joined the hub. You canā€™t reset kWhā€™s without resetting the whole device and rejoining, so the reset tile does a virtual reset. If you look at your device details, you should see these states:

image

kwhTotal = usage during the lifespan of the device since it joined the hub
resetTotal = a saved value since the last virtual reset to calculate energy (kwhTotal - resetTotal = energy)

You might want to keep an eye on the ā€˜Power Consumption Reportā€™ capability to see where that is going.

Do you mean cluster 0702? If so, thatā€™s where kWh is coming from. These devices donā€™t have the ability to reset that value without excluding them from the hub. Just in case someone wanted to reset these monthly, or some other schedule, I did the virtual reset while still saving total lifespan kWh used. Hopefully when weā€™re able to have custom tiles in the new app, Iā€™ll include it. I probably could add it now so the Classic app show it. Thatā€™s pretty easy to do.

OK. Iā€™m not sure I understood absolutely everything in your instructions but here is what Iā€™ve got until now.

  • I added the device handler
  • I reconfigured the device to use it
  • I tried turning the plug on and off
  • I tried the Refresh button
  • I tried the Configure button
  • I tried the Reset kWh button

There were two warnings that came up (Iā€™ve tried to highlight them below) but Iā€™m not sure what caused them. Here are the logs:

c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:28: debug Resetting kWhā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:24: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:24: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:22: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:22: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:21: debug refreshCommands: [st rattr 0xB364 0x01 0x0006 0x0000, delay 2000, st rattr 0xB364 0x01 0x0B04 0x050B, delay 2000]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:21: debug Refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:21: debug Refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:11: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:11: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:11: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:11: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:45:07: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:43:22: debug eventDescMap is : [raw:B36401FCC082F700413D64100103281E9839C74B074095394206483E963900E00D45973921011541052106009A20000821160107270000000000000000092101020B20009B1001, dni:B364, endpoint:01, cluster:FCC0, size:130, attrId:00f7, result:success, encoding:41, value:01109b00200b02012109000000000000000027070116210800209a00062105411501213997450de00039963e480642399540074bc739981e28030110643d, isValidForDataType:true, clusterInt:64704, attrInt:247]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:43:22: **warn** Unhandled variable length attribute, assuming a single attribute.
c98dbcbe-8a7f-444e-8607-11e944ead487 22:43:22: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:43:22: **warn** Unhandled variable length attribute, assuming a single attribute.
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:41:31: debug Updated
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:24: debug eventDescMap is : [raw:B36415000C0E55003952B80640, dni:B364, endpoint:15, cluster:000C, size:14, attrId:0055, result:success, encoding:39, value:4006b852, isValidForDataType:true, clusterInt:12, attrInt:85]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:24: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:15: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 0A 01 00001001F5002371000007, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:0A, direction:01, attrId:0000, encoding:10, value:01, isValidForDataType:true, unparsedData:[F5, 00, 23, 71, 00, 00, 07], additionalAttrs:[[attrId:00f5, attrInt:245, encoding:23, value:07000071, isValidForDataType:true, consumedBytes:14]], data:[00, 00, 10, 01, F5, 00, 23, 71, 00, 00, 07], clusterInt:6, attrInt:0, commandInt:10]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:15: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:15: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 0B 01 0100, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:0B, direction:01, data:[01, 00], clusterInt:6, commandInt:11]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:15: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventDescMap is : [raw:B36415000C0E55003900000000, dni:B364, endpoint:15, cluster:000C, size:14, attrId:0055, result:success, encoding:39, value:00000000, isValidForDataType:true, clusterInt:12, attrInt:85]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventDescMap is : [raw:B36415000C0E55003900000000, dni:B364, endpoint:15, cluster:000C, size:14, attrId:0055, result:success, encoding:39, value:00000000, isValidForDataType:true, clusterInt:12, attrInt:85]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 0A 01 00001000F5002370000007, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:0A, direction:01, attrId:0000, encoding:10, value:00, isValidForDataType:true, unparsedData:[F5, 00, 23, 70, 00, 00, 07], additionalAttrs:[[attrId:00f5, attrInt:245, encoding:23, value:07000070, isValidForDataType:true, consumedBytes:14]], data:[00, 00, 10, 00, F5, 00, 23, 70, 00, 00, 07], clusterInt:6, attrInt:0, commandInt:10]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:39:07: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:32: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:32: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:31: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:31: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:29: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:28: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:27: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:38:24: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:36:23: debug eventDescMap is : [raw:B36401FCC082F700413D64100103281D983912830840953948C9473E963900E00D459739F7571641052106009A20000821160107270000000000000000092101020B20009B1001, dni:B364, endpoint:01, cluster:FCC0, size:130, attrId:00f7, result:success, encoding:41, value:01109b00200b02012109000000000000000027070116210800209a00062105411657f73997450de00039963e47c94839954008831239981d28030110643d, isValidForDataType:true, clusterInt:64704, attrInt:247]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:36:23: warn Unhandled variable length attribute, assuming a single attribute.
c98dbcbe-8a7f-444e-8607-11e944ead487 22:36:23: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:36:23: warn Unhandled variable length attribute, assuming a single attribute.
c98dbcbe-8a7f-444e-8607-11e944ead487 22:36:23: warn Unhandled variable length attribute, assuming a single attribute.
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:19: debug eventDescMap is : [raw:B364010B040C0B0500290000, dni:B364, endpoint:01, cluster:0B04, size:12, attrId:050b, result:success, encoding:29, value:0000, isValidForDataType:true, clusterInt:2820, attrInt:1291]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:19: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug eventDescMap is : [raw:0104 0006 01 01 0000 00 B364 00 00 0000 01 01 0000001001, profileId:0104, clusterId:0006, sourceEndpoint:01, destinationEndpoint:01, options:0000, messageType:00, dni:B364, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:01, direction:01, attrId:0000, resultCode:00, encoding:10, value:01, isValidForDataType:true, data:[00, 00, 00, 10, 01], clusterInt:6, attrInt:0, commandInt:1]
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug eventMap is : null
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug Updated
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦refreshing valuesā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦reporting intervalsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug ā€¦bindingsā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug configureHealthCheck
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug Configureā€¦
c98dbcbe-8a7f-444e-8607-11e944ead487 22:34:16: debug Installed

Finally, hereā€™s the screenshot of how it looks in the app

And the data on the IDE

That 1.93 kWh is from a previous attempt with another DTH. Power is still at 0W.

Let me know if youā€™re missing anything or if further testing is needed. Thank you!

No, I meant ST has a ā€˜Power Consumption Reportā€™ capability that might have potential for handling your kWh total and resetTotal in a standard fashion. You can only guess so much from the JSON though. Not something Iā€™ve looked into myself as I donā€™t have suitable devices.

{
    "id": "powerConsumptionReport",
    "version": 1,
    "status": "proposed",
    "name": "Power Consumption Report",
    "attributes": {
        "powerConsumption": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "title": "PowerConsumption",
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                            "start": {
                                "title": "Iso8601Date",
                                "type": "string",
                                "pattern": "^(?:[1-9]\\d{3}-?(?:(?:0[1-9]|1[0-2])-?(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-?(?:29|30)|(?:0[13578]|1[02])-?31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-?02-?29)T(?:[01]\\d|2[0-3]):?[0-5]\\d:?[0-5]\\d(?:\\.\\d{3})?(?:Z|[+-][01]\\d(?::?[0-5]\\d)?)$"
                            },
                            "end": {
                                "title": "Iso8601Date",
                                "type": "string",
                                "pattern": "^(?:[1-9]\\d{3}-?(?:(?:0[1-9]|1[0-2])-?(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-?(?:29|30)|(?:0[13578]|1[02])-?31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-?02-?29)T(?:[01]\\d|2[0-3]):?[0-5]\\d:?[0-5]\\d(?:\\.\\d{3})?(?:Z|[+-][01]\\d(?::?[0-5]\\d)?)$"
                            },
                            "energy": {
                                "type": "number"
                            },
                            "power": {
                                "type": "number"
                            },
                            "deltaEnergy": {
                                "type": "number"
                            },
                            "powerEnergy": {
                                "type": "number"
                            },
                            "energySaved": {
                                "type": "number"
                            },
                            "persistedEnergy": {
                                "type": "number"
                            }
                        }
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "enumCommands": []
        }
    },
    "commands": []
}
1 Like

Hmm, ok. It looks like the plug turned on/off based on what I see, is that right?

I was hoping I could easily repurpose another similar DTH I have for this device, but it doesnā€™t look like Iā€™ll be able to do that. This is turning out to be a lot more complicated than I expected since I donā€™t have a device to test with.

This is the power reporting cluster, and there are several showing up. Unfortunately the value is always 0000, as you can see in your live logs. Looks like we wonā€™t be able to use that for anything.

There are also 2 other clusters being used - FCC0 and 000C. 000C seems to have to do with power reporting, and FCC0 is a Xiaomi manufacturer specific cluster (source), which looks like thatā€™s where several attributes live:

I looked back at one DTH you tried:

https://raw.githubusercontent.com/bspranger/Xiaomi/master/devicetypes/bspranger/xiaomi-zigbee-outlet.src/xiaomi-zigbee-outlet.groovy

Did that one turn it on/off?

If so, lines 165 and 172 may just need to be tweaked to change the endpoint from 02 and 03, to what this plug sends. Can you try going back to that DTH and change line 165 so that the endpoint is 15 instead of 02 and change line 172 so that endpoint is 16 instead of 03.

It should look like this after those changes:

else if (descMap.cluster == "000C" && descMap.attrId == "0055" && descMap.endpoint == "15") {
	def wattage_int = Long.parseLong(descMap.value, 16)
	def wattage = Float.intBitsToFloat(wattage_int.intValue())
	wattage = Math.round(wattage * 10) * 0.1
	resultMap = createEvent(name: "power", value: wattage, unit: 'W')
	log.debug "${device.displayName}: Reported power use is ${wattage}W"
}
else if (descMap.cluster == "000C" && descMap.attrId == "0055" && descMap.endpoint == "16") {
	def energy_int = Long.parseLong(descMap.value, 16)
	def energy = Float.intBitsToFloat(energy_int.intValue())
	energy = Math.round(energy * 100) * 0.0001
	resultMap = createEvent(name: "energy", value: energy, unit: 'kWh')
	log.debug "${device.displayName}: Reported energy usage is ${energy}kWh"
}

Iā€™m thinking these simple changes may work for you. Can you try? My DTH is pretty much useless at this point.

If youā€™re curious, hereā€™s my source for that info and why I think that should work for you:

image

2 Likes

We have power!!! :grin: :grin: :grin:

I did the changes as you suggested. Now I have power showing and running on my automations:

I owed you some answers though:

Yes. Your DTH turned the plug on and off normally.

Yes. It also turns it on and off without a problem.

So this was the key to the whole thing. Changing the endpoint to 15 started reporting power. It also started reporting temperature for some reason (although I canā€™t remember if it already did before the edit and it reports 150Ā° without changing at all). Energy is still at 0 kWh but that is not really important for me at the moment. I basically just want to know i the device connected to the plug is turned on or not.

I only have one more question for you. What would I need to learn in order to figure out something like this on my own next time? I guess there are 2 things that are still unclear to me at this point:

  1. What do I need to learn in order to understand everything that the code inside of a DTH refers to and does?
  2. How did the people on the link you provided figure out what data comes from which endpoint? How do they map the data sources in a new device?

This part is just my curiosity so let me know if you know what I would need to learn.

Thank you so much for helping me out!!! You just taught me a lot and saved me from buying a new plug!

Outstanding! I was really hoping this would do the trick. Regarding energy, that may only report every few hours, but I also read in other communities where it doesnā€™t even send a value for some reason. I suspect it could just be a configuration issue. The DTH youā€™re using doesnā€™t have a configuration method, which means the device sends data based on factory default settings/configuration.

I started out with the same questions, and through looking at STā€™s documentation, their Github code, and other developer code, I learned how to tweak and then eventually develop my own. Iā€™ve done code development in the past, so that also helped.

In this scenario, the deviceā€™s ā€œfingerprintā€ matched most ā€œclustersā€ of ones that were already in stock handlers, so thatā€™s why I thought some of those would work for you. Once you provided the model, I did a search in Github for it, and found those links I provided above. There are a lot of home automation platforms out there, and a lot of info can be learned from Github besides just code.

There are also a few good Zigbee tools out there that pull all this info out of Zigbee devices (zwave too). I donā€™t have any because I can usually find what Iā€™m looking for on the Internet.

SmartThings has a few good sources for documentation. One of them is being replaced with newer documentation, but itā€™s still valid:

New:
https://smartthings.developer.samsung.com/docs/index.html

Classic: (itā€™s also the Documentation link you see in the IDE)
https://docs.smartthings.com/en/latest/
https://docs.smartthings.com/en/latest/ref-docs/zigbee-ref.html
https://docs.smartthings.com/en/latest/device-type-developers-guide/zigbee-primer.html
https://docs.smartthings.com/en/latest/device-type-developers-guide/building-zigbee-device-handlers.html
https://docs.smartthings.com/en/latest/device-type-developers-guide/zigbee-example.html

I also used the Zigbee spec to see how a device is using clusters and attributes, as well has how theyā€™re suppose to be used:

In your scenario, a manufacturer specific cluster is being used, so that wonā€™t be found in that spec. Youā€™ll need the manufacturerā€™s documentation, which is usually hard to find. That is where those sniffer tools come in handy, and why I keep an eye on those links I sent you. Here are those again, and 1 or 2 more:

Le matƩriel compatible ZiGate - ZiGate (be sure to translate from French). This is a good site for seeing what they documented for clusters and attributes.

Database of Zigbee devices compatible with ZHA, Tasmota, Zigbee2MQTT, deCONZ, ZiGate and ioBroker is also really good. If you find the device youā€™re trying to debug, I usually click on the ā€œConfirmed working with DECONZā€ link to find what Iā€™m looking for. Thatā€™s where I found Xiaomi manufacturer specific clusters, attributes and attribute reporting Ā· dresden-elektronik/deconz-rest-plugin Wiki Ā· GitHub a long time ago.

Great! Iā€™m always glad to help anyone in any way I can.

3 Likes

Thank you so much for taking the time to teach those of us who are just getting started! Youā€™re awesome man!

Iā€™ll get to reading the links right away!

1 Like

Hi
I also have this device. It seems like that, I can connect it to my system without a device handler. Nice :smile: Shows up i Smartthings after just a few seconds, when IĀ“m searching for new devices. I can turn it on/off and set timers. But I canĀ“t see power consumption :frowning: Is it possible in any way to edit the plugs connection to the system?
Thanks in advance

To get power consumption, youā€™ll need the device handler mentioned above and then make the same changes outlined in post #13. Xiaomi does not use the Zigbee spec ā€œclusterā€ for reporting power consumption, but their own manufacturer specific one, so you will need a custom handler if you want power reporting.

Thank you :blush:

1 Like

Does the device also work with the new Smartthings app? Does it register history or only current power usage?