From d538316e03a9b5a0ed957d5e3ce86c9d102c576e Mon Sep 17 00:00:00 2001 From: DigiH Date: Mon, 10 Jun 2024 18:50:08 +0200 Subject: [PATCH] [DISC] always auto-discover Presence/Tracker timeout (#1959) auto-discover Presence/Tracker timeout even when HASS presence is not active Also inject an additional placeholder rssi key and value into the BM2 voltage connection message to avoid the message being registered as a device tracker AWAY https://community.openmqttgateway.com/t/bm2-home-and-away/3315 --- main/ZgatewayBLEConnect.ino | 2 ++ main/ZgatewayBT.ino | 4 ---- main/ZmqttDiscovery.ino | 20 +++++++++----------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/main/ZgatewayBLEConnect.ino b/main/ZgatewayBLEConnect.ino index 50d878b..0af221a 100644 --- a/main/ZgatewayBLEConnect.ino +++ b/main/ZgatewayBLEConnect.ino @@ -301,6 +301,8 @@ void BM2_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, si float volt = ((output[2] | (output[1] << 8)) >> 4) / 100.0f; BLEdata["volt"] = volt; Log.trace(F("volt: %F" CR), volt); + // to avoid the BM2 device tracker going offline because of the voltage MQTT message without an RSSI value + BLEdata["rssi"] = -60; buildTopicFromId(BLEdata, subjectBTtoMQTT); handleJsonEnqueue(BLEdata, QueueSemaphoreTimeOutTask); } else { diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index bafd130..97d59e4 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -156,10 +156,6 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) { if (startup == false) { if (BTdata.containsKey("hasspresence") && BTdata["hasspresence"] == false && BTConfig.presenceEnable == true) { BTdata["adaptivescan"] = true; -# ifdef ZmqttDiscovery - // Remove discovered entities - eraseTopic("number", (char*)getUniqueId("presenceawaytimer", "").c_str()); -# endif } else if (BTdata.containsKey("hasspresence") && BTdata["hasspresence"] == true && BTConfig.presenceEnable == false) { BTdata["adaptivescan"] = false; } diff --git a/main/ZmqttDiscovery.ino b/main/ZmqttDiscovery.ino index 0682f26..8a17a3b 100644 --- a/main/ZmqttDiscovery.ino +++ b/main/ZmqttDiscovery.ino @@ -423,17 +423,15 @@ void eraseTopic(const char* sensor_type, const char* unique_id) { # ifdef ZgatewayBT void btPresenceParametersDiscovery() { - if (BTConfig.presenceEnable) { - createDiscovery("number", //set Type - subjectBTtoMQTT, "BT: Presence detection timer", (char*)getUniqueId("presenceawaytimer", "").c_str(), //set state_topic,name,uniqueId - will_Topic, "", "{{ value_json.presenceawaytimer/60000 }}", //set availability_topic,device_class,value_template, - "{\"presenceawaytimer\":{{value*60000}},\"save\":true}", "", "min", //set,payload_on,payload_off,unit_of_meas, - 0, //set off_delay - Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic - "", "", "", "", false, // device name, device manufacturer, device model, device ID, retain, - stateClassNone //State Class - ); - } + createDiscovery("number", //set Type + subjectBTtoMQTT, "BT: Presence/Tracker timeout", (char*)getUniqueId("presenceawaytimer", "").c_str(), //set state_topic,name,uniqueId + will_Topic, "", "{{ value_json.presenceawaytimer/60000 }}", //set availability_topic,device_class,value_template, + "{\"presenceawaytimer\":{{value*60000}},\"save\":true}", "", "min", //set,payload_on,payload_off,unit_of_meas, + 0, //set off_delay + Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic + "", "", "", "", false, // device name, device manufacturer, device model, device ID, retain, + stateClassNone //State Class + ); } void btScanParametersDiscovery() {