Skip to content

Commit

Permalink
Update the Homeasistantr Discovery topics to comply with Homeasistant…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
caco3 committed Oct 12, 2024
1 parent 3c9b2c4 commit 45b6779
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions code/components/jomjol_mqtt/server_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NUMBERS>.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
Expand Down

0 comments on commit 45b6779

Please sign in to comment.