From cf8cd47126cd051aa834abc1e316168d8f50dd43 Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Mon, 3 Feb 2020 15:02:09 +1100 Subject: [PATCH] Add a key to the TuyaReceived to help when writing boilerplate rules. The key is in the form CmndDpIdDpType with a value that is the hex encoding of the DpIdData. This allows Rules to be written that target status updates from a specific DpId and of a specific message type. For example, an Anko HEGSM40 fan reports the speed the fan is operating at via STAT message on DpId 4 of type Enum. To publish the speed to MQTT as it's reported from the MCU, I can use the following rule: on TuyaReceived#Cmnd7DpId3DpType4 do Publish stat/%topic%/SPEED %value% endon This appears "on the wire" as: stat/tasmota/SPEED 01 --- tasmota/xdrv_16_tuyamcu.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index da189c568..4fc45e913 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -683,7 +683,9 @@ void TuyaSerialInput(void) uint8_t dpidStart = 6; while (dpidStart + 4 < Tuya.byte_counter) { uint16_t dpDataLen = Tuya.buffer[dpidStart + 2] << 8 | Tuya.buffer[dpidStart + 3]; - ResponseAppend_P(PSTR(",\"%d\":{\"DpId\":%d,\"DpIdType\":%d,\"DpIdData\":\"%s\""), Tuya.buffer[dpidStart], Tuya.buffer[dpidStart], Tuya.buffer[dpidStart + 1], ToHex_P((unsigned char*)&Tuya.buffer[dpidStart + 4], dpDataLen, hex_char, sizeof(hex_char))); + const char *dpData = ToHex_P((unsigned char*)&Tuya.buffer[dpidStart + 4], dpDataLen, hex_char, sizeof(hex_char)); + ResponseAppend_P(PSTR(",\"Cmnd%dDpId%dDpType%d\":\"%s\""), Tuya.buffer[3], Tuya.buffer[dpidStart], Tuya.buffer[dpidStart + 1], dpData); + ResponseAppend_P(PSTR(",\"%d\":{\"DpId\":%d,\"DpIdType\":%d,\"DpIdData\":\"%s\""), Tuya.buffer[dpidStart], Tuya.buffer[dpidStart], Tuya.buffer[dpidStart + 1], dpData); if (TUYA_TYPE_STRING == Tuya.buffer[dpidStart + 1]) { ResponseAppend_P(PSTR(",\"Type3Data\":\"%.*s\""), dpDataLen, (char *)&Tuya.buffer[dpidStart + 4]); }