Koenkk / zigbee2mqtt

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

Reading from endpoints doesn't work #11516

Closed vklachkov closed 2 years ago

vklachkov commented 2 years ago

What happened?

I am developing my own zigbee thermostat. In the converter, in exposes, I wrote climate() with some field. Like this:

exposes.climate()
    .withSystemMode(['off', 'auto'])
    .withLocalTemperature()
    .withLocalTemperatureCalibration(0.0, 2.5, 0.5)
    .withSetpoint('occupied_heating_setpoint', 15.0, 50.0, 0.5)
    .withEndpoint(epName),

And so that the values would be synchronized during configuration, I wrote the following code in configure:

configure: async (device, coordinatorEndpoint, logger) => {
    device.endpoints.forEach(async (ep) => {
        await ep.read('hvacThermostat', [
            'systemMode',
            'localTemperature',
            'occupiedHeatingSetpoint',
            'localTemperatureCalibration'
        ]);
        await ep.read('hvacThermostat', [1024], manufacturerOptions.jennic);
    });
}

And it doesn't work. I removed the reading of different attributes, each time deleting the device, restarting Z2M, adding again. And it somehow even synchronized systemMode and custom attribute 1024. One has only to add occupiedHeatingSetpoint or localTemperatureCalibration and everything breaks! Sometimes reading only a custom attribute does not work. No errors, no logs. Just like this:

image

And there is also a strange incomplete synchronization:

image

If I manually click all the synchronization buttons, then everything works:

image

What did you expect to happen?

Synchronize all values or display a detailed error in the logs

How to reproduce it (minimal and precise)

I don’t understand anything, but I'm ready to provide any information, even make a video

Zigbee2MQTT version

1.23.0

Adapter firmware version

20210120

Adapter

SONOFF ZigBEE 3.0 USB Dongle Plus

Debug log

No response

vklachkov commented 2 years ago

The problem turned out to be in foreach with async. I did this and it worked:

for (const ep of device.endpoints) {
  await ep.read('hvacThermostat', [
      'systemMode',
      'localTemp',
      'occupiedHeatingSetpoint',
      'localTemperatureCalibration'
  ]);
  await ep.read('hvacThermostat', [1024], manufacturerOptions.jennic);
}

I took the names from here: https://github.com/Koenkk/zigbee-herdsman/blob/fdc3a0f7de0b1e79346649e3edb2bb716255dc2f/src/zcl/definition/cluster.ts