Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge πŸŒ‰, get rid of your proprietary Zigbee bridges πŸ”¨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.17k stars 1.68k forks source link

[New device support]: CK-BL702-SWP-01(7020) #19334

Closed sixhills closed 1 year ago

sixhills commented 1 year ago

Link

https://www.ebay.co.uk/itm/314855773062

Database entry

{"id":20,"type":"Router","ieeeAddr":"0x7cb94c7736db0000","nwkAddr":15251,"manufId":4742,"manufName":"eWeLink","powerSource":"Unknown","modelId":"CK-BL702-SWP-01(7020)","epList":[1,242],"endpoints":{"1":{"profId":260,"epId":1,"devId":9,"inClusterList":[0,3,4,5,6,4096,64599,64529],"outClusterList":[25,2820,10],"clusters":{"64529":{"attributes":{"28676":0,"28677":238803,"28678":0}},"genBasic":{"attributes":{"modelId":"CK-BL702-SWP-01(7020)","manufacturerName":"eWeLink","powerSource":0,"zclVersion":8,"appVersion":1,"stackVersion":0,"hwVersion":0,"dateCode":"20210610-BL","swBuildId":"1.0.1"}},"genOnOff":{"attributes":{"onOff":0}}},"binds":[{"cluster":6,"type":"endpoint","deviceIeeeAddress":"0x00124b00238dad65","endpointID":1},{"cluster":2820,"type":"endpoint","deviceIeeeAddress":"0x00124b00238dad65","endpointID":1}],"configuredReportings":[{"cluster":6,"attrId":0,"minRepIntval":0,"maxRepIntval":3600,"repChange":0,"manufacturerCode":null}],"meta":{}},"242":{"profId":41440,"epId":242,"devId":97,"inClusterList":[],"outClusterList":[33],"clusters":{},"binds":[],"configuredReportings":[],"meta":{}}},"appVersion":1,"stackVersion":0,"hwVersion":0,"dateCode":"20210610-BL","swBuildId":"1.0.1","zclVersion":8,"interviewCompleted":true,"meta":{"configured":1466202208},"lastSeen":1697636915231,"defaultSendRequestWhen":"immediate"}

Comments

This is a Woolley smart plug with energy monitoring.

I tried to follow the "Support new devices" page but I'm unsure how to specify the "fromZigbee" and "toZigbee" lists.

Can you please include this device?

External converter

// Incomplete attempt at an external converter
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: ['CK-BL702-SWP-01(7020)'],
    model: 'CK-BL702-SWP-01(7020)',
    vendor: 'eWeLink',
    description: 'BL702 Smart plug',
    fromZigbee: [fz.on_off, fz.command_on_state, fz.command_off_state, fz.electrical_measurement],
    toZigbee: [], // Should be empty, unless device can be controlled (e.g. lights, switches).
    exposes: [e.switch()],
    // The configure method below is needed to make the device reports on/off state changes
    // when the device is controlled manually through the button on it.
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
        await reporting.onOff(endpoint);
    },
};

module.exports = definition;

Supported color modes

No response

Color temperature range

No response

ELKER54 commented 1 year ago

I would love to have this device supported. I just got 3 of these and hope that they will work soon.

Axelf-alex commented 1 year ago

Yes please got 3 would like to get them working too, they are not much different from already supported one BSD29 @Koenkk can we get your expertise on this please would really appreciate it.

englishteeth commented 1 year ago

I've it running with a local external converter with the following definition, cribbed and copied from other devices, so no idea if it's the best way. I have been trying to work out the power management data before I even thought about a PR, but it might keep you going.

const definition = {
    zigbeeModel: ['CK-BL702-SWP-01(7020)'],
    model: 'BSD29',
    vendor: 'Wooley',
    description: 'Zigbee 3.0 smart plug 13A (UK version)',
    fromZigbee: [fz.on_off_skip_duplicate_transaction],
    toZigbee: [tz.on_off],
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
        await reporting.onOff(endpoint);
    },
    exposes: [e.switch()],
};
Koenkk commented 1 year ago

Could you check if the issue is fixed with the following external converter: https://gist.github.com/Koenkk/2414b6ba5f911f02a67c7bc07b2b6d81

