From 45b6779efb1b7d2ab9b3fcf9ca4f0c48f2bbb96d Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sat, 12 Oct 2024 22:39:27 +0200 Subject: [PATCH] Update the Homeasistantr Discovery topics to comply with Homeasistant 2024.10 - "raw" should have a "State Class" unlike "". -> Set it to "measurement" since it could be decreasing as well as increasing. Further changes: - "value" should only have "State Class"="total_increasing" if "Allow Negative Rates" is NOT set. Else it should use "measurement" as it could go down again. --- code/components/jomjol_mqtt/server_mqtt.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index fd675a139..e7de125ca 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -184,9 +184,14 @@ bool MQTThomeassistantDiscovery(int qos) { group = ""; } + std::string value_state_class = "total_increasing"; + if ((*NUMBERS)[i]->AllowNegativeRates) { + value_state_class = "measurement"; + } + // Group | Field | User Friendly Name | Icon | Unit | Device Class | State Class | Entity Category - allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "value", "Value", "gauge", valueUnit, meterType, "total_increasing", "", qos); - allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "raw", "Raw Value", "raw", "", "", "", "diagnostic", qos); + allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "value", "Value", "gauge", valueUnit, meterType, value_state_class, "", qos); // State Class = "total_increasing" if .AllowNegativeRates = false, else use "measurement" + allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "raw", "Raw Value", "raw", valueUnit, meterType, "measurement", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "error", "Error", "alert-circle-outline", "", "", "", "diagnostic", qos); /* Not announcing "rate" as it is better to use rate_per_time_unit resp. rate_per_digitization_round */ // allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate", "Rate (Unit/Minute)", "swap-vertical", "", "", "", ""); // Legacy, always Unit per Minute