zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Aqara Outlet H1 USB QBCZ15LM

Open z-x-f opened this issue 5 years ago β€’ 15 comments

Information about the device + link

https://www.aqara.com/cn/productDetail/smart-wall-outlet-h1-usb

data/database.db entry of the device

{"id":37,"type":"Router","ieeeAddr":"0x04cf8cdf3c87bf4d","nwkAddr":34978,"manufId":4447,"manufName":"LUMI","powerSource":"Mains (single phase)","modelId":"lumi.plug.sacn03","epList":[1,2,21,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.sacn03","manufacturerName":"LUMI","powerSource":1,"zclVersion":3,"appVersion":32,"stackVersion":2,"hwVersion":1,"dateCode":"06-22-2020"}},"genOnOff":{"attributes":{"245":117440520,"onOff":1}},"aqaraOpple":{"attributes":{"247":{"type":"Buffer","data":[100,16,1,101,16,0,3,40,32,152,57,0,0,0,0,149,57,14,46,53,53,150,57,232,231,20,69,151,57,0,0,0,0,5,33,2,0,154,32,0,8,33,32,1,9,33,0,7,11,32,0]},"513":1,"515":1,"523":100,"550":0}}},"binds":[],"configuredReportings":[],"meta":{}},"2":{"profId":260,"epId":2,"devId":81,"inClusterList":[6,0,3,4,5],"outClusterList":[],"clusters":{"genBasic":{"attributes":{}},"genOnOff":{"attributes":{"245":42508800,"onOff":0}}},"binds":[],"configuredReportings":[],"meta":{}},"21":{"epId":21,"inClusterList":[],"outClusterList":[],"clusters":{"genAnalogInput":{"attributes":{"presentValue":0}}},"binds":[],"configuredReportings":[],"meta":{}},"242":{"profId":41440,"epId":242,"devId":97,"inClusterList":[],"outClusterList":[33],"clusters":{},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":32,"stackVersion":2,"hwVersion":1,"dateCode":"06-22-2020","zclVersion":3,"interviewCompleted":true,"meta":{"configured":-31071145},"lastSeen":1628606053156}

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.sacn03'],
    model: 'QBCZ15LM',
    vendor: 'Xiaomi',
    description: 'Aqara H1 outlet ZigBee',
    fromZigbee: [fz.on_off, fz.xiaomi_power, fz.ZNCZ15LM_overload_protection, fz.QBCZ15LM_button_switch_config, fz.xiaomi_switch_opple_basic],
    toZigbee: [tz.on_off, tz.xiaomi_switch_power_outage_memory, tz.xiaomi_led_disabled_night, tz.QBCZ15LM_button_switch_config, tz.ZNCZ15LM_overload_protection],
    meta: {multiEndpoint: true},
    endpoint: () => {
        return {'relay': 1, 'usb': 2};
    },
    exposes: [
        e.switch().withEndpoint('relay'), e.switch().withEndpoint('usb'),
        e.power().withAccess(ea.STATE), e.energy(), e.temperature().withAccess(ea.STATE), e.voltage().withAccess(ea.STATE),
        e.current(),e.power_outage_memory(), e.led_disabled_night(),
        exposes.enum('button_switch_config', exposes.access.ALL, ['relay', 'relay&usb']),
        exposes.numeric('overload_protection', exposes.access.ALL).withValueMin(100).withValueMax(2200).withUnit('W')
            .withDescription('power off automatically if the maximum power is exceeded')],
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint1 = device.getEndpoint(1);
        await device.getEndpoint(1).write('aqaraOpple', {'mode': 1}, {manufacturerCode: 0x115f, disableResponse: true});
	},
};

module.exports = definition;

All functions are working. But the usb of this socket can be controlled separately, and its on/off is reported from endpoint2. I want to make a button controlled by usb alone. How can I do it? Thanks.

z-x-f avatar Aug 10 '21 14:08 z-x-f

I want to make a button controlled by usb alone. How can I do it?

I'm not sure what you mean, isn't that the e.switch().withEndpoint('usb')?

Koenkk avatar Aug 10 '21 17:08 Koenkk

@Koenkk This doesn't work, When I click on it, an error will be reported

Error Entity '0x04cf8cdf3c87bf4d/usb' is unknown

z-x-f avatar Aug 10 '21 23:08 z-x-f

@xfzha should work after adding usb to this list: https://github.com/Koenkk/zigbee2mqtt/blob/70891eec39018303a43349c875ad04d44b3b43cf/lib/util/utils.js#L34

Koenkk avatar Aug 11 '21 07:08 Koenkk

@Koenkk Yes, I have tried, add it after the 'relay', and then restart z2m, there are still errors.

z-x-f avatar Aug 11 '21 07:08 z-x-f

@xfzha what errors? can you provide the full debug log?

See https://www.zigbee2mqtt.io/information/debug.html on how to enable debug logging.

Koenkk avatar Aug 12 '21 15:08 Koenkk

@Koenkk I added 'usb' to the back of the 'relay',

const endpointNames = [
    'left', 'right', 'center', 'bottom_left', 'bottom_right', 'default',
    'top_left', 'top_right', 'white', 'rgb', 'cct', 'system', 'top', 'bottom', 'center_left', 'center_right',
    'ep1', 'ep2', 'row_1', 'row_2', 'row_3', 'row_4', 'relay', 'usb',
    'l1', 'l2', 'l3', 'l4', 'l5', 'l6', 'l7', 'l8',
    'l9', 'l10', 'l11', 'l12', 'l13', 'l14', 'l15', 'l16',
    'button_1', 'button_2', 'button_3', 'button_4', 'button_5',
    'button_6', 'button_7', 'button_8', 'button_9', 'button_10',
    'button_11', 'button_12', 'button_13', 'button_14', 'button_15',
    'button_16', 'button_17', 'button_18', 'button_19', 'button_20',
    'button_light', 'button_fan_high', 'button_fan_med', 'button_fan_low',
    'heat', 'cool', 'water', 'meter', 'wifi',
];

