diff --git a/tasmota/settings.h b/tasmota/settings.h index 4842103b4..81a62c835 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -143,8 +143,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t mi32_enable : 1; // bit 1 (v9.1.0.1) - SetOption115 - (ESP32 BLE) Enable ESP32 MI32 BLE (1) uint32_t zb_disable_autoquery : 1; // bit 2 (v9.1.0.1) - SetOption116 - (Zigbee) Disable auto-query of zigbee lights and devices (1) uint32_t fade_fixed_duration : 1; // bit 3 (v9.1.0.2) - SetOption117 - (Light) run fading at fixed duration instead of fixed slew rate - uint32_t spare04 : 1; // bit 4 - uint32_t spare05 : 1; // bit 5 + uint32_t zb_received_as_subtopic : 1; // bit 4 (v9.2.0.3) - SetOption118 - (Zigbee) Move ZbReceived form JSON message and into the subtopic replacing "SENSOR" default + uint32_t zb_omit_json_addr : 1; // bit 5 (v9.2.0.3) - SetOption119 - (Zigbee) Remove the device addr from json payload, can be used with zb_topic_fname where the addr is already known from the topic uint32_t spare06 : 1; // bit 6 uint32_t spare07 : 1; // bit 7 uint32_t spare08 : 1; // bit 8 diff --git a/tasmota/xdrv_23_zigbee_2a_devices_impl.ino b/tasmota/xdrv_23_zigbee_2a_devices_impl.ino index 0a97a9938..80a69441c 100644 --- a/tasmota/xdrv_23_zigbee_2a_devices_impl.ino +++ b/tasmota/xdrv_23_zigbee_2a_devices_impl.ino @@ -511,15 +511,19 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l TasmotaGlobal.mqtt_data[0] = 0; // clear string // Do we prefix with `ZbReceived`? - if (!Settings.flag4.remove_zbreceived) { + if (!Settings.flag4.remove_zbreceived && !Settings.flag5.zb_received_as_subtopic) { Response_P(PSTR("{\"%s\":"), json_prefix); } // What key do we use, shortaddr or name? - if (use_fname) { - Response_P(PSTR("%s{\"%s\":{"), TasmotaGlobal.mqtt_data, friendlyName); - } else { - Response_P(PSTR("%s{\"0x%04X\":{"), TasmotaGlobal.mqtt_data, shortaddr); + if (!Settings.flag5.zb_omit_json_addr) { + if (use_fname) { + Response_P(PSTR("%s{\"%s\":"), TasmotaGlobal.mqtt_data, friendlyName); + } else { + Response_P(PSTR("%s{\"0x%04X\":"), TasmotaGlobal.mqtt_data, shortaddr); + } } + ResponseAppend_P(PSTR("{")); + // Add "Device":"0x...." ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_DEVICE "\":\"0x%04X\","), shortaddr); // Add "Name":"xxx" if name is present @@ -527,9 +531,13 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l ResponseAppend_P(PSTR("\"" D_JSON_ZIGBEE_NAME "\":\"%s\","), EscapeJSONString(friendlyName).c_str()); } // Add all other attributes - ResponseAppend_P(PSTR("%s}}"), attr_list.toString(false).c_str()); + ResponseAppend_P(PSTR("%s}"), attr_list.toString(false).c_str()); - if (!Settings.flag4.remove_zbreceived) { + if (!Settings.flag5.zb_omit_json_addr) { + ResponseAppend_P(PSTR("}")); + } + + if (!Settings.flag4.remove_zbreceived && !Settings.flag5.zb_received_as_subtopic) { ResponseAppend_P(PSTR("}")); } @@ -545,7 +553,10 @@ void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_l snprintf_P(subtopic, sizeof(subtopic), PSTR("%s/%04X"), TasmotaGlobal.mqtt_topic, shortaddr); } char stopic[TOPSZ]; - GetTopic_P(stopic, TELE, subtopic, D_RSLT_SENSOR); + if (Settings.flag5.zb_received_as_subtopic) + GetTopic_P(stopic, TELE, subtopic, json_prefix); + else + GetTopic_P(stopic, TELE, subtopic, D_RSLT_SENSOR); MqttPublish(stopic, Settings.flag.mqtt_sensor_retain); } else { MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);