Add a key to the TuyaReceived to help when writing boilerplate rules.

The key is in the form Cmnd<msgtype>DpId<ID>DpType<DpIdType> 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
This commit is contained in:
David Gwynne 2020-02-03 15:02:09 +11:00
parent 26cee00e2f
commit cf8cd47126

View File

@ -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]);
}