From 3f73d5a49db435f252b4fdb5523e01542da21b67 Mon Sep 17 00:00:00 2001 From: yvesdm3000 Date: Sun, 22 Jan 2023 11:50:52 +0100 Subject: [PATCH] Implement Zigbee tuya_time sync. (#17765) --- .../xdrv_23_zigbee_6_0_commands.ino | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_6_0_commands.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_6_0_commands.ino index 4aaad582b..3183db08a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_6_0_commands.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_6_0_commands.ino @@ -578,26 +578,55 @@ void parseSingleTuyaAttribute(Z_attribute & attr, const SBuffer &buf, } } +/*********************************************************************************************\ + * + * Reply Tuya time + * +\*********************************************************************************************/ +static void replyTuyaTime( uint16_t cluster, uint16_t shortaddr, uint8_t dstendpoint ) { + ZCLFrame zcl(10); // message is `attrs_len` bytes + zcl.shortaddr = shortaddr; + zcl.cluster = cluster; + zcl.dstendpoint = dstendpoint; + zcl.cmd = 0x24; + zcl.clusterSpecific = true; + zcl.needResponse = false; // it is a reply + zcl.direct = false; // discover route + zcl.payload.add16BigEndian(8); // Size + if (!RtcTime.valid) { + zcl.payload.add32(0); + zcl.payload.add32(0); + } else { + zcl.payload.add32BigEndian(Rtc.utc_time); + zcl.payload.add32BigEndian(Rtc.local_time); + } + zigbeeZCLSendCmd(zcl); +} + // // Tuya - MOES specifc cluster 0xEF00 // https://developer.tuya.com/en/docs/iot-device-dev/tuya-zigbee-universal-docking-access-standard?id=K9ik6zvofpzql#subtitle-6-Private%20cluster // bool convertTuyaSpecificCluster(class Z_attribute_list &attr_list, uint16_t cluster, uint8_t cmd, bool direction, uint16_t shortaddr, uint8_t srcendpoint, const SBuffer &buf) { - // uint16_t seq_number = buf.get16BigEndian(0) - uint8_t dpid = buf.get8(2); // dpid from Tuya documentation - uint8_t attr_type = buf.get8(3); // data type from Tuya documentation - uint16_t len = buf.get16BigEndian(4); if ((1 == cmd) || (2 == cmd)) { // attribute report or attribute response + // uint16_t seq_number = buf.get16BigEndian(0) + uint8_t dpid = buf.get8(2); // dpid from Tuya documentation + uint8_t attr_type = buf.get8(3); // data type from Tuya documentation + uint16_t len = buf.get16BigEndian(4); // create a synthetic attribute with id 'dpid' Z_attribute & attr = attr_list.addAttribute(cluster, (attr_type << 8) | dpid); parseSingleTuyaAttribute(attr, buf, 6, len, attr_type); return true; // true = remove the original Tuya attribute } - // TODO Cmd 0x24 to sync clock with coordinator time + if (0x24 == cmd) { + replyTuyaTime(cluster, shortaddr, srcendpoint); + return true; + } return false; } + /*********************************************************************************************\ * * Find commands