Add RSSI as diagnostic entity_category (#2224)

This commit is contained in:
Peter Lambrechtsen authored and GitHub committed 2025-08-12 07:11:42 -05:00
1 parent 6d1b7935c4
commit 75b3a3657e
3 files changed
+30 -2

No files matched your search

+8 -1
View File
@@ -79,6 +79,11 @@ extern void createDiscoveryFromList(const char* mac,
* @param device_mac set device MAC, * @param device_mac set device MAC,
* @param retainCmd set retain * @param retainCmd set retain
* @param state_class set state class * @param state_class set state class
* @param state_off state off value
* @param state_on state on value
* @param enum_options options
* @param command_template command template
* @param diagnostic_entity true if entity_category is diagnostic
* *
* */ * */
extern void createDiscovery(const char* sensor_type, extern void createDiscovery(const char* sensor_type,
@@ -88,7 +93,8 @@ extern void createDiscovery(const char* sensor_type,
int off_delay, int off_delay,
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* command_topic, const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* command_topic,
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_mac, bool retainCmd, const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_mac, bool retainCmd,
const char* state_class, const char* state_off = nullptr, const char* state_on = nullptr, const char* enum_options = nullptr, const char* command_template = nullptr); const char* state_class, const char* state_off = nullptr, const char* state_on = nullptr, const char* enum_options = nullptr,
const char* command_template = nullptr, bool diagnostic_entity = false);
/** /**
* @brief Create a message for Discovery Device Trigger. For HA @see https://www.home-assistant.io/integrations/device_trigger.mqtt/ * @brief Create a message for Discovery Device Trigger. For HA @see https://www.home-assistant.io/integrations/device_trigger.mqtt/
@@ -170,6 +176,7 @@ extern char discovery_prefix[];
#define jsonInuse "{{ value_json.power | is_defined | float > 0 }}" #define jsonInuse "{{ value_json.power | is_defined | float > 0 }}"
#define jsonInuseRN8209 "{% if value_json.power > 0.02 -%} on {% else %} off {%- endif %}" #define jsonInuseRN8209 "{% if value_json.power > 0.02 -%} on {% else %} off {%- endif %}"
#define jsonVoltBM2 "{% if value_json.uuid is not defined and value_json.volt is defined -%} {{value_json.volt}} {%- endif %}" #define jsonVoltBM2 "{% if value_json.uuid is not defined and value_json.volt is defined -%} {{value_json.volt}} {%- endif %}"
#define jsonRSSI "{{ value_json.rssi | is_defined }}"
#define stateClassNone "" #define stateClassNone ""
#define stateClassMeasurement "measurement" #define stateClassMeasurement "measurement"
+11
View File
@@ -1110,6 +1110,17 @@ void launchBTDiscovery(bool overrideDiscovery) {
} }
} }
} }
String rssi_name = String(model_id.c_str()) + "-rssi"; // rssi diagnostic entity_category
String rssi_id = macWOdots + "-rssi";
createDiscovery("sensor",
discovery_topic.c_str(), rssi_name.c_str(), rssi_id.c_str(),
will_Topic, "signal_strength", jsonRSSI,
"", "", "dB",
0, "", "", false, "",
model.c_str(), brand.c_str(), model_id.c_str(), macWOdots.c_str(), false,
stateClassMeasurement, nullptr, nullptr, nullptr, nullptr, true);
} else { } else {
if ((p->sensorModel_id > BLEconectable::id::MIN && if ((p->sensorModel_id > BLEconectable::id::MIN &&
p->sensorModel_id < BLEconectable::id::MAX) || p->sensorModel_id < BLEconectable::id::MAX) ||
+11 -1
View File
@@ -378,6 +378,11 @@ std::string remove_substring(std::string s, const std::string& p) {
* @param device_id set device(BLE)/entity(RTL_433) identification, * @param device_id set device(BLE)/entity(RTL_433) identification,
* @param retainCmd set retain * @param retainCmd set retain
* @param state_class set state class * @param state_class set state class
* @param state_off state off value
* @param state_on state on value
* @param enum_options options
* @param command_template command template
* @param diagnostic_entity true if entity_category is diagnostic
* *
* */ * */
void createDiscovery(const char* sensor_type, void createDiscovery(const char* sensor_type,
@@ -387,7 +392,8 @@ void createDiscovery(const char* sensor_type,
int off_delay, int off_delay,
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic, const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic,
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd, const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd,
const char* state_class, const char* state_off, const char* state_on, const char* enum_options, const char* command_template) { const char* state_class, const char* state_off, const char* state_on, const char* enum_options,
const char* command_template, bool diagnostic_entity) {
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer; StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject sensor = jsonBuffer.to<JsonObject>(); JsonObject sensor = jsonBuffer.to<JsonObject>();
@@ -537,6 +543,10 @@ void createDiscovery(const char* sensor_type,
} }
} }
if (diagnostic_entity) { // entity_category
sensor["ent_cat"] = "diagnostic";
}
if (enum_options != nullptr) { if (enum_options != nullptr) {
sensor["ops"] = enum_options; // options sensor["ops"] = enum_options; // options
} }