Axelf-alex commented 1 year ago

I knew you would fix it straight away @Koenkk thank you so much absolute legend :) .

The only problem is I can only turn it on and off these ones have power monitoring function I don't know what to include in the config to enable this

image

Weirdly this device is CK-BL702-SWP-01(7020) but on the plug plastic and booklet mentions BSD29 lol So not quite the same I would say.

Any way around this?

Thank you so much once again

Koenkk commented 1 year ago

When in the frontend, you click on the device -> configure button (yellow refresh icon), does this succeed?

Axelf-alex commented 1 year ago

I have added it couple of times just in case pairing was a bit flaky but made no difference then pressed the yello "Reconfigure" made no difference again :( Got errors tho 1st Screenshot when added ---- 2nd Whne "Reconfigure" z image

sixhills commented 1 year ago

I've also tried the new external converter and I'm seeing the same effect as @Axelf-alex: pressing the yellow 'Reconfigure' button results in a timeout.

sixhills commented 1 year ago

I'm not sure if the following helps, but I recorded this in the log when first connecting the device using the eternal converter listed at the start of this thread: Oct 22 19:34:34 `Zigbee2MQTT:info 2023-10-22 19:34:34: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":{"description":"BL702 Smart plug",

"exposes":[{"features":[{"access":7,"description":"On/off state of the switch", "label":"State","name":"state","property":"state","type":"binary","value_off":"OFF","value_on":"ON","value_toggle":"TOGGLE"}], "type":"switch"},{"access":1,"description":"Sum of consumed energy", "label":"Energy","name":"energy","property":"energy","type":"numeric","unit":"kWh"}, {"access":1,"description":"Instantaneous measured power", "label":"Power","name":"power","property":"power","type":"numeric","unit":"W"}, {"access":1,"description":"Measured electrical potential value", "label":"Voltage","name":"voltage","property":"voltage","type":"numeric","unit":"V"}, {"access":1,"description":"Instantaneous measured electrical current", "label":"Current","name":"current","property":"current","type":"numeric","unit":"A"}, {"access":1,"description":"Link quality (signal strength)", "label":"Linkquality","name":"linkquality","property":"linkquality","type":"numeric","unit":"lqi","value_max":255,"value_min":0}], "model":"CK-BL702-SWP-01(7020)",

"options":[{"access":2,"description":"State actions will also be published as 'action' when true (default false).", "label":"State action","name":"state_action","property":"state_action","type":"binary","value_off":false,"value_on":true}, {"access":2,"description":"Calibrates the power value (percentual offset), takes into effect on next report of device.", "label":"Power calibration","name":"power_calibration","property":"power_calibration","type":"numeric"}, {"access":2,"description":"Number of digits after decimal point for power, takes into effect on next report of device.", "label":"Power precision","name":"power_precision","property":"power_precision","type":"numeric","value_max":3,"value_min":0}, {"access":2,"description":"Calibrates the current value (percentual offset), takes into effect on next report of device.","label":"Current calibration","name":"current_calibration","property":"current_calibration","type":"numeric"}, {"access":2,"description":"Number of digits after decimal point for current, takes into effect on next report of device.", "label":"Current precision","name":"current_precision","property":"current_precision","type":"numeric","value_max":3,"value_min":0}, {"access":2,"description":"Calibrates the voltage value (percentual offset), takes into effect on next report of device.", "label":"Voltage calibration","name":"voltage_calibration","property":"voltage_calibration","type":"numeric"}, {"access":2,"description":"Number of digits after decimal point for voltage, takes into effect on next report of device.", "label":"Voltage precision","name":"voltage_precision","property":"voltage_precision","type":"numeric","value_max":3,"value_min":0}, {"access":2,"description":"Number of digits after decimal point for energy, takes into effect on next report of device.", "label":"Energy precision","name":"energy_precision","property":"energy_precision","type":"numeric","value_max":3,"value_min":0}, {"access":2,"description":"Calibrates the energy value (percentual offset), takes into effect on next report of device.", "label":"Energy calibration","name":"energy_calibration","property":"energy_calibration","type":"numeric"}],"supports_ota":false,"vendor":"eWeLink"},

