[BT] Device tracker presence detection (#1548)

Add device tracker detection and automatic creation following HA discovery convention
So as to trigger the away state, add an offline status to the identified BLE trackers
This commit is contained in:
Florian authored and GitHub committed 2023-03-20 07:31:00 -05:00
1 parent 7bae999435
commit 85650a6204
5 files changed
+107 -31

No files matched your search

+19 -1
View File
@@ -295,6 +295,8 @@ void createDiscovery(const char* sensor_type,
}
if (payload_off[0])
sensor["pl_off"] = payload_off; //payload_off
if (strcmp(sensor_type, "device_tracker") == 0)
sensor["source_type "] = "bluetooth_le"; // payload_install for update
if (off_delay != 0)
sensor["off_delay"] = off_delay; //off_delay
if (payload_available[0])
@@ -386,8 +388,22 @@ 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
);
}
}
void btScanParametersDiscovery() {
if (BTConfig.adaptiveScan == false) {
if (!BTConfig.adaptiveScan) {
createDiscovery("number", //set Type
subjectBTtoMQTT, "BT: Interval between scans", (char*)getUniqueId("interval", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.interval/1000 }}", //set availability_topic,device_class,value_template,
@@ -1105,6 +1121,8 @@ void pubMqttDiscovery() {
btScanParametersDiscovery();
btPresenceParametersDiscovery();
createDiscovery("switch", //set Type
subjectBTtoMQTT, "BT: Publish HASS presence", (char*)getUniqueId("hasspresence", "").c_str(), //set state_topic,name,uniqueId
will_Topic, "", "{{ value_json.hasspresence }}", //set availability_topic,device_class,value_template,