Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.92k stars 1.66k forks source link

AQARA T1 Power report is wrong or absent #20895

Open jmcollin78 opened 8 months ago

jmcollin78 commented 8 months ago

What happened?

Aqara T1 with last firmware update doesn't report the power of report a wrong power. The installed firmware is: Capture d’écran 2024-01-19 à 16 24 19

For one on the switch, the power is always set even if the switch is off (and the switch is really off): Capture d’écran 2024-01-19 à 16 03 06

For one other the power is always 0 even if the switch is off:

Capture d’écran 2024-01-19 à 16 09 53

Just after pairing, it works as expected, but after a while, this stop working and the issues are present.

The issue is very similar with https://github.com/Koenkk/zigbee2mqtt/issues/11480#issuecomment-1162896817 which is Closed, but still here on 1.35.1-1 and on Edge release.

This issue appears approximatively with the 1.33 release (not totally certain of the release because I lost the backup).

What did you expect to happen?

The power should reflect the real power of the device connected.

How to reproduce it (minimal and precise)

Switch on/off. Check power.

Zigbee2MQTT version

Edge

Adapter firmware version

(not found ??)

Adapter

ezsp

Setup

Pi 4

Debug log

SWITCH ON: Zigbee2MQTT:debug 2024-01-19 16:17:57: Received MQTT message on 'zigbee2mqtt/Radiateur chambre 2/set' with data '{"state":"ON"}' Zigbee2MQTT:debug 2024-01-19 16:17:57: Publishing 'set' 'state' to 'Radiateur chambre 2'

Zigbee2MQTT:info 2024-01-19 16:17:57: MQTT publish: topic 'zigbee2mqtt/Radiateur chambre 2', payload '{"consumption":0.06978899240493774,"current":0,"device_temperature":14,"energy":0.07,"last_seen":"2024-01-19T15:17:57.704Z","linkquality":176,"power":0,"power_outage_count":0,"power_outage_memory":false,"state":"OFF","switch_type":"toggle","update":{"installed_version":23,"latest_version":23,"state":"idle"},"update_available":null,"voltage":238.82}'

Zigbee2MQTT:info 2024-01-19 16:17:57: MQTT publish: topic 'zigbee2mqtt/Radiateur chambre 2', payload '{"consumption":0.06978899240493774,"current":0,"device_temperature":14,"energy":0.07,"last_seen":"2024-01-19T15:17:57.704Z","linkquality":176,"power":0,"power_outage_count":0,"power_outage_memory":false,"state":"ON","switch_type":"toggle","update":{"installed_version":23,"latest_version":23,"state":"idle"},"update_available":null,"voltage":238.82}'

Zigbee2MQTT:debug 2024-01-19 16:17:57: Received Zigbee message from 'Radiateur chambre 2', type 'attributeReport', cluster 'genOnOff', data '{"onOff":1}' from endpoint 1 with groupID 0

Zigbee2MQTT:info 2024-01-19 16:17:57: MQTT publish: topic 'zigbee2mqtt/Radiateur chambre 2', payload '{"consumption":0.06978899240493774,"current":0,"device_temperature":14,"energy":0.07,"last_seen":"2024-01-19T15:17:57.740Z","linkquality":176,"power":0,"power_outage_count":0,"power_outage_memory":false,"state":"ON","switch_type":"toggle","update":{"installed_version":23,"latest_version":23,"state":"idle"},"update_available":null,"voltage":238.82}'

Zigbee2MQTT:debug 2024-01-19 16:18:21: Received Zigbee message from 'Radiateur chambre 2', type 'attributeReport', cluster 'genDeviceTempCfg', data '{"currentTemperature":12}' from endpoint 1 with groupID 0 Zigbee2MQTT:info 2024-01-19 16:18:21: MQTT publish: topic 'zigbee2mqtt/Radiateur chambre 2', payload '{"consumption":0.06978899240493774,"current":0,"device_temperature":12,"energy":0.07,"last_seen":"2024-01-19T15:18:21.867Z","linkquality":176,"power":0,"power_outage_count":0,"power_outage_memory":false,"state":"ON","switch_type":"toggle","update":{"installed_version":23,"latest_version":23,"state":"idle"},"update_available":null,"voltage":238.82}'

jmcollin78 commented 8 months ago

