From 86fbf23178de0a17f2798d6353acc364386a665c Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Sun, 12 Nov 2023 19:03:31 -0600 Subject: [PATCH] Add status binary sensor and text sensor --- main/ZgatewayBT.ino | 18 +++++++++++++++++- main/config_mqttDiscovery.h | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 817852612a..555857d9a7 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -1030,7 +1030,7 @@ void launchBTDiscovery(bool overrideDiscovery) { 0, "", "", false, "", model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false, stateClassMeasurement, nullptr, nullptr, "[\"lb\",\"kg\",\"jin\"]"); - } else if (strcmp(prop.key().c_str(), "pres") == 0) { + } else if (strcmp(prop.key().c_str(), "pres") == 0 || strcmp(prop.key().c_str(), "movement") == 0) { createDiscovery("binary_sensor", discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(), will_Topic, "motion", value_template.c_str(), // Idealy we should have the decoder give the name here as "motion" but for now it gives "presence" @@ -1038,6 +1038,22 @@ void launchBTDiscovery(bool overrideDiscovery) { BTConfig.presenceAwayTimer, "", "", false, "", model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false, stateClassNone); + } else if (strcmp(prop.value()["unit"], "string") == 0 && strcmp(prop.key().c_str(), "mac") != 0) { + createDiscovery("sensor", + discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(), + will_Topic, prop.value()["name"], value_template.c_str(), + "", "", "", + 0, "", "", false, "", + model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false, + stateClassNone); + } else if (strcmp(prop.value()["unit"], "status") == 0) { + createDiscovery("binary_sensor", + discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(), + will_Topic, prop.value()["name"], value_template.c_str(), + "True", "False", "", + 0, "", "", false, "", + model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false, + stateClassNone); } else if (strcmp(prop.key().c_str(), "device") != 0 && strcmp(prop.key().c_str(), "mac") != 0) { // Exception on device and mac as these ones are not sensors createDiscovery("sensor", discovery_topic.c_str(), entity_name.c_str(), unique_id.c_str(), diff --git a/main/config_mqttDiscovery.h b/main/config_mqttDiscovery.h index b1ad133cc7..c08c4a2965 100644 --- a/main/config_mqttDiscovery.h +++ b/main/config_mqttDiscovery.h @@ -184,6 +184,8 @@ void announceDeviceTrigger(bool use_gateway_info, const char* availableHASSClasses[] = {"battery", "carbon_monoxide", "carbon_dioxide", + "door", + "enum", "pm10", "pm25", "humidity", @@ -197,7 +199,8 @@ const char* availableHASSClasses[] = {"battery", "energy", "power_factor", "voltage", - "enum"}; + "window" + }; // From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379 // List of units available in Home Assistant