Xiaomi Mi Smart Plug (New Model) Device Handler

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

1 Like

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:

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:

https://zigbeealliance.org/

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:

https://zigate.fr/le-materiel-compatible-zigate/ (be sure to translate from French). This is a good site for seeing what they documented for clusters and attributes.

https://zigbee.blakadder.com/all.html 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 https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Xiaomi-manufacturer-specific-clusters,-attributes-and-attribute-reporting 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?

It works with the new Smartthings app.

Regarding history, I’m not sure if this is what you mean but I can see historical power readings in the “History” tab for the device:

I can also see it as a graph on the “Controls” tab.