Let me know if I can help in any way.

jmcollin78 commented 8 months ago

Hello after the "Current version: 1.35.2-1" the problem is still there.

rjaros87 commented 7 months ago

I've got the same problem. If I re-pair it helps for ~1-2 days and then the same like you mention it hangs. I'm using Skyconnect EZSP v12 7.3.2.0 build 212, Z2M 1.35.3, zigbee_herdsman_version 0.33.8

jmcollin78 commented 7 months ago

Still have the pb after all update (I try also the Edge Z2M addon without sucess). The symptoms are exactly the same: power is fine just after pairing for one or two days. Then it is stuck in the last value (which can be positive). No error logs nowhere.

rjaros87 commented 7 months ago

I discovered something 💡 , I had a second relay with an older firmware version 21, tested for 5 days without any issues. I've updated it to the latest version 23, and after about 1.5 days, the relay stopped reporting. I haven't tested it with the latest firmware version 7.4+ for the coordinator and the test "ember" driver. Maybe I will test it on the weekend.

jmcollin78 commented 7 months ago

I discovered something 💡 , I had a second relay with an older firmware version 21, tested for 5 days without any issues. I've updated it to the latest version 23, and after about 1.5 days, the relay stopped reporting. I haven't tested it with the latest firmware version 7.4+ for the coordinator and the test "ember" driver. Maybe I will test it on the weekend.

This is a fact I already expriment on my side. One AQARA T1 POWER was working as expected but after firmware update, the power didn't comes to HA after one or two days. May be we should open an issue on Aqara forum if there is one ?

jmcollin78 commented 7 months ago

You can create a ticket here like I will do: https://static-resource.aqara.com/html/feedback.html

rjaros87 commented 6 months ago

Any response from Aqara support? I didn't receive any response :(

jmcollin78 commented 6 months ago

No response yet

jmcollin78 commented 6 months ago

I just look at my email and I got an answer from support:

Hi Jean-Marc,

Thank you for contacting us. 

I'm sorry to hear that you are having this problem. I have some questions for you. 

What region do you choose in the app? 

Could you please provide your Aqara user account? Not included password. 

Could you please send us a short video to show this behavior? 

Sincerely, 
Cecilia
rjaros87 commented 6 months ago

It would be nice if they provided OTA version 0.0.0_0021, because this version worked for me 👍. I've registered on their Aqara developer site and I've got only those information for region EU (without url to ota files):

{
  "code": 0,
  "requestId": "a9a7eb3e91c546dba00f8bca26649ba4.344420.17101976422032075",
  "message": "Success",
  "msgDetails": null,
  "result": [
    {
      "releaseTime": "1708655686000",
      "necessary": 0,
      "fileSize": 288146,
      "updateLog": "1.Fix known bugs",
      "state": 2,
      "firmwareVersion": "0.0.0_0030"
    },
    {
      "releaseTime": "1644466164000",
        1698329291
      "necessary": 0,
      "fileSize": 287666,
      "updateLog": "Fix the offline problem of device.",
      "state": 2,
      "firmwareVersion": "0.0.0_0023"
    },
    {
      "releaseTime": "1635488564000",
      "necessary": 0,
      "fileSize": 287046,
      "updateLog": "1. Device stability was increased.",
      "state": 2,
      "firmwareVersion": "0.0.0_0022"
    }
  ]
}
jmcollin78 commented 6 months ago

Do you find how to restore an old firmware (without the application and aqara hub) ?

rjaros87 commented 6 months ago

If we have the ota file, than we can use Z2M and override index.json file with "custom" firmwares :)

jmcollin78 commented 6 months ago

The last and quick answer of the support:

Hi Jean-Marc,

Unfortunately, the device is not compatible with Home Assistant for the time being. 

Sincerely, 
Cecilia
Aqara Technical Support 

Such a shame...

jmcollin78 commented 6 months ago

I try with the Ember adapter in Z2M. Same problem.

jmcollin78 commented 6 months ago

The answer of the support to the question "is it possible to flash the firmware of the Aqara devices":

Hi Jean-Marc,

I'm sorry that there is no way to do this. 

Sincerely, 
Cecilia
Aqara Technical Support 
jmcollin78 commented 6 months ago

I tried with Z2M 1.36.1-1 and problem is still there.