Then I click on/off Endpoint: usb state the debug log:

debug 2021-08-12 23:07:09: Received MQTT message on 'zigbee2mqtt/0x04cf8cdf3c87bf4d/usb/set' with data '{"state_usb":"ON"}'
info  2021-08-12 23:07:09: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":{"friendly_name":"0x04cf8cdf3c87bf4d/usb"},"type":"entity_not_found"}'
error 2021-08-12 23:07:09: Entity '0x04cf8cdf3c87bf4d/usb' is unknown

And when I turn on/off Endpoint: relay state the debug log:

debug 2021-08-12 23:13:17: Received MQTT message on 'zigbee2mqtt/0x04cf8cdf3c87bf4d/relay/set' with data '{"state_relay":"ON"}'
debug 2021-08-12 23:13:17: Publishing 'set' 'state' to '0x04cf8cdf3c87bf4d'
info  2021-08-12 23:13:17: MQTT publish: topic 'zigbee2mqtt/0x04cf8cdf3c87bf4d', payload '{"button_switch_config":"relay&usb","consumer_overload":100,"consumption":0,"current":0,"energy":0,"led_disabled_night":true,"linkquality":63,"overload_protection":100,"power":0,"power_outage_memory":false,"state":"ON","state_relay":"ON","state_usb":"OFF","temperature":29,"voltage":235.1}'
debug 2021-08-12 23:13:17: Received Zigbee message from '0x04cf8cdf3c87bf4d', type 'attributeReport', cluster 'genOnOff', data '{"245":117440554,"onOff":1}' from endpoint 1 with groupID 0
info  2021-08-12 23:13:17: MQTT publish: topic 'zigbee2mqtt/0x04cf8cdf3c87bf4d', payload '{"button_switch_config":"relay&usb","consumer_overload":100,"consumption":0,"current":0,"energy":0,"led_disabled_night":true,"linkquality":63,"overload_protection":100,"power":0,"power_outage_memory":false,"state":"ON","state_relay":"ON","state_usb":"OFF","temperature":29,"voltage":235.1}'

z-x-f avatar Aug 12 '21 15:08 z-x-f

Can you try sending either:

  • zigbee2mqtt/0x04cf8cdf3c87bf4d/usb/set {"state":"ON"}
  • zigbee2mqtt/0x04cf8cdf3c87bf4d/set {"state_usb":"ON"}

Koenkk avatar Aug 12 '21 15:08 Koenkk

zigbee2mqtt/0x04cf8cdf3c87bf4d/usb/set {"state":"ON"} the debug log:

debug 2021-08-12 23:45:05: Received MQTT message on 'zigbee2mqtt/0x04cf8cdf3c87bf4d/usb/set' with data '{"state":"ON"}'
info  2021-08-12 23:45:05: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":{"friendly_name":"0x04cf8cdf3c87bf4d/usb"},"type":"entity_not_found"}'
error 2021-08-12 23:45:05: Entity '0x04cf8cdf3c87bf4d/usb' is unknown

zigbee2mqtt/0x04cf8cdf3c87bf4d/set {"state_usb":"ON"} the debug log:

debug 2021-08-12 23:44:30: Received MQTT message on 'zigbee2mqtt/0x04cf8cdf3c87bf4d/set' with data '{"state_usb":"ON"}'
error 2021-08-12 23:44:30: No converter available for 'state_usb' (ON)

z-x-f avatar Aug 12 '21 15:08 z-x-f

Could it be that you only have endpoint 1 in your configure section?

I am not entirely sure what your config entries are actually doing?

@danieledwardgeorgehitchcock No, if I change the usb to the left right center, it can be on/off normally

z-x-f avatar Aug 13 '21 14:08 z-x-f

@xfzha ive tried to reproduce this but failed to do so, the following test passes fine: https://github.com/Koenkk/zigbee2mqtt/commit/19b5ecf61771f579b7850ff7efacc987791c1495 after changing https://github.com/Koenkk/zigbee-herdsman-converters/blob/5c0f0194d0ab27b22eebf4b31f9560da1e9f8588/devices/xiaomi.js#L430 to return {'system': 1, 'usb': 2, 'right': 3};

Koenkk avatar Aug 13 '21 17:08 Koenkk

@Koenkk It’s strange, I swapped the relay and usb, The relay controls the usb port, and the usb controls the relay port. Now the usb can be normally on/off by the relay, but the relay cannot be controlled by the usb. It seems that my 'usb' doesn’t work. I changed zigbee2mqtt/lib/util/utils.js, is this correct? Do I need to do anything else after editing?

UPDATE: I modified /opt/zigbee2mqtt/dist/util/utils.js and finally it can work normally.

z-x-f avatar Aug 14 '21 00:08 z-x-f

Ah you should indeed modify dist (if you modify lib you need to run npm run build afterwards).

Koenkk avatar Aug 14 '21 10:08 Koenkk

Ok, I will create a pull request later, adding 'usb' is also my create pr?

z-x-f avatar Aug 14 '21 11:08 z-x-f

no problem, assuming this can be closed now.

Koenkk avatar Aug 15 '21 18:08 Koenkk