"friendly_name":"0x7cb94c77d5860000","ieee_address":"0x7cb94c77d5860000","status":"successful","supported":true}, "type":"device_interview"}' ... Oct 22 19:34:34 npm[17739]: Zigbee2MQTT:info 2023-10-22 19:34:34: Configuring '0x7cb94c77d5860000' Oct 22 19:34:34 npm[17739]: Zigbee2MQTT:info 2023-10-22 19:34:34: Successfully configured '0x7cb94c77d5860000'`

Axelf-alex commented 1 year ago

I tried to read and try to do things from the GUI of Z2m I noticed in the code there is

    const endpoint = device.getEndpoint(1);
    await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'haElectricalMeasurement']);
    await reporting.onOff(endpoint);
    await reporting.readEletricalMeasurementMultiplierDivisors(endpoint);
    await reporting.activePower(endpoint);
    await reporting.rmsVoltage(endpoint);
    await reporting.rmsCurrent(endpoint);

But nothing comes up automatically after adopting device I tried it manually its goes well until I get to the reporting part.

image

At the reporting part the readEletricalMeasurementMultiplierDivisors(endpoint) is missing also I tried the rmsVoltage and activePower and it fails

image

image

Any help as always would be greatly appreciated. @Koenkk I think if we fix the haElectricalMeasurement we might fix the reporting.

Thank you in advance for all the help and support :)

Koenkk commented 1 year ago

Can you try removing await reporting.rmsVoltage(endpoint);

sixhills commented 1 year ago

I've tried that and it no longer reports a failure to configure.

Clicking the "Reconfigure" button generates:

Oct 27 19:44:06 pi42 npm[10603]: Zigbee2MQTT:info 2023-10-27 19:44:06: MQTT publish: topic 'zigbee2mqtt/bridge/response/device/configure', payload '{"data":{"id":"WL1_plug"},"status":"ok","transaction":"ybk5z-3"}'

so that's welcome progress, but there's still no reporting of power, either in the log or on the dashboard.

Thanks for sticking with this - it's much appreciated.

dangnguyen0906 commented 1 year ago

i got the same issues of tracking power measuring . Please help to add this devices as supported in next version of z2m

Koenkk commented 1 year ago

Does something shows up in the frontend -> device -> reporting tab?

Axelf-alex commented 1 year ago

@Koenkk unfortunately nothing comes up image

sixhills commented 1 year ago

Just for info: for people struggling with this smart plug, I took a risk on very similar devices from Aliexpress: https://www.aliexpress.com/item/1005005362261536.html They arrived in the UK in 6 days and "just work" with Z2M. They identify as Tuya BSD29 devices and power monitoring works fine.

Koenkk commented 1 year ago

@Axelf-alex that indeed doesn't look good, based on what you provided in https://github.com/Koenkk/zigbee2mqtt/issues/19334#issuecomment-1781347783 (manually setting the reporting also fails), I guess the device doesn't support it or there is some non standard way of setting this up. To check both, you need the original hub and check if power measurements work there, if yes, you can sniff the traffic which reveals how to setup the reporting correctly.

Axelf-alex commented 1 year ago

@Koenkk Thank you so much for your help and support with this. I guess expensive e-waste then..!! πŸ˜‚ I guess if ZHA works with it can we not sniff the traffic from there? Will try couple of things and if I manage to find a solution will post here

sixhills commented 1 year ago

At least they can be used as MQTT-controlled switches, so not a total loss. I wondered whether to buy a Sonoff hub ( which it claims to work with) to investigate further, but it's probably not worth it when there are other power-monitoring plugs that work. My thanks also to @Koenkk for all his help.

englishteeth commented 1 year ago

Not fully investigated yet, but I was looking at the data for the unhandled messages and have this draft converter:

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 utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;

