zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Tuya JM-TRH-ZGB-V1 clock error

Open z-x-f opened this issue 3 years ago • 14 comments

What happened?

Since the update of (https://github.com/Koenkk/zigbee2mqtt/commit/ddcab827ad086949b87d5eaff8d261d8f2d529bf), my tuya jm-trh-zgb-v1 has a clock error. Please help me to find out where the problem is.

What did you expect to happen?

No response

How to reproduce it (minimal and precise)

No response

Zigbee2MQTT version

1.31.2-dev commit: 0dd89967

Adapter firmware version

20230410

Adapter

zigstar

Debug log

No response

z-x-f avatar Jun 12 '23 05:06 z-x-f

i have the same issue with this two devices: M-TRH-ZGB-V1 SZ-T04

b2un0 avatar Jun 12 '23 08:06 b2un0

@z-x-f does it still work in z2m 1.31.0?

Koenkk avatar Jun 12 '23 16:06 Koenkk

~~1.31.0 commit: f440c860, have the same problem.~~ Sorry, the test was not re-added just now, resulting in a test error. Retested, 1.31.0 works fine.

z-x-f avatar Jun 12 '23 16:06 z-x-f

https://github.com/Koenkk/zigbee2mqtt/commit/21f51258a9749d2ccba212997c3ab2f419d62142 works normally, but https://github.com/Koenkk/zigbee2mqtt/commit/7df6b2bab54616ce6573ca8633bec4b0a4b8fbd6 is abnormal again.

z-x-f avatar Jun 12 '23 17:06 z-x-f

@z-x-f can you add a log statement here: https://github.com/Koenkk/zigbee-herdsman-converters/blob/1d4e3cc732397fe1a2cd7ba7075f888d404ba3dd/src/lib/tuya.ts#L106 and a console.log(error) here: https://github.com/Koenkk/zigbee-herdsman-converters/blob/1d4e3cc732397fe1a2cd7ba7075f888d404ba3dd/src/lib/tuya.ts#L122 to see where it goes wrong?

Koenkk avatar Jun 13 '23 16:06 Koenkk

DataConfirmError: Command 0xa4c1383a1e6417c1/1 manuSpecificTuya.mcuSyncTime({"payloadSize":8,"payload":[100,null,140,236,100,null,140,108]}, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) failed (Data request failed with error: 'No network route' (205))
    at ZStackAdapter.sendZclFrameToEndpointInternal (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/src/adapter/z-stack/adapter/zStackAdapter.ts:415:23)
    at Queue.executeNext (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/src/utils/queue.ts:32:32) {
  code: 205 

Is this error unrelated to the problem?

z-x-f avatar Jun 16 '23 13:06 z-x-f

It is, this is the time sync command. It seems for some reason the device is not reachable, did you already try to re-pair it?

Koenkk avatar Jun 17 '23 07:06 Koenkk

I tried to repair the affected devices, it does not help.

b2un0 avatar Jun 17 '23 13:06 b2un0

When the time synchronization is wrong, I found that there is null in the payload, I'm not sure why it is like this?

This is the normal log when the time is synchronized:

  Zigbee2MQTT:debug 2023-06-19 21:06:00: Received Zigbee message from '0xa4c1386584b6bf43', type 'commandMcuSyncTime', cluster 'manuSpecificTuya', data '{"payloadSize":117}' from endpoint 1 with groupID 0
  zigbee-herdsman:controller:endpoint Command 0xa4c1386584b6bf43/1 manuSpecificTuya.mcuSyncTime({"payloadSize":8,"payload":[100,144,82,184,100,144,195,56]}, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) +131ms
  zigbee-herdsman:controller:endpoint DefaultResponse 0xa4c1386584b6bf43/1 61184(36, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":1,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) +0ms

This is the log when the time synchronization is not normal:

Zigbee2MQTT:debug 2023-06-19 21:01:09: Received Zigbee message from '0xa4c1386584b6bf43', type 'commandMcuSyncTime', cluster 'manuSpecificTuya', data '{"payloadSize":75}' from endpoint 1 with groupID 0
  zigbee-herdsman:controller:endpoint Command 0xa4c1386584b6bf43/1 manuSpecificTuya.mcuSyncTime({"payloadSize":8,"payload":[100,null,144,149,100,null,144,21]}, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) +129ms
  zigbee-herdsman:controller:endpoint DefaultResponse 0xa4c1386584b6bf43/1 61184(36, {"sendWhen":"immediate","timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":1,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) +0ms
utcTime:1687183379
localTime:1687212179

{
  payloadSize: 8,
  payload: [
    100, NaN, 144,
     19, 100, NaN,
    144, 147
  ]
}

z-x-f avatar Jun 19 '23 13:06 z-x-f

I modified convertDecimalValueTo4ByteHexArray as follows, which temporarily solved the problem. Is this modification feasible?

function convertDecimalValueTo4ByteHexArray(value) {
    const hexValue = Number(value).toString(16).padStart(8, '0');
    const chunk1 = parseInt(hexValue.substring(0, 2), 16);
    const chunk2 = parseInt(hexValue.substring(2, 4), 16);
    const chunk3 = parseInt(hexValue.substring(4, 6), 16);
    const chunk4 = parseInt(hexValue.substring(6), 16);
    return [chunk1, chunk2, chunk3, chunk4];
}
=============
utcTime: 1687191707
localTime: 1687220507
=============
{
  payloadSize: 8,
  payload: [
    100, 144, 128,
    155, 100, 144,
    241,  27
  ]
}

z-x-f avatar Jun 19 '23 16:06 z-x-f

Yes, but I don't know what the diff with existing code is. Does the following also work?

function convertDecimalValueTo4ByteHexArray(value) {
    const hexValue = Number(value).toString(16).padStart(8, '0');
    const chunk1 = hexValue.substring(0, 2);
    const chunk2 = hexValue.substring(2, 4);
    const chunk3 = hexValue.substring(4, 6);
    const chunk4 = hexValue.substring(6);
    return [chunk1, chunk2, chunk3, chunk4].map((hexVal) => parseInt(hexVal, 16));
}

Koenkk avatar Jun 19 '23 18:06 Koenkk

This is also working fine.

function convertDecimalValueTo4ByteHexArray(value) {
    const hexValue = Number(value).toString(16).padStart(8, '0');
    const chunk1 = hexValue.substring(0, 2);
    const chunk2 = hexValue.substring(2, 4);
    const chunk3 = hexValue.substring(4, 6);
    const chunk4 = hexValue.substring(6);
    return [chunk1, chunk2, chunk3, chunk4].map((hexVal) => parseInt(hexVal, 16));
}

=============
utcTime: 1687228201
localTime: 1687257001
=============
{
  payloadSize: 8,
  payload: [
    100, 145,  15,  41,
    100, 145, 127, 169
  ]
}

By the way, test the original again, there is still an error.

=============
utcTime: 1687228553
localTime: 1687257353
=============
{
  payloadSize: 8,
  payload: [
    100, NaN, 145, 137,
    100, NaN, 145,   9
  ]
}

It seems to be caused by different substring(startIndex, endIndex) substr(startIndex, length)methods.

z-x-f avatar Jun 20 '23 02:06 z-x-f

Thanks, pushed the fix!

Changes will be available in the dev branch in a few hours from now. (https://www.zigbee2mqtt.io/advanced/more/switch-to-dev-branch.html)

Koenkk avatar Jun 20 '23 17:06 Koenkk

i have the same issue with this two devices: M-TRH-ZGB-V1 SZ-T04

can confirm, both devices works again. 🎉 thanks!

b2un0 avatar Jun 21 '23 09:06 b2un0