jmcollin78 commented 4 months ago

The problem is fixed with Z2M 1.37.1-1 !

This is really a surprise because the release notes don't mention this but all my Aqara T1 now report the power.

Did you experience the same thing ?

rjaros87 commented 4 months ago

I will check that :)

rjaros87 commented 4 months ago

After 2 days, same behaviour, power reports 0W. Zigbee2MQTT version 1.37.1 commit: [ea39d86(https://github.com/Koenkk/zigbee2mqtt/commit/ea39d86) SkyConnect EZSP v13 7.4.1.0 build 0

jmcollin78 commented 4 months ago

After one week, 3 over 4 are fixed on my side. Nothing special on the one which don't report the power. Very strange.

petravic commented 3 months ago

This converter works with latest release and fixed the power not reporting problem for me.

const {} = require('zigbee-herdsman-converters/lib/modernExtend');

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

const definition = {
    zigbeeModel: ['lumi.switch.n0agl1'],
    model: 'SSM-U01',
    vendor: 'Aqara',
    description: 'Single switch module T1 (with neutral)',
    extend: [],
    fromZigbee: [fz.on_off, fz.metering, fz.electrical_measurement, fz.device_temperature, lumi.fromZigbee.lumi_specific],
    exposes: [e.switch(), e.energy(), e.power(), e.device_temperature(), e.power_outage_memory(), e.power_outage_count(), e.switch_type(), e.voltage(), e.current()],
    toZigbee: [lumi.toZigbee.lumi_switch_type, tz.on_off, lumi.toZigbee.lumi_switch_power_outage_memory, lumi.toZigbee.lumi_led_disabled_night],
    configure: async (device, coordinatorEndpoint) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'haElectricalMeasurement', 'seMetering', 'genDeviceTempCfg']);
        await reporting.onOff(endpoint);
        await endpoint.read('haElectricalMeasurement', ['acPowerMultiplier', 'acPowerDivisor']);
        await reporting.readMeteringMultiplierDivisor(endpoint);
        await reporting.currentSummDelivered(endpoint);
        await reporting.activePower(endpoint, {min: 5, max: 600, change: 10});
        await reporting.deviceTemperature(endpoint);
        device.powerSource = 'Mains (single phase)';
        device.type = 'Router';
        device.save();
    }
};
rjaros87 commented 3 months ago

@petravic I believe that the final line of the converter should include module.exports = definition; :) However, despite using the converter, the power, temperature, and consumption reports are still returning null. :/ What version of zigbee2mqtt and coordinator driver do you have?

Edited: After a few minutes, the device started reporting power, temperature, and energy :) I will observe it for a week to see if this solution will work :) Thanks :)

jmcollin78 commented 3 months ago

Hello @petravic,

When trying your converter I have this issue in the logs:

[2024-06-15 11:26:18] error:    z2m: Failed to load external converter file 'aqara-t1.js' (Cannot read properties of undefined (reading 'push'))
[2024-06-15 11:26:18] error:    z2m: Probably there is a syntax error in the file or the external converter is not compatible with the current Zigbee2MQTT version
[2024-06-15 11:26:18] error:    z2m: Note that external converters are not meant for long term usage, it's meant for local testing after which a pull request should be created to add out-of-the-box support for the device

I guess you install it with the modification of zigbee2mqtt/configuration.yaml:

...
device_options:
  legacy: false
devices:
...
external_converters:
  - aqara-t1.js

EDIT: OK I should have read more carfully the post of @rjaros87 which gave the solution. For new comers, here is the complete and fixed converter:

const {} = require("zigbee-herdsman-converters/lib/modernExtend");

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