const fzLocal = {
    who_knows: {
        cluster: '64529',
        type: ['attributeReport', 'readResponse'],
        convert: (model, msg, publish, options, meta) => {
            if (utils.hasAlreadyProcessedMessage(msg, model)) return;
            const lookup = [
                {key: '28678', name: 'power', factor: 'acPower'},
                {key: '28677', name: 'voltage', factor: 'acVoltage'},
                {key: '28676', name: 'current', factor: 'acCurrent'},
            ];
            const payload = {};
            for (const entry of lookup) {
                if (msg.data.hasOwnProperty(entry.key)) {
                    const property = utils.postfixWithEndpointName(entry.name, msg, model, meta);
                    const value = msg.data[entry.key] / 1000;
                    payload[property] = utils.calibrateAndPrecisionRoundOptions(value, options, entry.name);
                }
            }
            return payload;
        },
    },
};

const definition = {
    zigbeeModel: ['CK-BL702-SWP-01(7020)'],
    model: 'BSD29',
    vendor: 'Woolley',
    description: 'Zigbee 3.0 smart plug 13A (UK version)',
    fromZigbee: [fz.on_off_skip_duplicate_transaction, fzLocal.who_knows],
    toZigbee: [tz.on_off],
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
        await reporting.onOff(endpoint);
        device.powerSource = 'Mains (single phase)';
        device.save();
    },
    exposes: [e.power(), e.current(), e.voltage(), e.switch()],
};

module.exports = definition;

Totally non-standard, but the numbers output look plausible.

As said above, they still work as switches and repeaters. :)

Koenkk commented 1 year ago

@englishteeth I wasn't aware that the device reports on a non-standard cluster, your code looks good, if others can confirm it works correctly you can make a PR.

sixhills commented 1 year ago

@englishteeth Thanks so much for that code. I don't understand it but I'm delighted to report that it works! The Z2M log is reporting:

Oct 29 19:06:02 pi42 npm[10579]: Zigbee2MQTT:info 2023-10-29 19:06:02: MQTT publish: topic 'zigbee2mqtt/WL1_plug', payload '{"current":0.08,"linkquality":138,"power":9.37,"state":"ON","voltage":236.58}'

The dashboard reports the same values. The reported values are extremely plausible, so I think you've fixed the problem. Thank you so much.

sixhills commented 1 year ago

@englishteeth One last query: it looks as though it should also report energy used so far in kWh. Have you found a key that would extract that value? If that's possible, it would be great to have a way of resetting energy to zero but I appreciate that that may be a step too far. Thanks again for your excellent work on this.

Axelf-alex commented 1 year ago

@englishteeth You sir deserve a medal absolute legend thank you so much it works amazingly well. I tested even a hair dryer and the numbers look plausible.

Next Z2M patch will probably have this in support for other users to have an easier time 😊

englishteeth commented 1 year ago

Thanks for the kind words and number sanity checks, I'll look into how to raise a PR for this as it stands.

@sixhills - I only found the '64529' cluster because it was reporting by default so, so far I've not been able to get the plug to do anything else. There is another curious cluster '64599' but it might really need a compatible hub to find out what's going on.

Koenkk commented 1 year ago

@englishteeth added the device, will be supported out of the box in the 1 November release.

Delliaf commented 1 year ago

This is the same, external converter is working

Screenshots ![Screenshot_2023-10-31-19-10-50-77_3c841798971d89a92069939d312bec3c](https://github.com/Koenkk/zigbee2mqtt/assets/34547169/68861657-202b-4a2f-a75b-e0ba0040fc92) ![Screenshot_2023-10-31-19-12-15-76_c3a231c25ed346e59462e84656a70e50](https://github.com/Koenkk/zigbee2mqtt/assets/34547169/6d4d19f3-5f10-4d2f-84a0-30ca053d9789) ![IMG_20231031_191134](https://github.com/Koenkk/zigbee2mqtt/assets/34547169/76f82972-b635-41a4-81d8-20f7ce4deb0e)

https://sl.aliexpress.ru/p?key=qQpBUci

sixhills commented 1 year ago

Closing as this device is now supported by Z2M.

Mikes-HAAS commented 12 months ago

Works for me thats is all I needed as bought a pack of 4. Regards Mike

treemonkey83 commented 10 months ago

Has anyone experienced excessive publishing from these plugs. It's reporting it's state every few seconds. Looking at the debug level log it's pushing

Received Zigbee message from 'LR wall', type 'read', cluster 'genTime', data '["localTime"]' from endpoint 1 with groupID 0

Over and over. Debounce of any time doesn't seem to do anything.