From 2a087f40f9760cb72bdf9c125d3cac11b235a262 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 9 Aug 2022 18:30:01 +0200 Subject: [PATCH] Zigbee ``SetOption144 1`` includes a timestamp in `ZbReceived` messages --- CHANGELOG.md | 1 + tasmota/include/tasmota_types.h | 2 +- .../xdrv_23_zigbee_2_devices.ino | 2 +- .../xdrv_23_zigbee_2a_devices_impl.ino | 14 +++++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba63afbb..99ed78f57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - Zigbee include "BatteryPercentage" in all messages - Commands ``WifiScan`` and ``WifiTest`` (#16141) - Support for Catalan language translations by Albert Gonzalez (#16145) +- Zigbee ``SetOption144 1`` includes a timestamp in `ZbReceived` messages ### Changed - ESP32 LVGL library from v8.2.0 to v8.3.0 (#16019) diff --git a/tasmota/include/tasmota_types.h b/tasmota/include/tasmota_types.h index fc54a728d..38247b377 100644 --- a/tasmota/include/tasmota_types.h +++ b/tasmota/include/tasmota_types.h @@ -171,7 +171,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t gui_module_name : 1; // bit 27 (v11.1.0.3) - SetOption141 - (GUI) Disable display of GUI module name (1) uint32_t wait_for_wifi_result : 1; // bit 28 (v11.1.0.4) - SetOption142 - (Wifi) Wait 1 second for wifi connection solving some FRITZ!Box modem issues (1) uint32_t zigbee_no_batt_autoprobe : 1; // bit 29 (v12.0.2.4) - SetOption143 - (Zigbee) Disable Battery auto-probe and using auto-binding - uint32_t spare30 : 1; // bit 30 + uint32_t zigbee_include_time : 1; // bit 30 (v12.0.2.4) - SetOption144 - (Zigbee) include time in `ZbReceived` messages like other sensors uint32_t spare31 : 1; // bit 31 }; } SOBitfield5; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2_devices.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2_devices.ino index befa1e22f..cf11e2405 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2_devices.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2_devices.ino @@ -828,7 +828,7 @@ public: void jsonAddDataAttributes(Z_attribute_list & attr_list) const; void jsonAddDeviceAttributes(Z_attribute_list & attr_list) const; void jsonDumpSingleDevice(Z_attribute_list & attr_list, uint32_t dump_mode, bool add_name) const; - void jsonPublishAttrList(const char * json_prefix, const Z_attribute_list &attr_list) const; + void jsonPublishAttrList(const char * json_prefix, const Z_attribute_list &attr_list, bool include_time = false) const; void jsonLightState(Z_attribute_list & attr_list) const; // dump device attributes to ZbData diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2a_devices_impl.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2a_devices_impl.ino index 2bb0a231a..02df96cf7 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2a_devices_impl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_2a_devices_impl.ino @@ -522,14 +522,22 @@ void Z_Devices::jsonAppend(uint16_t shortaddr, const Z_attribute_list &attr_list // // internal function to publish device information with respect to all `SetOption`s // -void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_list &attr_list) const { +void Z_Device::jsonPublishAttrList(const char * json_prefix, const Z_attribute_list &attr_list, bool include_time) const { bool use_fname = (Settings->flag4.zigbee_use_names) && (friendlyName); // should we replace shortaddr with friendlyname? ResponseClear(); // clear string + // Do we prefix with `ZbReceived`? if (!Settings->flag4.remove_zbreceived && !Settings->flag5.zb_received_as_subtopic) { - Response_P(PSTR("{\"%s\":"), json_prefix); + if (include_time && Rtc.utc_time >= START_VALID_TIME) { + // Add time if needed (and if time is valide) + ResponseAppendTimeFormat(Settings->flag2.time_format); + ResponseAppend_P(PSTR(",\"%s\":"), json_prefix); + } else { + ResponseAppend_P(PSTR("{\"%s\":"), json_prefix); + } } + // What key do we use, shortaddr or name? if (!Settings->flag5.zb_omit_json_addr) { if (use_fname) { @@ -609,7 +617,7 @@ void Z_Devices::jsonPublishFlush(uint16_t shortaddr) { attr_list.setBattPercent(device.batt_percent); } - device.jsonPublishAttrList(PSTR(D_JSON_ZIGBEE_RECEIVED), attr_list); + device.jsonPublishAttrList(PSTR(D_JSON_ZIGBEE_RECEIVED), attr_list, Settings->flag5.zigbee_include_time); attr_list.reset(); // clear the attributes } }