const definition = {
    zigbeeModel: ["lumi.switch.n0agl1"],
    model: "SSM-U01",
    vendor: "Aqara",
    description: "Single switch module T1 (with neutral)",
    extend: [],
    fromZigbee: [fz.on_off, fz.metering, fz.electrical_measurement, fz.device_temperature, lumi.fromZigbee.lumi_specific],
    exposes: [
        e.switch(),
        e.energy(),
        e.power(),
        e.device_temperature(),
        e.power_outage_memory(),
        e.power_outage_count(),
        e.switch_type(),
        e.voltage(),
        e.current(),
    ],
    toZigbee: [lumi.toZigbee.lumi_switch_type, tz.on_off, lumi.toZigbee.lumi_switch_power_outage_memory, lumi.toZigbee.lumi_led_disabled_night],
    configure: async (device, coordinatorEndpoint) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ["genOnOff", "haElectricalMeasurement", "seMetering", "genDeviceTempCfg"]);
        await reporting.onOff(endpoint);
        await endpoint.read("haElectricalMeasurement", ["acPowerMultiplier", "acPowerDivisor"]);
        await reporting.readMeteringMultiplierDivisor(endpoint);
        await reporting.currentSummDelivered(endpoint);
        await reporting.activePower(endpoint, { min: 5, max: 600, change: 10 });
        await reporting.deviceTemperature(endpoint);
        device.powerSource = "Mains (single phase)";
        device.type = "Router";
        device.save();
    },
};

module.exports = definition;

EDIT2 : after few minutes it doesn't to change anything. Power is still not reported.

rjaros87 commented 3 months ago

@jmcollin78 I've re-paired the devices after uploading the converter, and it has been working for 3 days now. There is about a 3-minute delay in getting the Power value. You might be able to adjust the reporting settings to receive updates more frequently.

jmcollin78 commented 3 months ago

I will try that. Thank you

EDIT: i try many thing:

Each time I have wait 5 minutes but it don't work either. There must be something wrong on my configuration.

jmcollin78 commented 3 months ago

Is my configuration wrong ? in config/zigbee2mqtt: file aqara-t1.js:

const {} = require("zigbee-herdsman-converters/lib/modernExtend");

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

const definition = {
    zigbeeModel: ["lumi.switch.n0agl1"],
    model: "SSM-U01",
    vendor: "Aqara",
    description: "Single switch module T1 (with neutral)",
    extend: [],
    fromZigbee: [fz.on_off, fz.metering, fz.electrical_measurement, fz.device_temperature, lumi.fromZigbee.lumi_specific],
    exposes: [
        e.switch(),
        e.energy(),
        e.power(),
        e.device_temperature(),
        e.power_outage_memory(),
        e.power_outage_count(),
        e.switch_type(),
        e.voltage(),
        e.current(),
    ],
    toZigbee: [lumi.toZigbee.lumi_switch_type, tz.on_off, lumi.toZigbee.lumi_switch_power_outage_memory, lumi.toZigbee.lumi_led_disabled_night],
    configure: async (device, coordinatorEndpoint) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ["genOnOff", "haElectricalMeasurement", "seMetering", "genDeviceTempCfg"]);
        await reporting.onOff(endpoint);
        await endpoint.read("haElectricalMeasurement", ["acPowerMultiplier", "acPowerDivisor"]);
        await reporting.readMeteringMultiplierDivisor(endpoint);
        await reporting.currentSummDelivered(endpoint);
        await reporting.activePower(endpoint, { min: 5, max: 600, change: 10 });
        await reporting.deviceTemperature(endpoint);
        device.powerSource = "Mains (single phase)";
        device.type = "Router";
        device.save();
    },
};

module.exports = definition;

in configuration.yaml at the end of the file:

...
external_converters:
  - aqara-t1.js

The last state I have:

{
    "consumption": 0.08414331823587418,
    "current": 0,
    "device_temperature": 19,
    "energy": 0.08,
    "last_seen": "2024-06-17T06:46:34.783Z",
    "linkquality": 208,
    "power": 0,                                <----------------------
    "power_outage_count": 0,
    "power_outage_memory": false,
    "state": "ON",                           <------------------------
    "switch_type": "toggle",
    "voltage": 242.51
}

DeviceTemperature and energy are changing but not the power.

jmcollin78 commented 3 months ago

Ooooh something have change. On another device (which was NOT re-paired) I have this wrong power: Capture d’écran 2024-06-17 à 08 49 55

11420W instead of 1142 W I guess.

jmcollin78 commented 3 months ago

Finally I get it working by clicking on the botu button here for each device : Capture d’écran 2024-06-18 à 19 10 05

jmcollin78 commented 3 months ago

How this fix will be integrated into the next release of Z2M ? Is there any process to run to have this merged in the add-on directly ?

DzianisFrydliand commented 3 months ago

I have the same question. I have Aqara DLKZMK11LM and power is not reported.